Skip to content

Add sha512 support - #4946

Open
tianon wants to merge 1 commit into
distribution:mainfrom
tianon-sso:sha512
Open

tianon wants to merge 1 commit into
distribution:mainfrom
tianon-sso:sha512

Conversation

@tianon

@tianon tianon commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Verified against the OCI conformance suite (779 -> 950 passing tests, all core sha512 categories now green).

This also includes support for the (optional) ?digest-algorithm= query parameter (opencontainers/distribution-spec@eadf94b / opencontainers/distribution-spec#543) on blob uploading to pre-inform the registry of the final digest algorithm (so it can correctly digest in-progress instead of having to perform an expensive re-read / re-digest at commit).

Assisted-By: "claude my eyes right out"

@tianon

tianon commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Hmm this should really implement opencontainers/distribution-spec#543 too.

Edit: done

@tianon
tianon marked this pull request as draft August 31, 2026 22:53
@tianon
tianon marked this pull request as ready for review August 31, 2026 23:21
@tianon

tianon commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

(Tested against opencontainers/distribution-spec#623, which is also why I missed implementing that in the first place 😂)

@Vad1mo

Vad1mo commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Nice to see you are still engaged with registries @tianon!

I have made my agents run a few tests, and asked questions, related to throuput, ops calls etc.

Here are some of the returned findings, can you take a look at 2,3, not sure about 5

Tested locally: filesystem storage, PR head vs merge base 5b354e6f, distribution-spec conformance on main plus opencontainers/distribution-spec#623.

Suite Base pass/fail PR pass/fail
distribution-spec main 743 / 93 814 / 24
with #623 749 / 96 829 / 24

Every sha512 category passes and nothing regresses. The 24 remaining failures are the same on base: referrers, OCI-Subject, and a 500 on non-distributable layers.

Findings

  1. No unit tests. Nothing covers digest-algorithm (valid, unsupported, or different from the final digest), Create followed by Resume rebuilding the sha512 digester, or a manifest PUT/GET by sha512 digest.
  2. Resume adds a backend GET on every PATCH/PUT, including plain sha256 uploads (it 404s). On S3 that is a fourth call next to startedat, ListMultipartUploads and ListParts. The HMAC _state token already carries upload state across replicas, so putting the algorithm there would avoid the read. That needs Resume to accept options, the same way Create already does in this PR.
  3. The "written == size" fast path in validateBlob still compares against digest.Canonical. It should compare against the digester's algorithm. Resumption is only disabled in proxy mode, and the proxy calls Create with no options, so it should also pass WithDigestAlgorithm(dgst.Algorithm()). Without both changes, a pull-through cache reads every sha512 blob back from storage to verify it.
  4. sha384 is now accepted. crypto/sha512 also registers sha384, and a sha384 push returned 201 and created blobs/sha384/. The spec does not define sha384, so reject it explicitly or document it.
  5. Cross-algorithm dedup is gone. The same bytes pushed as sha256 and as sha512 are now stored twice. Base stored them once, with a sha512 link pointing at sha256 data. That layout looks unsafe for GC: mark records the sha512 digest, sweep walks blobs/sha256/, so the data looks unreferenced. I found that by reading garbagecollect.go and did not run GC to confirm. The new layout is the correct trade-off, but it is worth noting.

Behavior that checked out:

  • A sha512 hint followed by a commit with a sha256 digest returns 201 and stores the blob under sha256.
  • An unsupported hint returns 400 DIGEST_INVALID.
  • FromBytes in PutManifest cannot panic, because the router already runs digest.Parse on the URL digest.

Hash throughput, Go stdlib, Apple M1 Pro:

1 KB 8 KB
sha256 1.99 GB/s 1.99 GB/s
sha512 0.99 GB/s 1.07 GB/s

That is still well above per-connection network rates. Without the digest-algorithm hint, the full re-read at commit costs more than hashing does.

@tianon

tianon commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing! Good points all around. I've pushed a new commit to address your points (kept separate to make it easier to [re-]review), but I am perfectly happy to squash (or for this to be squash-merged).

  1. extended existing tests and added some new coverage

  2. did not change the signature of the Resume interface because that's a public interface and might be implemented outside dist/dist, but I'm happy to if the maintainers would prefer that breaking change (it now stores in the state token through a context helper so existing sha256 workflows are unaffected/unchanged)

  3. fast path fixed (and proxy declares the algorithm too)

  4. sha384 now rejected with DIGEST_INVALID appropriately (hint, commit digest, and manifest PUT by digest)

  5. the dedupe/GC effect is intentional -- the likelihood of a registry receiving the exact same content across multiple digest algorithms is very small, and the savings from dedupe there are probably a lot smaller than the cost of running two hashes on every sha512 push (but of course, if maintainers disagree I'm happy to change this); the older layout looked unsafe for GC at a glance (even though it had a link, it doesn't appear it was consulted during GC) but the new layout avoids that because content lives under the digest it's referenced as

@github-actions github-actions Bot added the area/proxy Related to registry as a pull-through cache label Oct 2, 2026
@tianon

tianon commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Had the paperclip counter go and actually verify the GC claims:

Method: I built two registries, one from the PR's merge base (5b354e6) and one from our PR, each with filesystem storage and its own empty data directory. On each I:

  1. pushed a layer blob and a config blob addressed by sha512;
  2. pushed a manifest by tag that references both;
  3. stopped the registry and ran garbage-collect, first with --dry-run and then for real;
  4. restarted the registry and fetched the layer, config and manifest.

Results:

  • Base:
    • The sha512 content was stored under blobs/sha256/.
    • GC marked the two sha512 digests but flagged the two sha256 data blobs for deletion, and it deleted them.
    • After GC, the layer and config returned 404 and the manifest returned 200, so the manifest was left pointing at deleted blobs.
  • PR:
    • The content was stored under blobs/sha512/.
    • GC marked the same digests and found 0 blobs eligible for deletion.
    • After GC, all three fetches returned 200.

Not covered: --delete-untagged, multiple repos, and manifest PUT by sha512 digest.

@milosgajdos

Copy link
Copy Markdown
Member

This is still broken and needs a bit more work.

Specifically, we the following 2 things would've been broken if we merged this:

  • proxy
  • manifest notifications

proxy

sha512 manifests never hit the proxy cache... manifeststore.Get calls localManifests.Put without the new WithDigest(dgst) option

_, err = pms.localManifests.Put(ctx, manifest)

so content is cached under sha256 instead of sha512 - this is easily reproducible, just ask your agent...

notifs

this one is tricky and without an agent it would've skipped past me - thanks AI Gods...

So, in

manifest, desc, err := distribution.UnmarshalManifest(mt, p)
if err != nil {
return nil, err
}
event.Target.MediaType = mt
event.Target.Digest = desc.Digest

UnmarshalManifest computes the default sha256 digest from the payload - it doesn’t know that this manifest was stored under sha512;

this digest

event.Target.Digest = desc.Digest
is calulated via UnmarshalManifest
func UnmarshalManifest(ctHeader string, p []byte) (Manifest, v1.Descriptor, error) {
which delegates to
func unmarshalOCISchema(b []byte) (distribution.Manifest, v1.Descriptor, error) {
(via unmarshalFunc(p)); that actually calls digest.FromBytes 👉
Digest: digest.FromBytes(b),
which computes sha256

Which we then set in

event.Target.Digest = desc.Digest

instead of the sha512 digest

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

This needs a bit more work 😅

@tianon

tianon commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Review updates (and a few bonus related edges I pressed to find while fixing those) are up in 98cffd6 -- I'll rebase/squash shortly, esp. to fix that conflict.

Accept, store, and serve content addressed by sha512 in addition to sha256, including through the pull-through proxy and in notification events.  Verified against the OCI conformance suite (all sha512 blob and digest-algorithm categories now pass).

Newly pushed content is limited to sha256 and sha512 (the `digest-algorithm` hint, the blob commit digest, and manifest PUT by digest), and anything else is rejected with `DIGEST_INVALID` -- `crypto/sha512` also registers sha384, but the spec does not define it.

This also adds the optional `?digest-algorithm=` blob upload parameter (opencontainers/distribution-spec@eadf94bb) so a client can pre-inform the registry of the final digest algorithm, which lets it digest in-progress instead of doing an expensive re-read / re-digest at commit.

- carry the declared `digest-algorithm` in the signed upload state and hand it to `Resume` via the new `storage.WithResumeDigestAlgorithm`, instead of persisting a file that every PATCH/PUT would have to read back (the public `Resume` signature is unchanged)
- compare against the digester's algorithm rather than `digest.Canonical` in the `validateBlob` "written == size" fast path, and declare the algorithm when the pull-through cache creates its local writer, so sha512 blobs that were just hashed while streaming are not read back from storage
- pass the requested digest through to the proxy's local manifest `Put`, so pull-through caches store sha512 manifests under sha512 (this also fixes the TTL expiry callback deleting a digest that was never stored)
- report the algorithm a manifest was stored under in push and pull notification events instead of always the canonical one
- recognize the empty blob for non-sha256 algorithms
- document `digest-algorithm` and sha512 in the API spec, and extend the blob upload, blob API, manifest API, proxy, and notification tests to cover sha512 with and without the hint, `Resume` rebuilding the digester, and rejection of sha384 and unknown algorithms

Assisted-By: "claude my eyes right out"
Signed-off-by: Tianon Gravi <[email protected]>
@milosgajdos

Copy link
Copy Markdown
Member

this is failing validation, alas

@tianon

tianon commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

That's a Docker Hub flake, not this change 😅

#16 [stage-2 1/1] RUN --mount=type=bind,target=.     --mount=type=cache,target=/root/.cache     --mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint     golangci-lint config verify &&     golangci-lint --timeout "5m" --build-tags "" run
#16 2.226 The command is terminated due to an error: [.golangci.yml] validate: compile schema: failing loading "https://golangci-lint.run/jsonschema/golangci.v2.9.jsonschema.json": Get "https://golangci-lint.run/jsonschema/golangci.v2.9.jsonschema.json": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
#16 ERROR: process "/bin/sh -c golangci-lint config verify &&     golangci-lint --timeout \"${TIMEOUT}\" --build-tags \"${BUILDTAGS}\" run" did not complete successfully: exit code: 3
------
 > [stage-2 1/1] RUN --mount=type=bind,target=.     --mount=type=cache,target=/root/.cache     --mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint     golangci-lint config verify &&     golangci-lint --timeout "5m" --build-tags "" run:
2.226 The command is terminated due to an error: [.golangci.yml] validate: compile schema: failing loading "https://golangci-lint.run/jsonschema/golangci.v2.9.jsonschema.json": Get "https://golangci-lint.run/jsonschema/golangci.v2.9.jsonschema.json": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

@milosgajdos

Copy link
Copy Markdown
Member

That's a Docker Hub flake, not this change 😅

Ah nice, I responded from phone when I saw this; retried from desktop now; all good; will review later. thanks

This branch has not been deployed

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

Labels

area/api area/docs area/proxy Related to registry as a pull-through cache area/storage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pushing a manifest with a sha512 digest fails

4 participants