Skip to content

Fix setting ServerAddress property in NativeStore#4655

Merged
thaJeztah merged 1 commit intodocker:masterfrom
StealthyCoder:4653-fix-credential-helper
Nov 13, 2023
Merged

Fix setting ServerAddress property in NativeStore#4655
thaJeztah merged 1 commit intodocker:masterfrom
StealthyCoder:4653-fix-credential-helper

Conversation

@StealthyCoder
Copy link
Copy Markdown
Contributor

@StealthyCoder StealthyCoder commented Nov 10, 2023

This will return the ServerAddress property when using the NativeStore. This happens when you use docker credential helpers, not the credential store.

The reason this fix is needed is because it needs to be propagated properly down towards moby/moby project in the following logic:

func authorizationCredsFromAuthConfig(authConfig registrytypes.AuthConfig) docker.AuthorizerOpt {
	cfgHost := registry.ConvertToHostname(authConfig.ServerAddress)
	if cfgHost == "" || cfgHost == registry.IndexHostname {
		cfgHost = registry.DefaultRegistryHost
	}

	return docker.WithAuthCreds(func(host string) (string, string, error) {
		if cfgHost != host {
			logrus.WithFields(logrus.Fields{
				"host":    host,
				"cfgHost": cfgHost,
			}).Warn("Host doesn't match")
			return "", "", nil
		}
		if authConfig.IdentityToken != "" {
			return "", authConfig.IdentityToken, nil
		}
		return authConfig.Username, authConfig.Password, nil
	})
}

This logic resides in the following file :
daemon/containerd/resolver.go .

In the case when using the containerd storage feature when setting the cfgHost variable from the authConfig.ServerAddress it will always be empty. Since it will never be returned from the NativeStore currently. Therefore Docker Hub images will work fine, but anything else will fail since the cfgHost will always be the registry.DefaultRegistryHost.

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah
Copy link
Copy Markdown
Member

Thanks! We also merged a fix on the daemon-side in moby/moby#46779

Perhaps both won't do harm though

/cc @dmcgowan

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Nov 10, 2023

Codecov Report

Merging #4655 (b24e7f8) into master (a9ae9b3) will increase coverage by 0.00%.
Report is 4 commits behind head on master.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4655   +/-   ##
=======================================
  Coverage   59.74%   59.75%           
=======================================
  Files         288      288           
  Lines       24849    24853    +4     
=======================================
+ Hits        14846    14850    +4     
  Misses       9117     9117           
  Partials      886      886           

Comment thread cli/config/credentials/native_store.go Outdated
ac.Username = creds.Username
ac.Password = creds.Password
ac.IdentityToken = creds.IdentityToken
ac.ServerAddress = creds.ServerAddress
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is ac.ServerAddress ever a non-empty value?

Copy link
Copy Markdown
Contributor Author

@StealthyCoder StealthyCoder Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not believe so no. Since in both stores the code always sets it to what the Registry Hostname is. Is your idea to just have creds be returned there directly? 🙂

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmcgowan do you mean you prefer to make this conditional to keep that option open?

Something like this?;

if ac.ServerAddress  == "" {
    ac.ServerAddress = creds.ServerAddress
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had not read it that way yet. That makes sense. So we only set it when it is empty and not accidentally overwrite a potential value. I can add that real quick.

@dmcgowan
Copy link
Copy Markdown
Contributor

@thaJeztah agreed, both changes make sense

@thaJeztah thaJeztah added this to the 25.0.0 milestone Nov 10, 2023
This will return the ServerAddress property when using the NativeStore.
This happens when you use docker credential helpers, not the credential
store.

The reason this fix is needed is because it needs to be propagated
properly down towards `moby/moby` project in the following logic:

```golang
func authorizationCredsFromAuthConfig(authConfig registrytypes.AuthConfig) docker.AuthorizerOpt {
	cfgHost := registry.ConvertToHostname(authConfig.ServerAddress)
	if cfgHost == "" || cfgHost == registry.IndexHostname {
		cfgHost = registry.DefaultRegistryHost
	}

	return docker.WithAuthCreds(func(host string) (string, string, error) {
		if cfgHost != host {
			logrus.WithFields(logrus.Fields{
				"host":    host,
				"cfgHost": cfgHost,
			}).Warn("Host doesn't match")
			return "", "", nil
		}
		if authConfig.IdentityToken != "" {
			return "", authConfig.IdentityToken, nil
		}
		return authConfig.Username, authConfig.Password, nil
	})
}
```
This logic resides in the following file :
`daemon/containerd/resolver.go` .

In the case when using the containerd storage feature when setting the
`cfgHost` variable from the `authConfig.ServerAddress` it will always be
empty. Since it will never be returned from the NativeStore currently.
Therefore Docker Hub images will work fine, but anything else will fail
since the `cfgHost` will always be the `registry.DefaultRegistryHost`.

Signed-off-by: Eric Bode <eric.bode@foundries.io>
@StealthyCoder StealthyCoder force-pushed the 4653-fix-credential-helper branch from 652cd45 to b24e7f8 Compare November 11, 2023 13:22
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

And thanks for the extra eyes, @dmcgowan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker credential helpers don't work with containerd image store

4 participants