Sitelet https://github.com/kubernetes/kops/pull/18819
Skip to content

containerd: set override_path for registry mirrors with a path - #18819

Merged
kubernetes-prow[bot] merged 2 commits into
kubernetes:masterfrom
peter-svensson:fix/containerd-mirror-override-path
Oct 1, 2026
Merged

kubernetes-prow[bot] merged 2 commits into
kubernetes:masterfrom
peter-svensson:fix/containerd-mirror-override-path

Conversation

@peter-svensson

@peter-svensson peter-svensson commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

#18291 moved containerd.registryMirrors from the inline registry.mirrors.<name>.endpoint config to /etc/containerd/certs.d/<name>/hosts.toml. The two formats treat a path in the mirror URL differently:

  • Legacy registry.mirrors endpoints: a non-empty path is used as-is, /v2 is only added when the path is empty.
  • hosts.toml: containerd always appends /v2 to the host path unless override_path = true is set (hosts.md).

Mirrors that carry their own API path therefore stopped working in 1.36. With an ECR pull-through cache configured as

containerd:
  registryMirrors:
    docker.io:
      - https://<account>.dkr.ecr.eu-west-1.amazonaws.com/v2/docker-hub

kops 1.36 nodes request

HEAD https://<account>.dkr.ecr.eu-west-1.amazonaws.com/v2/docker-hub/v2/<repo>/manifests/<digest>: 403 Forbidden

while the correct URL .../v2/docker-hub/<repo>/manifests/<digest> returns 200 with the same credentials. containerd then falls back to the upstream registry, so the failure is easy to miss until upstream pulls fail as well.

This PR writes override_path = true for mirror endpoints whose URL has a non-root path, which matches the pre-1.36 behaviour. Endpoints without a path (https://mirror.example.com) produce the same hosts.toml as before.

Which issue(s) this PR fixes:

Special notes for your reviewer:

This is a regression from 1.35, so a cherry-pick to release-1.36 would be appreciated.

The complex containerd builder test gets an ECR-style quay.io mirror to cover the path case; the existing mirrors in that test are unchanged in the golden output.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: peter-svensson / name: Peter Svensson (f6821e4)

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @peter-svensson!

It looks like this is your first PR to kubernetes/kops 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kops has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 28, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @peter-svensson. Thanks for your PR.

I'm waiting for a kubernetes 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.

Details

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-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 28, 2026
@kubernetes-prow kubernetes-prow Bot added area/nodeup cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Sep 28, 2026

@hakman hakman left a comment

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.

Thanks for the fix @peter-svensson. I would suggest some small fixes and adding a test for endpointHasPath().

func TestEndpointHasPath(t *testing.T) {
	grid := []struct {
		endpoint string
		expected bool
	}{
		{endpoint: "https://mirror.example.com", expected: false},
		{endpoint: "https://mirror.example.com/", expected: false},
		{endpoint: "https://mirror.example.com//", expected: false},
		{endpoint: "http://10.0.0.5:5000", expected: false},
		{endpoint: "mirror.example.com", expected: false},
		{endpoint: "mirror.example.com:5000", expected: false},
		{endpoint: "10.0.0.5", expected: false},
		{endpoint: "https://mirror.example.com/v2", expected: true},
		{endpoint: "https://123456789012.dkr.ecr.us-east-1.amazonaws.com/v2/docker-hub", expected: true},
		{endpoint: "mirror.example.com:5000/v2/docker-hub", expected: true},
		{endpoint: "10.0.0.5:5000/v2/docker-hub", expected: true},
		{endpoint: "https://mirror.example.com/./", expected: false},
		{endpoint: "https://mirror.example.com/v2/..", expected: false},
		{endpoint: "https://mirror.example.com/prefix/./v2", expected: true},
		{endpoint: "https://mirror.example.com/v2/docker-hub/", expected: true},
		{endpoint: "[::1]:5000/v2/x", expected: true},
		{endpoint: "https://[fd00::1]:5000", expected: false},
	}

	for _, g := range grid {
		if actual := endpointHasPath(g.endpoint); actual != g.expected {
			t.Errorf("endpointHasPath(%q): got %v, expected %v", g.endpoint, actual, g.expected)
		}
	}
}

Comment thread nodeup/pkg/model/containerd.go Outdated
Comment on lines +684 to +689
// endpointHasPath reports whether a mirror endpoint carries its own API path, e.g.
// https://<account>.dkr.ecr.<region>.amazonaws.com/v2/<prefix> for an ECR pull-through cache.
// containerd appends /v2 to hosts.toml host paths unless override_path is set, whereas the
// legacy registry.mirrors endpoint list used a non-empty path as-is. Setting override_path
// for these endpoints keeps the behaviour of the legacy configuration.
func endpointHasPath(endpoint string) bool {

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.

Suggested change
// endpointHasPath reports whether a mirror endpoint carries its own API path, e.g.
// https://<account>.dkr.ecr.<region>.amazonaws.com/v2/<prefix> for an ECR pull-through cache.
// containerd appends /v2 to hosts.toml host paths unless override_path is set, whereas the
// legacy registry.mirrors endpoint list used a non-empty path as-is. Setting override_path
// for these endpoints keeps the behaviour of the legacy configuration.
func endpointHasPath(endpoint string) bool {
// endpointHasPath reports whether a mirror endpoint has a non-root path. These endpoints get
// override_path, so containerd uses the path as-is instead of appending /v2, as the legacy
// registry.mirrors config did.
func endpointHasPath(endpoint string) bool {
// Match containerd's parseHostConfig normalization so we check the same path.
if !strings.HasPrefix(endpoint, "http") {
endpoint = "https://" + endpoint
}

Comment thread nodeup/pkg/model/containerd.go Outdated
if err != nil {
return false
}
return strings.TrimSuffix(u.Path, "/") != ""

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.

Suggested change
return strings.TrimSuffix(u.Path, "/") != ""
return u.Path != "" && path.Clean(u.Path) != "/"

@peter-svensson

peter-svensson commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @hakman! Applied both suggestions and added TestEndpointHasPath in b9c131f.

The normalization matters beyond style: without the https:// prefix, url.Parse treats a scheme-less host like mirror.example.com:5000/v2/docker-hub as the URL scheme, so those mirrors did not get override_path at all, and plain hosts such as mirror.example.com got it by mistake. Your table covers both.

Since registry mirrors moved from the inline registry.mirrors config to
certs.d/<registry>/hosts.toml, containerd appends /v2 to every mirror
host URL. The legacy endpoint list used a non-empty path as-is, so
mirrors that carry their own API path, such as an ECR pull-through cache
at https://<account>.dkr.ecr.<region>.amazonaws.com/v2/<prefix>, now
resolve to .../v2/<prefix>/v2/<repo> and fail.

Emit override_path = true for endpoints with a non-root path, which
restores the previous behaviour. Endpoints without a path are unchanged.
…g the path

Endpoints without a scheme (mirror.example.com:5000/v2/docker-hub) were misparsed by url.Parse, and paths such as "//" or "/v2/.." counted as a path. Prefix https:// the way containerd parseHostConfig does and compare the cleaned path against "/". Add a table test for endpointHasPath.
@peter-svensson
peter-svensson force-pushed the fix/containerd-mirror-override-path branch from 70ddb6e to b9c131f Compare September 30, 2026 20:44
@hakman

hakman commented Sep 30, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@kubernetes-prow kubernetes-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 30, 2026
@hakman

hakman commented Oct 1, 2026

Copy link
Copy Markdown
Member

Thanks @peter-svensson!
/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 1, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hakman

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 1, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit 2b56ba7 into kubernetes:master Oct 1, 2026
26 checks passed
kubernetes-prow Bot added a commit that referenced this pull request Oct 1, 2026
…-upstream-release-1.37

Automated cherry pick of #18819: containerd: set override_path for registry mirrors with a path
kubernetes-prow Bot added a commit that referenced this pull request Oct 1, 2026
…-upstream-release-1.36

Automated cherry pick of #18819: containerd: set override_path for registry mirrors with a path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/nodeup cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants