Skip to content

feat: add the experimental oras check command - #2362

Merged
TerryHowe merged 7 commits into
oras-project:mainfrom
Branson404:feat/oras-check-2359
Nov 25, 2026
Merged

TerryHowe merged 7 commits into
oras-project:mainfrom
Branson404:feat/oras-check-2359

Conversation

@Branson404

@Branson404 Branson404 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Adds oras check, an experimental command that verifies one artifact, in a registry or an OCI image layout, is complete and intact. It reads the manifest, config and every layer, matches each against its digest and size, reports every problem it finds (not only the first), and exits non-zero if anything fails.

This is step 1 of 3 from #2359 (part of #1791). Referrers and whole layouts (#2360), and multiple tags, formatted output and TTY progress (#2361), are not included.

Design, following #2359:

  • oras.Resolve (with --platform), then oras.VerifyGraph with a custom FindSuccessors that checks each manifest body against its descriptor's media type and includes the config and the subject.
  • Failures are missing, corrupt, invalid or unable to check. Only proven corruption is called corrupt, so a short read is corrupt in a layout but "unable to check" from a registry, where it can be a dropped connection.
  • An absent subject is a warning. Foreign layers are counted, not checked. The summary is sorted, so output is stable.
  • Layouts are read without loading their graph, so one corrupt manifest does not block an intact tag next to it.
  • Open points in Add oras check to verify the integrity of an artifact #2359 follow its "Proposal" lines. --concurrency of 0 or less uses the oras-go default (8).

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 #2359

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update? The command reference on oras.land is generated from the command help, which is included here. A how-to guide could follow once steps 2 and 3 land.
  • Does this introduce breaking changes that would require an announcement or bumping the major version? No. It adds a new experimental command and changes no existing command, flag, output or exit code.
  • Do all new files have an appropriate license header?

Testing

  • Unit tests cover the cases listed in Add oras check to verify the integrity of an artifact #2359 (intact, missing, corrupt, truncated, trailing data, invalid manifests, nested indexes, foreign layers, subject cases, cancellation, output order, --platform, directory and tar layouts, registry errors) plus command-level tests.
  • Run locally: go test -race -coverpkg=./... ./... passes, golangci-lint with the repo config reports no issues, go mod tidy leaves no diff, and the CLI builds for every Makefile target.
  • E2E: test/e2e/suite/command/check.go has 17 specs for the scenarios in Add oras check to verify the integrity of an artifact #2359: an intact artifact in a layout and in a registry, a corrupt layout with a non-zero exit, --platform, a manifest nested in an index, a missing layer and the argument errors. I ran them locally against a registry:2 container and a stand-in login server, since I have no Kubernetes cluster for the repo's Zot setup, so they have not run against Zot or the CI setup.
  • Not run: CodeQL and the image label check.

For reviewers: about 480 lines of code in one new file, and the rest of the diff is tests. cmd.go gets one line.

Add `oras check`, which verifies that one artifact in a registry or an OCI
image layout is complete and intact. It reads the manifest, config and every
layer and proves each matches its digest and size, continues after a failure,
and reports every problem. Part of oras-project#1791, step 1 of 3 as described in oras-project#2359.

It resolves the reference, then walks the graph with oras.VerifyGraph and a
successor finder that checks each manifest body against the media type of its
descriptor and includes the config and the subject. Failures are classified as
missing, corrupt, invalid or unable to check, and only proven corruption is
called corrupt. A subject that is absent is a warning. Layouts are read without
loading their graph, so one corrupt manifest does not stop an intact tag next
to it from being checked. The summary is sorted, and the command exits non-zero
if anything failed.

Refs oras-project#2359

Signed-off-by: branson404 <[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.

Issue #2359: E2E tests (intact artifact in a registry and a layout, corrupt layout with non-zero exit, --platform) are not addressed.

Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Print a Verified or Failed line for every node by turning on verbose
output for the command, because most manifests, configs and layers have
no title and were hidden. Find a manifest nested in an index by its
digest in a layout, by falling back to the blob storage when the digest
is not listed in the top-level index.json. Treat only the exact media
types that oras-go drops as foreign layers, so other types are verified.
Clarify the comment on a walk that stops early.

Add e2e specs for oras check: an intact artifact in a layout and in a
registry, a manifest nested in an index, --platform, a corrupt layer, a
missing layer, several problems at once, and the argument errors.

Refs oras-project#2359

Signed-off-by: branson404 <[email protected]>
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
…ted verbose flag

A blob over 4 MiB that is resolved by digest got a truncated size, so an intact layer was reported as corrupt (trailing data). Count the rest of the blob to get its real size.

Also drop the deprecated --verbose flag; a new command does not need it, and the output is always verbose.

Signed-off-by: branson404 <[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

… manifests

An absent subject was counted in the total but is neither verified nor failed, so the summary did not add up. Leave it out of the total.

Reject a manifest or index larger than 4 MiB as invalid before reading it into memory.

Signed-off-by: branson404 <[email protected]>
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.20979% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.71%. Comparing base (b07be87) to head (34c71d2).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cmd/oras/root/check.go 90.17% 16 Missing and 12 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2362      +/-   ##
==========================================
- Coverage   90.73%   90.71%   -0.03%     
==========================================
  Files         156      157       +1     
  Lines        6681     6967     +286     
==========================================
+ Hits         6062     6320     +258     
- Misses        360      376      +16     
- Partials      259      271      +12     

☔ 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.

Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check.go Resolved
Comment thread cmd/oras/root/check_test.go Resolved
Comment thread cmd/oras/root/check_test.go Resolved
Branson404 and others added 3 commits November 25, 2026 18:38
…ersized manifest as unable to check

An oversized manifest is not proof that the content is invalid, only that it was not read.

Signed-off-by: branson404 <[email protected]>
Resolve a duplicate tag in a layout to the last match, as oras-go does.
Refuse an oversized blob that may be a manifest when it is looked up by
digest, instead of checking only its bytes. Do not take an image config
for a manifest, and accept an artifact manifest without blobs. Correct
the comment on the size limit.

Signed-off-by: Terry Howe <[email protected]>
Cover a duplicate tag, an image config and an oversized manifest looked
up by digest, and an artifact manifest without blobs.

Signed-off-by: Terry Howe <[email protected]>
@TerryHowe
TerryHowe merged commit 6370c7e into oras-project:main Nov 25, 2026
10 checks passed
@TerryHowe

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add oras check to verify the integrity of an artifact

2 participants