Skip to content

fix: Allow same-host private/loopback registry bearer realms (NCN-114223)#1046

Merged
jimmidyson merged 2 commits into
mainfrom
fix/NCN-114223-bump-go-containerregistry
May 19, 2026
Merged

fix: Allow same-host private/loopback registry bearer realms (NCN-114223)#1046
jimmidyson merged 2 commits into
mainfrom
fix/NCN-114223-bump-go-containerregistry

Conversation

@jimmidyson

Copy link
Copy Markdown
Contributor

Summary

  • Bump github.com/google/go-containerregistry v0.21.5 → v0.21.6 to pick up google/go-containerregistry#2302 — transport: allow bearer realm at same host:port as registry.
  • Fixes NCN-114223: mindthegap push bundle (and downstream nkp push bundle) regression against on-prem registries that colocate the registry and bearer-token endpoint on the same private IP. e.g. for an internal Harbor at https://10.162.182.23:5000/library the push aborted with invalid realm in www-authenticate: realm host "10.162.182.23" is a private or link-local address.
  • Add regression test TestPushDockerArchive_BearerAuthSameHostLoopbackRealm in cmd/mindthegap/push/imagearchive/push_test.go that reproduces the exact NCN-114223 error against v0.21.5 and passes against v0.21.6.

Background

The realm-URL validation introduced in go-containerregistry#2243 (shipped in v0.21.5) rejects realms whose host resolves to a private, loopback, or link-local IP. This is the right default for the cross-host SSRF case (a malicious registry pointing the token endpoint at 169.254.169.254 or a sister internal service), but it broke legitimate on-prem deployments that serve their own token endpoint at the same host:port as the registry. #2258 tracked the discussion; #2302 implements the agreed fix: keep the cross-host SSRF block, but skip the private-IP check when the realm URL host AND port match the registry host:port.

Transitive dependency changes

Pulled in by go-containerregistry v0.21.6's go.mod via MVS resolution:

  • docker/cli v29.4.0 → v29.4.3
  • moby/moby/api v1.54.1 → v1.54.2
  • moby/moby/client v0.4.0 → v0.4.1
  • docker/go-connections v0.6.0 → v0.7.0
  • klauspost/compress v1.18.5 → v1.18.6
  • golang.org/x/{crypto,mod,net,sys,term,text,tools} — minor bumps

Dropped (v0.21.6 removed estargz support in go-containerregistry#2288):

  • containerd/stargz-snapshotter/estargz (indirect)
  • vbatts/tar-split (indirect)

Test fixture update

images/manifest_test.go is updated for the unrelated OCI-spec compliance change in go-containerregistry#2269: mutate.AppendManifests now sets the index entry ArtifactType to the image's Config.MediaType when the image manifest does not itself set artifactType. For the Docker schema2 fixture in TestManifestListForImage_RemoteImage this becomes "application/vnd.docker.container.image.v1+json" (types.DockerConfigJSON).

Test plan

  • go test -count=1 ./... passes (155 tests).
  • New TestPushDockerArchive_BearerAuthSameHostLoopbackRealm fails on v0.21.5 with the exact NCN-114223 error (invalid realm in www-authenticate: realm host "127.0.0.1" is a private or link-local address) and passes on v0.21.6 — bisected to confirm it is not a tautology.
  • go build ./... passes.
  • golangci-lint run ./... clean.
  • Manual verification against an on-prem Harbor with realm host == registry host on an RFC1918 IP (e.g. the reproducer environment in NCN-114223).

Out of scope

The two pre-existing govulncheck stdlib findings (GO-2026-4982, GO-2026-4980, GO-2026-4971, GO-2026-4918 — all go1.25.x fixed in go1.25.10) are unrelated to this change.

@github-actions github-actions Bot added the fix label May 19, 2026
@jimmidyson jimmidyson requested a review from bish-ntx May 19, 2026 17:36
@github-actions

github-actions Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Unit test results

156 tests  +1   156 ✅ +1   0s ⏱️ ±0s
 30 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 1a23172. ± Comparison against base commit 02e9b57.

♻️ This comment has been updated with latest results.

Bump google/go-containerregistry from v0.21.5 to v0.21.6 to include
google/go-containerregistry#2302 (transport: allow bearer realm at
same host:port as registry).

The realm-URL validation introduced in go-containerregistry#2243
(shipped in v0.21.5) rejects realms whose host resolves to a private,
loopback, or link-local IP. This is the right default for the
cross-host SSRF case (a malicious registry pointing the token
endpoint at 169.254.169.254 or a sister internal service), but it
breaks `mindthegap push bundle` (and downstream `nkp push bundle`)
against on-prem registries that colocate the registry and bearer-
token endpoint on the same private IP. e.g. for an internal Harbor
at https://10.162.182.23:5000/library the push aborts with:

    invalid realm in www-authenticate: realm host
    "10.162.182.23" is a private or link-local address

v0.21.6 keeps the cross-host SSRF block but adds a same-host:port
exception: when the realm URL host AND port match the registry, the
private-IP check is skipped. The realm cannot escape a trust boundary
the user already crossed by passing the registry reference.

The transitive bumps (docker/cli, moby/moby, docker/go-connections,
klauspost/compress, golang.org/x/{crypto,mod,net,sys,term,text,
tools}) are pulled in by go-containerregistry v0.21.6 go.mod via MVS
resolution. The containerd/stargz-snapshotter/estargz and
vbatts/tar-split indirect dependencies are dropped because v0.21.6
removed estargz support (go-containerregistry#2288).

Test expectations in images/manifest_test.go are updated for the
unrelated OCI-spec compliance change in
google/go-containerregistry#2269: mutate.AppendManifests now sets the
index entry ArtifactType to the image Config.MediaType when the image
manifest does not itself set artifactType. For the Docker schema2
fixture in TestManifestListForImage_RemoteImage this becomes
"application/vnd.docker.container.image.v1+json"
(types.DockerConfigJSON).
Adds TestPushDockerArchive_BearerAuthSameHostLoopbackRealm covering
google/go-containerregistry#2258 (fixed in v0.21.6 by #2302) at the
mindthegap push level.

The test wraps the in-process crane registry with a Bearer-auth handler
that serves WWW-Authenticate with a realm pointing back at the same
httptest server (a 127.0.0.1 loopback IP literal that equals the
registry host:port). It then invokes `mindthegap push` with the same
basic credentials and asserts the push succeeds — i.e. that we go
through token exchange, get a Bearer token, and write the image.

This reproduces the exact NCN-114223 failure mode against v0.21.5:

    invalid realm in www-authenticate: realm host "127.0.0.1" is a
    private or link-local address

and passes against v0.21.6, where validateRealmURL allows realms
whose host:port matches the registry host:port. Bisected to confirm
the test fails on v0.21.5 and passes on v0.21.6, so it would catch
any future regression of the same-host bypass.

The test sanity-checks that httptest is still binding to a loopback
IP literal — if Go's net/http ever started returning a hostname here
the test would silently stop exercising the private-IP path.
@jimmidyson jimmidyson force-pushed the fix/NCN-114223-bump-go-containerregistry branch from 850732a to 1a23172 Compare May 19, 2026 17:39
@github-actions

Copy link
Copy Markdown
Contributor

e2e test results

59 tests  ±0   59 ✅ ±0   3m 14s ⏱️ -24s
 3 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 1a23172. ± Comparison against base commit 02e9b57.

@jimmidyson jimmidyson merged commit fc6722c into main May 19, 2026
11 of 12 checks passed
@jimmidyson jimmidyson deleted the fix/NCN-114223-bump-go-containerregistry branch May 19, 2026 17:57
jimmidyson pushed a commit that referenced this pull request May 19, 2026
🤖 I have created a release *beep* *boop*
---


## 1.26.0 (2026-05-19)

<!-- Release notes generated using configuration in .github/release.yaml
at main -->

## What's Changed
### Exciting New Features 🎉
* feat: push OCI/docker image archive tarballs (NCN-113655) by
@jimmidyson in #1038
### Fixes 🔧
* fix: Allow same-host private/loopback registry bearer realms
(NCN-114223) by @jimmidyson in
#1046
### Other Changes
* build: bump Go toolchain to 1.26.3 by @jimmidyson in
#1048


**Full Changelog**:
v1.25.4...v1.26.0

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: mesosphere-actions-pr-bot[bot] <157582460+mesosphere-actions-pr-bot[bot]@users.noreply.github.com>
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.

2 participants