Skip to content

feat: store full reference in ref.name during oras backup - #1904

Merged
TerryHowe merged 10 commits into
oras-project:mainfrom
AustinAbro321:add-title-annotation
Nov 25, 2026
Merged

TerryHowe merged 10 commits into
oras-project:mainfrom
AustinAbro321:add-title-annotation

Conversation

@AustinAbro321

@AustinAbro321 AustinAbro321 commented Nov 13, 2025 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

oras backup now stores the full reference of each artifact (e.g. localhost:5000/repo:v1) in org.opencontainers.image.ref.name in the backup's index.json, instead of only the tag. Tools that read backups, such as air-gap packaging tools, can then tell what each image was named when it was backed up. This follows docs/proposals/backup-restore-multi.md, but without the --full-reference flag: since backup and restore are experimental, backups always store the full reference. #2358 updates the proposal to match.

An earlier version of this PR put the reference in org.opencontainers.image.title. That was dropped, because oras pull treats the title as a file name and the status output uses it as the node name.

  • Backup: passes the full reference to Tag on the OCI store, which writes it to ref.name. No title annotation is set.
  • Restore: takes the tag out of each ref.name value and pushes under that tag. Backups created by earlier versions, which store only the tag, still restore. Tags given on the command line are matched against the parsed tags. Restore fails if two stored references would restore to the same tag.
  • Tests: unit tests for parsing ref.name, for restoring full-reference and tag-only backups, and for the backup's index.json. The e2e backup test now checks for the full reference, and a new e2e test restores a tag-only backup.

Compatibility: earlier ORAS versions cannot restore backups created with this change, because they use the ref.name value as the destination tag. Backups created by earlier versions can still be restored by this version.

Which issue(s) this PR fixes
Fixes #1893

Please check the following list:

  • Yes Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • No Does this change require a documentation update? The proposal update is in docs: record full references and support multiple registries in backup proposal #2358
  • Yes Does this introduce breaking changes that would require an announcement or bumping the major version? The backup format changes and should be called out in the release notes. backup/restore are experimental, so no major version bump
  • NA Do all new files have an appropriate license header?

Signed-off-by: Austin Abro <[email protected]>
Signed-off-by: Austin Abro <[email protected]>
Signed-off-by: Austin Abro <[email protected]>
@FeynmanZhou

FeynmanZhou commented Dec 10, 2025 •

Copy link
Copy Markdown
Member

Hi @AustinAbro321 ,

This proposal from @shizhMSFT should help clarify the scenario and define the desired experience to add full image reference to anootations. Would you mind reviewing this PR? #1917

We should implement this with a more holistic design and consider multi-repo backup and restore scenario.

@AustinAbro321

Copy link
Copy Markdown
Contributor Author

Yup just gave it a review. It would solve what I'm looking for. Let me know you're preferred next steps.

If you'd like I could implement the --full-reference flag for only single image repositories for now. Otherwise I can wait for the proposal to be merged and for y'all to implement this feature.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions Bot added the stale Inactive issues or pull requests label Jan 25, 2026
@TerryHowe TerryHowe added keep open and removed stale Inactive issues or pull requests labels Jan 25, 2026
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions Bot added the stale Inactive issues or pull requests label Mar 12, 2026
@TerryHowe
TerryHowe requested a review from sabre1041 as a code owner March 18, 2026 13:42
@TerryHowe TerryHowe removed the stale Inactive issues or pull requests label Mar 18, 2026
@TerryHowe TerryHowe added this to the v1.4.0 milestone Mar 18, 2026
@TerryHowe

Copy link
Copy Markdown
Member

Hi Austin, nice to chat with you today. If you have the bandwidth, I think the new e2e tests threw off the indexes. I do not like they way they are fragile, but that is a topic for another PR.

  [FAIL] ORAS users: when restoring a single tag [It] should successfully restore a multi-arch artifact without referrers from a directory
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when restoring a single tag [It] should successfully restore an image without referrers from a tar file
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when backing up a single tag [It] should back up a multi-arch image (itself has no referrers), child images and referrers of the child images, to a directory
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when backing up multiple tags [It] should backup all specified tags
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when restoring multiple tags [It] should restore multiple specified tags without referrers from a directory
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when backing up a single tag [It] should successfully backup a multi-arch artifact to a directory
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when backing up a single tag [It] should successfully backup an image to tar file
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when backing up a single tag [It] should successfully backup an image to tar file (case insensitive)
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when backing up multiple tags [It] should auto-discover and back up all tags when no tag is specified
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when restoring a single tag [It] should successfully restore an image without referrers from a directory
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when restoring a single tag [It] should restore a multi-arch image with child images and referrers of the child images
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when restoring a single tag [It] should successfully restore a multi-arch artifact without referrers from a tar file
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when backing up a single tag [It] should successfully backup an image to a directory
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when using --concurrency flag [It] should successfully backup with custom concurrency level
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when restoring multiple tags [It] should restore all tags without referrers when no specific tags are provided
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196
  [FAIL] ORAS users: when using --concurrency [It] should successfully restore with custom concurrency level when --concurrency flag is used
  /home/runner/work/oras/oras/test/e2e/internal/utils/match/status.go:196

@Rohilalala Rohilalala left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up, Austin. Having the full reference in a backup would be really handy.

I ran it locally and hit a side effect. oras pull treats anything carrying org.opencontainers.image.title as a file to save, so pulling --oci-layout backup:v1 now also writes the manifest JSON to ./localhost:5077/demo:v1, and it overwrites whatever is already there. Released oras clients do the same with backups made this way.

The title is also used as the display name in the progress output, so the root shows up as the full ref. I think that's what's failing the 16 backup/restore e2e tests Terry listed: I ran those specs against zot and got 16 "status output doesn't match" failures with this branch and none with main. So it's the names, not the indexes.

Since this was opened, #1917 landed with a --full-reference flag that stores the ref in org.opencontainers.image.ref.name instead. Would you be up for moving this toward that, single-repo only for now like you offered? I think it sidesteps both problems.

Comment thread cmd/oras/root/backup.go Resolved
Comment thread cmd/oras/root/backup.go Resolved
Comment thread test/e2e/suite/command/backup.go Resolved
@TerryHowe

Copy link
Copy Markdown
Member

Hi @AustinAbro321, thanks for sticking with this one. I'd like to get it moving again, and I think the scope can be smaller than the #1917 proposal suggests.

Why not org.opencontainers.image.title: @Rohilalala's finding holds up. oras pull and the progress display treat a title as a file name. Pulling from a backup layout would write the manifest JSON to a path like ./localhost:5000/repo:v1, and released clients would do the same. The title also changes the node names in the status output, which is what's breaking the 16 backup/restore e2e tests. oras restore reads org.opencontainers.image.ref.name, not the title, so ORAS itself wouldn't get any use out of it either.

Suggested approach: One correction: #1917 only merged the proposal doc, and --full-reference isn't implemented yet. Since backup and restore are still experimental, I don't think we need the opt-in flag or the compatibility handling. How about:

  1. oras backup always writes the full reference to org.opencontainers.image.ref.name (e.g. localhost:5000/repo:v1) instead of just the tag.
  2. oras restore parses the tag out of a full-reference ref.name, and still accepts tag-only values from existing backups. Right now it uses ref.name directly as the destination tag, so a full reference would fail without this.
  3. Optional, and could be a follow-up: if the destination is omitted, oras restore defaults to the registry/repository stored in the reference.

Single-repo only is fine for now, like you offered. Multi-repo can build on it later. Unit tests for the reference parsing in restore would be great, along with updated e2e expectations.

Does that work for you? Happy to help with the e2e side if the status matching gets annoying.

@TerryHowe TerryHowe 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 sticking with this, @AustinAbro321. The agreed design in docs/proposals/backup-restore-multi.md stores the full reference in org.opencontainers.image.ref.name rather than org.opencontainers.image.title. Moving to that also fixes the two problems Rohilalala found: oras pull writing the manifest to a path named after the reference, and the 16 e2e failures caused by the title renaming the root node in the status output.

One change from the proposal: please don't add the --full-reference flag. It was never implemented, and since backup/restore are experimental, backups should always store the full reference. #2358 updates the proposal to match.

The inline suggestions cover backup and its test. oras backup already calls Tag on the OCI store with the tag, and the store writes that value into ref.name, so passing the full reference there is enough. No annotation needs to be set by hand.

Restore also needs a change (outside this diff). oras restore currently uses each ref.name value from the layout as both the source and the destination tag (oras.Copy(ctx, srcOCI, tag, trackedDst, tag, ...)), so a full reference would fail at the push. Something like:

// tagFromRefName returns the tag stored in an org.opencontainers.image.ref.name value.
// Backups made by earlier versions store only the tag.
func tagFromRefName(name string) (string, error) {
	if !strings.Contains(name, "/") {
		return name, nil
	}
	ref, err := registry.ParseReference(name)
	if err != nil {
		return "", err
	}
	if err := ref.ValidateReferenceAsTag(); err != nil {
		return "", fmt.Errorf("%q does not reference a tag: %w", name, err)
	}
	return ref.Reference, nil
}

Then in runRestore:

  • List the ref.name values from the source layout. Keep the full value as the source reference and use tagFromRefName for the destination tag: oras.Copy(ctx, srcOCI, srcRef, trackedDst, dstTag, copyOpts) and recursiveCopy(ctx, srcOCI, trackedDst, dstTag, roots[i], ...).
  • When the user names tags (oras restore --input backup localhost:5000/repo:v1), match them against tagFromRefName(...) instead of resolving them directly. A full-reference backup has no entry stored under the bare tag v1.
  • Report the destination tag in the metadata/status output so it stays the same as today.
  • Fail if two entries in the backup produce the same tag. That can't happen with a single-repository backup, but it guards against multi-repository backups later.

Tests:

  • A unit test for tagFromRefName: tag-only, host/repo:tag, a host with a port (localhost:5000/repo:v1), and a digest reference, which should error.
  • An e2e round trip: backup → restore → the tag resolves in the destination registry.
  • An e2e restore from a tag-only backup, so backups made by earlier versions keep working.

The branch is also behind main, which has since moved to oras-go v3 and split the backup loop out into doBackup. It merges cleanly, but a rebase would make CI meaningful. Happy to help with any of this.

Comment thread cmd/oras/root/backup.go Resolved
Comment thread cmd/oras/root/backup.go Resolved
Comment thread cmd/oras/root/backup.go Resolved
Comment thread test/e2e/suite/command/backup.go Resolved
Comment thread test/e2e/suite/command/backup.go Resolved
oras restore now parses the tag out of each org.opencontainers.image.ref.name value instead of using the value as the destination tag. Backups created by earlier versions, which store only the tag, still restore. Tags named on the command line are matched against the parsed tags.

Signed-off-by: Terry Howe <[email protected]>
oras backup now stores the full reference (e.g. localhost:5000/repo:v1) in org.opencontainers.image.ref.name, as described in docs/proposals/backup-restore-multi.md, and no longer sets org.opencontainers.image.title. The title is treated as a file name by oras pull and renamed the root node in the status output.

Signed-off-by: Terry Howe <[email protected]>
@TerryHowe TerryHowe changed the title feat: add title annotation during oras backup feat: store full reference in ref.name during oras backup Nov 25, 2026
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.73%. Comparing base (46eb58a) to head (b247eeb).

Files with missing lines Patch % Lines
cmd/oras/root/backup.go 57.14% 3 Missing and 3 partials ⚠️
cmd/oras/root/restore.go 95.65% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1904      +/-   ##
==========================================
+ Coverage   90.68%   90.73%   +0.04%     
==========================================
  Files         156      156              
  Lines        6625     6681      +56     
==========================================
+ Hits         6008     6062      +54     
+ Misses        362      360       -2     
- Partials      255      259       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

registry.ParseReference and Reference.Reference are deprecated in oras-go v3.

Signed-off-by: Terry Howe <[email protected]>
Backups store tagged artifacts under their full reference, which the --oci-layout <path>:<tag> form cannot address. Read the backup with --oci-layout-path and the full reference instead, and look up child images and referrers by digest.

Signed-off-by: Terry Howe <[email protected]>
When tags are specified, oras restore now only checks the entries it restores, so an unparsable or duplicate entry for another tag no longer fails the whole restore. Restoring all tags still rejects them. Tag-only entries are validated as tags.

oras backup now removes a tag-only entry for a tag it backs up, so backing up into an output created by an earlier version does not leave two entries that restore to the same tag.

Signed-off-by: Terry Howe <[email protected]>

@TerryHowe TerryHowe 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.

/lgtm

@TerryHowe
TerryHowe merged commit b07be87 into oras-project:main Nov 25, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Store full image reference during oras backup

4 participants