Repository navigation
Description
What is the version of your ORAS CLI
v1.4.0 / main (oras-go v3.0.0)
What would you like to be added?
Part of #1791. This is the first of three steps: an [Experimental] oras check command that verifies one artifact in a registry or an OCI image layout, using the verification API that shipped in oras-go v3.0.0 (oras-project/oras-go#1493).
oras check [flags] <name>{:<tag>|@<digest>}
Scope
- Verify the manifest (or index and its manifests), config and layers of one artifact, by tag or digest. Continue after a failure and report every problem found.
- Flags:
--oci-layout,--oci-layout-path,--platform,--concurrency. - Plain text status output and a summary in a stable order.
- Non-zero exit code if anything fails.
Referrers and whole-layout checks are in #2360. Multiple tags, formatted output and TTY progress are in #2361.
Evaluation
Feasible now with no blockers. Effort is medium: one command, small display handlers, and a test matrix larger than the code. The change is additive and read-only, so the main risk is a wrong result: passing an artifact that was not fully checked, or reporting corruption that is not there.
These behaviors were observed in scratch tests against oras-go v3.0.0:
| Scenario | Result | What oras check needs to do |
|---|---|---|
| Image manifest body with an index media type in its descriptor | Passes, and the layers are never checked | Compare the body with the descriptor media type |
| Walk cancelled midway | Returns an error, but report.OK() is true |
Check the error before OK() |
| Registry: corrupt root manifest | oras.Verify returns an error and a nil report; Resolve then VerifyGraph reports a failed node |
Use Resolve then VerifyGraph |
| Registry: 403 or 5xx for a blob | Failed node | Do not report it as corruption |
Registry: connection dropped, or short blob without Content-Length |
Both are io.ErrUnexpectedEOF |
The two cannot be told apart |
Registry: blob with the wrong Content-Length |
Failed node with a plain mismatch Content-Length error, no sentinel or sizes |
Cannot be classified without matching text |
| Digest is valid but the manifest is not JSON | Failed node with json.SyntaxError |
Report it as invalid |
Absent subject |
Failed node, not found | Warn only; see below |
| Non-distributable layer | Not in the report at all | Decide whether to print a note |
| Layout with one corrupt manifest | oci.NewFromFS and oci.NewFromTar fail, even to check a different, intact tag |
Use the graph-free storage; see below |
--platform on an image whose config is missing |
Resolve fails before there is a report |
Return a clear error |
| 20 runs of the same check | 20 different report orders, 8 concurrent PostVerify calls |
Sort the results; hooks must be safe for concurrent use |
Proposed implementation
-
Command. Add
cmd/oras/root/check.gowithoption.Common,option.Platform,option.Targetand--concurrency, modelled onresolve.go, and register it incmd/oras/root/cmd.go. Do not useoption.Cache; the check must read from the target, not fromORAS_CACHE. -
Source. Use
NewReadonlyTargetfor registries. For OCI layouts, useoci.NewStorageFromFSoroci.NewStorageFromTarand resolve the reference fromindex.json. This storage does not load the graph, so it can check an intact tag next to a corrupt one, and reports the corrupt one as a failed node. The oras-go tar file system is internal, soindex.jsonhas to be read from a tar separately. -
Walk. Call
oras.Resolve(settingTargetPlatformfor--platform, becauseVerifyOptionshas no platform filter), thenoras.VerifyGraphwith a customFindSuccessorsthat:- checks the body of each manifest against its descriptor media type;
- records which digests are reached by a subject edge and which by any other edge.
graph.Successorsininternal/graph/graph.goalready returns the subject and config separately; both must be included in the returned successors.
-
Classify each failure. Only report corruption that is proven.
Class Errors Missing errdef.ErrNotFoundCorrupt content.ErrMismatchedDigest,content.ErrTrailingData, andio.ErrUnexpectedEOFfor OCI layouts onlyInvalid JSON errors, invalid successor descriptors, body and descriptor media type mismatch Unable to check Everything else, including 401, 403, 5xx, network errors, and io.ErrUnexpectedEOFfrom a registry -
Report. Print status from
PreVerifyandPostVerify, then a summary sorted by class, media type and digest. -
Exit. Return the walk error first if there is one, otherwise a summary error if anything failed. The summary error must not wrap
errdef.ErrNotFoundorerrcode.ErrorResponse, becauseTarget.ModifyErrorwould present it as a registry error.
Design decisions to confirm
- Absent subject. The OCI image spec allows a subject that does not exist. Proposal: warn if it is absent, fail if it is present but fails verification. Only treat it as a warning if the error is not found, the digest is reached only by subject edges, and it is not a requested artifact. In this step the only requested artifact is the root, but with referrers (Support referrers and whole OCI layouts in
oras check#2360) or multiple tags (Support multiple tags, formatted output and TTY progress inoras check#2361) a requested artifact can also be reached as the subject of another node, and must still fail when it is missing. A prototype of this rule worked, including when an index also lists the subject. - Manifest body without
mediaType. The field is optional in OCI manifests. Proposal: allow it, and compare the shape of the body (manifestsorconfigandlayers) with the descriptor instead. - Registry size mismatch. Proposal: report it as unable to check until oras-go has a typed error, rather than match the error text. The
size mismatch (expected: 32, got: 42)output in Support content integrity detection #1791 also needs that typed error. - Foreign layers. Proposal: print the number that were not checked.
- Exit codes. Proposal: a single non-zero code for now.
--concurrency.VerifyGraphuses its default of 8 for zero or less, while fix: reject a negative --concurrency level #2351 proposes the wording "use 0 for no limit" for all commands.
Known limitations
- The check proves that content matches its digests. It does not detect a moved tag or prove who published the content. The help text should say so, and that every byte is downloaded.
- A truncated blob from a registry may be reported as unable to check instead of corrupt.
Tests
- Unit, content: intact artifact; missing blob; same-size corruption; truncated and trailing data; corrupt root manifest; invalid JSON; nested index; foreign layers; index media type on an image manifest with a missing layer.
- Unit, subject: absent; corrupt; present with a missing layer; absent and also listed in an index.
- Unit, registry: 401, 403 and 5xx; dropped connection; short blob with and without
Content-Length. - Unit, other: cancellation with a clean partial report; output order;
--platformwith no match and with a missing config; intact tag next to a corrupt one, in a directory and in a tar. - E2E: intact artifact in a registry and in a layout; corrupt layout with non-zero exit;
--platform.
Avoid the memory store for media type tests. It matches on media type as well as digest, so it reports the same content under a second media type as missing.
Related code
cmd/oras/root/resolve.go: closest command templatecmd/oras/internal/option/target.go:NewReadonlyTarget,EnsureReferenceNotEmpty,ModifyErrorinternal/graph/graph.go:Successorscmd/oras/internal/display/handler.go,status/interface.go,metadata/interface.go: handler patternscmd/oras/internal/output/print.go:PrintStatusis safe for concurrent use, but hides untitled blobs unlessVerboseis setcmd/oras/root/backup_test.go(Test_doBackup_handlerCalls) andtest/e2e/internal/utils/exec.go(MatchStatus): test patterns- oras-go v3.0.0:
verify.go,content/oci/readonlystorage.go
Why is this needed for ORAS?
There is no built-in way to check that a stored artifact is complete and intact. This step covers troubleshooting a failed pull and gating a CI/CD pipeline. The earlier drafts (#1801 and #1803) predate the oras-go API.
Are you willing to submit PRs to contribute to this feature?
- Yes, I am willing to implement it.
Activity
feat: add the experimental oras check command
fix(check): address review feedback and add e2e tests