fix(r2): return source digest/size for mounted blob HEAD responses#121
Open
mushanyoung wants to merge 1 commit intocloudflare:mainfrom
Open
fix(r2): return source digest/size for mounted blob HEAD responses#121mushanyoung wants to merge 1 commit intocloudflare:mainfrom
mushanyoung wants to merge 1 commit intocloudflare:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title
fix(r2): return source digest/size for mounted blob HEAD responses
Summary
Mounted layers in the R2 backend are stored as lightweight "symlink" objects (body like
<repo>/blobs/<digest>).HEAD /v2/:name/blobs/:digestcould return metadata from that symlink object instead of the mounted source blob.This caused invalid blob metadata in HEAD responses for mounted layers, including:
Docker-Content-DigestContent-Lengthvalues (commonly around path-string length such as86)Those headers are consumed by OCI clients during push/pull validation and can surface as unauthorized/manifest-corruption style failures in downstream workflows.
Root Cause
Two pieces combined into the bug:
mountExistingLayerstores a symlink object whose checksum represents the symlink payload bytes (the path string), not the mounted source blob digest.HEADroute read R2 object metadata directly (env.REGISTRY.head(...)), bypassing symlink resolution logic.Result: for mounted blobs, HEAD returned symlink metadata instead of source blob metadata.
Changes
1) Persist source metadata on new symlink objects
File:
src/registry/r2.tsX-Serverless-Registry-Symlink-DigestX-Serverless-Registry-Symlink-Size2) Resolve symlinks in
layerExists(including old symlinks)File:
src/registry/r2.ts<repo>/blobs/<digest>, then recursively querylayerExistson the source target.3) Route blob HEAD through
layerExistsFile:
src/router.tsHEAD /v2/:name+/blobs/:tagto useenv.REGISTRY_CLIENT.layerExists(name, tag)for local lookups.4) Add regression assertions
File:
test/index.test.tsDocker-Content-Digest == layer digestContent-Length == source blob byte lengthReproduction (before this patch)
repoA.repoBthat mounts the same layer fromrepoA.HEAD /v2/repoB/blobs/<mounted-layer-digest>.Content-Lengthcan be tiny (e.g. path-length values such as86)Behavior After Patch
For mounted blobs,
HEADnow returns source blob metadata (digest + size), including for previously-created symlink objects.Compatibility and Risk
Test Plan
Executed:
npm test -- test/index.test.ts -t "Upload manifests with recursive layer mounting"npm test -- test/index.test.tsBoth pass.