fix(collector): fold Docker Hub registry-host aliases to docker.io#219
fix(collector): fold Docker Hub registry-host aliases to docker.io#219thomasboni wants to merge 1 commit into
Conversation
The image_authorized_sources policy does a literal go-wildcard match and performs no host canonicalisation. The collectors kept explicit registry hosts verbatim, so an image referenced via a Docker Hub alias hostname (registry.hub.docker.com, index.docker.io, registry-1.docker.io) was NOT matched by a docker.io/* trustedUrls pattern and got flagged ISSUE-101, even though it is the same image. Add a shared canonicalisation helper and apply it at parse time for both providers: - GitLab: parseImageLink now wraps the existing parser (renamed to parseImageReference) and folds i.Registry once, covering all ~19 registry-assignment sites uniformly. - GitHub: splitImageRef folds the leading host segment of the image name (GitHub refs keep the registry inside Name). This lets users drop the registry.hub.docker.com/* alias workaround from their trusted-registry config. Digest pins and bare/library forms are unaffected (already covered by the official fast-path and /* patterns). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
PR SummaryLow Risk Overview GitLab: New tests cover helpers, both parsers, and an OPA E2E check that alias refs authorize with only Reviewed by Cursor Bugbot for commit 48370e5. Bugbot is set up for automated code reviews on this repo. Configure here. |
Problem
The
image_authorized_sourcespolicy does a literalgo-wildcardmatch and performs no host canonicalisation. The collectors kept explicit registry hosts verbatim, so an image referenced via a Docker Hub alias hostname was not matched by adocker.io/*trustedUrlspattern and got flaggedISSUE-101— even though it is the same image.Example:
registry.hub.docker.com/library/node:alpinewas flagged despitedocker.io/library/*being trusted.Affected aliases (all resolve to Docker Hub):
registry.hub.docker.comindex.docker.ioregistry-1.docker.ioFix
Add a shared canonicalisation helper and apply it at parse time for both providers:
parseImageLink): now wraps the existing parser (renamedparseImageReference) and foldsi.Registryonce — covering all ~19 registry-assignment sites uniformly instead of editing each.splitImageRef): folds the leading host segment of the image name (GitHub refs keep the registry insideName).Both providers share the same
image_authorized_sources.rego, so this makes alias handling consistent across them.Impact
Users can drop
registry.hub.docker.com/*-style alias workarounds from their trusted-registry config. Digest pins and bare/library/forms are unaffected — they were already covered by thetrustDockerHubOfficialfast-path and/*patterns respectively.Tests
New
collector/registry_alias_normalization_test.go:canonicalizeDockerHubRegistryandfoldDockerHubAliasInNameparseImageLink(GitLab) andsplitImageRef(GitHub) fold aliases; non-Hub hosts untoucheddocker.io/library/*trusted (no alias pattern), a Hub-alias ref is authorized for both providers; a genuinely untrusted registry stays flaggedgo test ./collector/ ./policies/pass;go vetandgofmtclean.🤖 Generated with Claude Code