Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HostsFromHostDir() to remotes/docker/config #10141

Closed
wants to merge 1 commit into from

Conversation

minuk-dev
Copy link

related: containerd/nerdctl#2844

  • remotes/docker/config package provides ConfigureHosts() and HostDirFromRoot() functions only.
  • But, its caller cannot know the actual hosts from a host. It causes that the caller cannot call ConfigureHosts() method with its proper Credentials.
  • If it provides HostsFromHostDir(), nerdctl can find the proper credential for a image.

e.g.
https://github.com/containerd/nerdctl/blob/40fe8b6211b0ec3cc200fe53512b557559701a29/pkg/imgutil/dockerconfigresolver/dockerconfigresolver.go#L116-L122

		if ho.HostDir != nil {
			hosts := dockerconfig.HostsFromHostDir(ctx, refHostname)  // <- what I want to achieve.
			for _, host := hosts {
				authCreds, err := NewAuthCreds(host)
				if err != nil {
					return nil, err
				}
				if authCreds != nil {
					ho.Credentials = authCreds
					break
				}
			}
		} else {
			authCreds, err := NewAuthCreds(refHostname)
			if err != nil {
				return nil, err
			}
			ho.Credentials = authCreds
		}

`remotes/docker/config` package provides `ConfigureHosts()` and
`HostDirFromRoot()` functions only. But, its caller cannot know the
actual hosts from a host. It causes that the caller cannot call
`ConfigureHosts()` method with its proper Credentials.
e.g. containerd/nerdctl#2844 - "nerdctl pull from private registry
mirror is missing Authorization header"

Signed-off-by: Min Uk Lee <minuk.dev@gmail.com>
@k8s-ci-robot
Copy link

Hi @minuk-dev. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@dmcgowan
Copy link
Member

dmcgowan commented May 1, 2024

Can you explain further the case this is trying to solve for. We are intentionally not supporting pre-fetching of the auth credentials to avoid credentials being passed to the wrong hosts. What is the information missing to get the correct credentials for the mirror?

@minuk-dev
Copy link
Author

minuk-dev commented May 1, 2024

(It's only on nerdctl. I don't know other program's scenario.)

In the containerd/nerdctl#2844's description,

When I configured like below

/etc/containerd/config.toml

    [plugins."io.containerd.grpc.v1.cri".registry]
      config_path = "/etc/containerd/certs.d"

and

/etc/containerd/certs.d/gcr.io/hosts.toml

server = "https://gcr.io"

[host."https://harbor.example.com:8443/v2/gcr.io"]
  capabilities = ["pull", "resolve"]
  override_path = true

And when I request to pull the image gcr.io/~~~, I'll request to harbor.example.com:8443 because ConfigureHosts() returns RegistryHost (

type RegistryHost struct {
) with harbor.example.com:8443.
But the Authorizer in RegistryHost is configured for gcr.io.
So Credentials() (
Credentials func(host string) (string, string, error)
) are called with gcr.io.

In other words,
even if the request is sent to harbor.example.com:8443 because of ConfigureHosts(), but the Credentials() is called with gcr.io. It means when I login to harbor.example.com:8443, it does not use the credentials.
So, I want to make containerd provides the actual hosts in order to configure Credentials() of HostOptions.

@dmcgowan
Copy link
Member

dmcgowan commented May 1, 2024

But the Authorizer in RegistryHost is configured for gcr.io.

The point of using a callback is that this can be dynamically looked up when requested from the registry. It seems odd that nerdctl would pre-fetch just to return it in the closure, is there any specific reason it does this or was just originally done that way?

@minuk-dev
Copy link
Author

minuk-dev commented May 2, 2024

In order to make RegistryHost using ConfigureHosts(), I should call with credential options with the original host, not the actual host because HostDir is parsed into containerd completely. So, outside of containerd, cannot know the actual host.
Is there any way to fetch the actual host or inject it into registryhost's credential?

Or,
Do you mean that
why use WithAuthCreds() instead of WithAuthHeader()?. (

// WithAuthCreds provides a credential function to the authorizer
func WithAuthCreds(creds func(string) (string, string, error)) AuthorizerOpt {
return func(opt *authorizerConfig) {
opt.credentials = creds
}
}
// WithAuthHeader provides HTTP headers for authorization
func WithAuthHeader(hdr http.Header) AuthorizerOpt {
return func(opt *authorizerConfig) {
opt.header = hdr
}
}
)

@minuk-dev minuk-dev closed this Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants