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

host-ctr: setting img reg credentials for public.ecr.aws does not work #2671

Closed
etungsten opened this issue Dec 19, 2022 · 1 comment · Fixed by #2676
Closed

host-ctr: setting img reg credentials for public.ecr.aws does not work #2671

etungsten opened this issue Dec 19, 2022 · 1 comment · Fixed by #2676
Assignees
Labels
area/core Issues core to the OS (variant independent) type/bug Something isn't working

Comments

@etungsten
Copy link
Contributor

etungsten commented Dec 19, 2022

Image I'm using:
Any bottlerocket image supporting settings.container-registry.mirrors and settings.container-registry.credentials

What I expected to happen:
host-ctr to use the provided registry credentials in settings.container-registry.credentials for public.ecr.aws when going through a configured private registry mirror.

What actually happened:
host-ctr tries to pull the public ECR image from through the prescribed registry mirror but without the specified registry credentials for public.aws.ecr which then causes the image pull to fail.

How to reproduce the problem:
With the following user-data:

[settings.container-registry.mirrors]
"public.ecr.aws" = ["https://198.18.34.118:443"]
[settings.pki.registry-mirror-ca]
data = "<redacted>"
trusted=true
[[settings.container-registry.credentials]]
registry = "public.ecr.aws"
username = "<redacted>"
password = "<redacted>"

Bottlerocket then repeatedly fails to pull bottlerocket-admin host container image from public ECR due to authentication failures.

Screen Shot 2022-12-15 at 4 06 14 PM

@etungsten etungsten added type/bug Something isn't working status/needs-triage Pending triage or re-evaluation area/core Issues core to the OS (variant independent) go labels Dec 19, 2022
@etungsten etungsten changed the title host-ctr: setting img reg credentials for public.ecr.aws does not work when using private reg mirror host-ctr: setting img reg credentials for public.ecr.aws does not work Dec 19, 2022
@etungsten etungsten self-assigned this Dec 19, 2022
@etungsten
Copy link
Contributor Author

The issue here is that we're overriding the registry authorizer with credentials fetched from ECR public to enable authenticated pulls so users won't hit anonymous pull limits.

// For Amazon ECR Public registries, we should try and fetch credentials before resolving the image reference
case strings.HasPrefix(ref, "public.ecr.aws/"):
// Try to get credentials for authenticated pulls from ECR Public

custome authorizer object created here:
// Use the fetched authorization credentials to resolve the image
authOpt := docker.WithAuthCreds(func(host string) (string, string, error) {
// Double-check to make sure the we're doing this for an ECR Public registry
if host != "public.ecr.aws" {
return "", "", errors.New("ecr-public: expected image to start with public.ecr.aws")
}
return tokens[0], tokens[1], nil
})
authorizer := docker.NewDockerAuthorizer(authOpt)
resolverOpt := docker.ResolverOptions{
Hosts: registryHosts(registryConfig, &authorizer),
}

Then used here through authorizerOverride:

var authorizer docker.Authorizer
if authorizerOverride == nil {
// Set up auth for pulling from registry
var authOpts []docker.AuthorizerOpt
if _, ok := registryConfig.Credentials[defaultHost]; ok {
// Convert registry credentials config to runtime auth config, so it can be parsed by `ParseAuth`
authConfig.Username = registryConfig.Credentials[defaultHost].Username
authConfig.Password = registryConfig.Credentials[defaultHost].Password
authConfig.Auth = registryConfig.Credentials[defaultHost].Auth
authConfig.IdentityToken = registryConfig.Credentials[defaultHost].IdentityToken
authOpts = append(authOpts, docker.WithAuthClient(&http.Client{
Transport: newTransport(),
}))
authOpts = append(authOpts, docker.WithAuthCreds(func(host string) (string, string, error) {
return server.ParseAuth(&authConfig, host)
}))
}
authorizer = docker.NewDockerAuthorizer(authOpts...)
} else {
authorizer = *authorizerOverride
}

What we want to do is to NOT override the authorizer if there is a settings.container-registry.credentials entry for public.ecr.aws so the user-specified reg creds can be used.

We can add a if to check registryConfig.Credentials before this line:

// Try to get credentials for authenticated pulls from ECR Public

and just return the defaultResolver if it contains public.ecr.aws.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core Issues core to the OS (variant independent) type/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants