Skip to content

Commit

Permalink
internal: Skip the docker auth generation on RMT
Browse files Browse the repository at this point in the history
Fixes bsc#1231185

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Oct 25, 2024
1 parent 56d6ac2 commit d13d099
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cmd/suseconnect/suseconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func main() {
fmt.Printf("URL \"%s\" not valid: %s\n", baseURL, err)
os.Exit(1)
}
connect.CFG.BaseURL = baseURL
connect.CFG.ChangeBaseURL(baseURL)
writeConfig = true
}
if fsRoot != "" {
Expand Down
17 changes: 9 additions & 8 deletions internal/connect/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,14 @@ func announceOrUpdate(quiet bool) error {
}

if err = cred.CreateCredentials(login, password, "", cred.SystemCredentialsPath(CFG.FsRoot)); err == nil {
util.Debug.Print("\nAdding SUSE registry system authentication configuration ...")
setupRegistryAuthentication(login, password)
// If the user is authenticated against the SCC, then setup the Docker
// Registry configuration for the system. Otherwise, if the system is
// behind a proxy (e.g. RMT), this step might fail and it's best to
// avoid it (see bsc#1231185).
if CFG.IsScc() {
util.Debug.Print("\nAdding SUSE registry system authentication configuration ...")
setupRegistryAuthentication(login, password)
}
}
return err
}
Expand All @@ -405,14 +411,9 @@ func UpToDate() bool {
return upToDate()
}

// URLDefault returns true if using https://scc.suse.com
func URLDefault() bool {
return CFG.BaseURL == defaultBaseURL
}

func printInformation(action string, jsonOutput bool) {
var server string
if URLDefault() {
if CFG.IsScc() {
server = "SUSE Customer Center"
} else {
server = "registration proxy " + CFG.BaseURL
Expand Down
32 changes: 27 additions & 5 deletions internal/connect/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const (
type ServerType uint64

const (
Unknown ServerType = iota
Scc
Rmt
UnknownProvider ServerType = iota
SccProvider
RmtProvider
)

// Config holds the config!
Expand Down Expand Up @@ -93,6 +93,12 @@ func (c Config) Save() error {
func (c *Config) Load() {
f, err := os.Open(c.Path)
if err != nil {
// If we failed at parsing the configuration, we can make further
// assumptions based on the base URL being used.
if c.BaseURL == defaultBaseURL {
c.ServerType = SccProvider
}

util.Debug.Println(err)
return
}
Expand All @@ -101,6 +107,22 @@ func (c *Config) Load() {
util.Debug.Printf("Config after parsing: %+v", c)
}

// Change the base url to be used when talking to the server to the one being
// provided.
func (c *Config) ChangeBaseURL(baseUrl string) {
c.BaseURL = baseUrl

// When making an explicit change of the URL, we can further detect which
// kind of server we are dealing with. For now, let's keep it simple, and if
// it's the defaultBaseURL then we assume it to be SccProvider, otherwise
// RmtProvider.
if c.BaseURL == defaultBaseURL {
c.ServerType = SccProvider
} else {
c.ServerType = RmtProvider
}
}

func parseConfig(r io.Reader, c *Config) {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
Expand Down Expand Up @@ -135,7 +157,7 @@ func parseConfig(r io.Reader, c *Config) {

// Set the server type depending on what we parsed from the configuration.
if c.BaseURL == defaultBaseURL {
c.ServerType = Scc
c.ServerType = SccProvider
}
}

Expand All @@ -152,5 +174,5 @@ func (c *Config) MergeJSON(jsn string) error {
// but it might need to be filled in upon HTTP requests to further guess if it's
// a Glue instance running on localhost or similar developer-only scenarios.
func (c *Config) IsScc() bool {
return c.ServerType == Scc
return c.ServerType == SccProvider
}
4 changes: 2 additions & 2 deletions internal/connect/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ func TestSaveLoad(t *testing.T) {
c1 := NewConfig()
c1.Path = path
c1.AutoAgreeEULA = true
c1.ServerType = Unknown
c1.ServerType = UnknownProvider
if err := c1.Save(); err != nil {
t.Fatalf("Unable to write config: %s", err)
}
c2 := NewConfig()
c2.Path = path
c2.Load()
c2.ServerType = Unknown
c2.ServerType = UnknownProvider
if !reflect.DeepEqual(c1, c2) {
t.Errorf("got %+v, expected %+v", c2, c1)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/connect/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ func callHTTP(verb, path string, body []byte, query map[string]string, auth auth
// configuration, we can actually further inspect it via some of the headers
// that are returned by Glue vs RMT. Hence, if the server type is unknown,
// make an educated guess now.
if CFG.ServerType == Unknown {
if CFG.ServerType == UnknownProvider {
if api := resp.Header.Get("Scc-Api-Version"); api == sccAPIVersion {
CFG.ServerType = Scc
CFG.ServerType = SccProvider
} else {
CFG.ServerType = Rmt
CFG.ServerType = RmtProvider
}
}

Expand Down

0 comments on commit d13d099

Please sign in to comment.