Repository navigation
fix: keep an index's own children out of its reported referrers - #2174
Conversation
`oras cp -r` fails with MANIFEST_UNKNOWN against a registry that does not implement the Referrers API. Such a registry can resolve the referrers tag `sha256-<hex>` as the digest `sha256:<hex>` and answer with the index itself, so its own children are read back as its referrers. prepareCopyOption passes those through, and extended copy walks upwards from the index into the children, takes them for the graph roots and copies only their sub-graphs. The index is never pushed, so the root tagging in recursiveCopy asks the destination for a manifest that is not there. A successor can never be a predecessor, so drop any reported referrer the index already lists in `manifests`. The index is then left with no predecessors, becomes a graph root itself and is copied before it is tagged. Signed-off-by: somaz <[email protected]>
… survive Co-authored-by: Terry Howe <[email protected]> Signed-off-by: somaz <[email protected]>
f729054 to
9dcaca5
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2174 +/- ##
==========================================
- Coverage 87.81% 87.78% -0.04%
==========================================
Files 139 139
Lines 5689 5714 +25
==========================================
+ Hits 4996 5016 +20
- Misses 413 417 +4
- Partials 280 281 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
TerryHowe
left a comment
There was a problem hiding this comment.
Two follow-ups, plus a scope note.
Scope: oras discover still reports the phantom referrers — discover.go:173 calls registry.Referrers on the remote repo directly and has no equivalent filter, so an index there still lists its own children (the visited map stops the recursion, not the wrong output). oras attach has the same exposure one layer down, since oras-go's updateReferrersIndex shares the referrersFromIndex call that oras-go#1403 fixed. Not asking you to widen the PR — but worth a line in the description that cp -r and backup are the intended blast radius (backup --include-referrers gets this for free via recursiveCopy, restore and countReferrers read OCI layouts so they were never affected), and that the rest waits on a v2 backport of #1403.
…note Co-authored-by: Terry Howe <[email protected]> Signed-off-by: somaz <[email protected]>
|
Thanks! |
…-project#2174) Signed-off-by: somaz <[email protected]> Co-authored-by: Terry Howe <[email protected]>
What this PR does / why we need it:
oras cp -rfails withMANIFEST_UNKNOWNwhen the source registry does not implement the Referrers API. ORAS falls back to the referrers tag schema and requestssha256-<hex>; a registry that resolves that as the digestsha256:<hex>answers with the index itself, so the index's own children are read back as its referrers.prepareCopyOption(cmd/oras/root/cp.go:293) passes those through untouched.oras.ExtendedCopyGraphthen walks upwards from the index into the children, takes them for the graph roots and copies only their sub-graphs, so the index is never pushed. Thedst.Tagat cmd/oras/root/cp.go:279 asks the destination for a manifest that is not there, which is the 404 at the end of the log in the issue. It is also why a plainoras cpfollowed bycp -rsucceeds: the index is already at the destination by then.A successor can never be a predecessor, so this drops any reported referrer the index already lists in its own
manifests(cmd/oras/root/cp.go:327). The index is left with no predecessors, becomes a graph root itself and is copied before it is tagged. Genuine referrers are untouched, and a child that both appears inmanifestsand declares the index as its subject is still copied, as a successor.The upstream half of this report, oras-project/oras-go#1396, was fixed in oras-project/oras-go#1403 on oras-go
main, which is v3. This repo is onoras.land/oras-go/v2 v2.6.2and no v2 release carries it, so the failure still reproduces here.Scope: the fix covers
cp -randbackup, sincebackup --include-referrersgoes through the samerecursiveCopy.restoreandcountReferrersread OCI layouts, so they were never affected.oras discoverstill lists the phantom referrers, because it callsregistry.Referrerson the remote directly (cmd/oras/root/discover.go:173), andoras attachhas the same exposure one layer down in oras-go'supdateReferrersIndex. Those two wait on a v2 backport of oras-project/oras-go#1403.On the alternative suggested in the issue, an
oras.CopyGraphof the root beforedst.Tag: I built that first and measured a regression incp -r --force.--forcewraps the destination incontentutil.TraversingTarget(cmd/oras/root/cp.go:197), whoseExistsreturns false for every manifest media type (internal/contentutil/traverse.go:56), so the extraCopyGraphcannot short-circuit and walks the manifest graph a second time. Against two local registries that turned a 14 linecp -r --forceinto 20 lines, with the index and both child manifests pushed twice. Clearing the status callbacks does not cover the TTY path, because the progress rows come from the tracked target'sPushrather than from the handler. I am happy to switch to that shape if you prefer it.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #2148
Please check the following list:
Local validation (macOS arm64, Go 1.26.7):
go test -run Test_recursiveCopy_strandedRoot ./cmd/oras/root/on unmodified main:FAIL cp_test.go:666: recursiveCopy() error = failed to perform "Tag" on destination: sha256:d2ef7640...: application/vnd.oci.image.index.v1+json: not found. With the change:ok.go test -race ./...: all packages ok.go test -race -count=50 ./cmd/oras/root/ -run Test_recursiveCopy: ok.golangci-lint run ./...: 0 issues.gofmt -l cmd internal: clean.go vet ./...: clean.End to end against two local
registry:3instances, comparing this build with one built frommain. Copying a two platform index that carries a referrer: first copy, idempotent recopy andcp -r --forcerecopy all produce output identical tomain. The #1728 shape, an index with no referrer of its own but a referrer on one child, is also identical, and the child's referrer arrives at the destination.