Skip to content

Conversation

@lsm5
Copy link
Member

@lsm5 lsm5 commented Nov 26, 2025

Add a new manifest.DigestWithAlgorithm function that
allows computing the digest of a manifest using a specified algorithm
(e.g., SHA256, SHA512) while properly handling v2s1 signed manifest
signature stripping.

This addresses the need for skopeo's --manifest-digest flag to support
different digest algorithms while correctly handling all manifest types,
particularly Docker v2s1 signed manifests that require signature
stripping before digest computation.

Note: Currently rebased on #475 .

lsm5 added 2 commits November 26, 2025 14:23
When storing blobs with non-canonical digest algorithms (e.g., sha512),
store the blob under the provided digest algorithm with an algorithm
prefix (e.g., "sha512-abc" instead of just "abc").

SHA256 (canonical) digests continue to be stored without a prefix for
backward compatibility.

Signed-off-by: Lokesh Mandvekar <[email protected]>
Introduce version 1.2 and dynamically assign versions based on the digest
algorithms used:
- Version 1.1 for sha256-only images (backward compatibility)
- Version 1.2 for images using non-sha256 digest algorithms (e.g., sha512)

Add validation in both ImageDestination and ImageSource to:
- Assume 1.1 if no version file found in dir transport images
- Accept both version 1.1 and 1.2
- Refuse unsupported future versions

Signed-off-by: Lokesh Mandvekar <[email protected]>
@github-actions github-actions bot added the image Related to "image" package label Nov 26, 2025
Add a new `manifest.DigestWithAlgorithm` function that
allows computing the digest of a manifest using a specified algorithm
(e.g., SHA256, SHA512) while properly handling v2s1 signed manifest
signature stripping.

This addresses the need for skopeo's `--manifest-digest` flag to support
different digest algorithms while correctly handling all manifest types,
particularly Docker v2s1 signed manifests that require signature
stripping before digest computation.

Signed-off-by: Lokesh Mandvekar <[email protected]>
@lsm5 lsm5 force-pushed the digest-redux-manifest branch from e1149c9 to bdbac34 Compare November 26, 2025 19:40
@lsm5 lsm5 changed the title manifest: Add DigestWithAlgorithm function image/manifest: Add DigestWithAlgorithm function Nov 26, 2025
@packit-as-a-service
Copy link

Packit jobs failed. @containers/packit-build please check.

podmanbot pushed a commit to podmanbot/buildah that referenced this pull request Nov 26, 2025
@podmanbot
Copy link

✅ A new PR has been created in buildah to vendor these changes: containers/buildah#6541


// Digest returns the a digest of a docker manifest, with any necessary implied transformations like stripping v1s1 signatures.
// This is publicly visible as c/image/manifest.Digest.
func Digest(manifest []byte) (digest.Digest, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

With Digest just a { return DigestWithAlgorithm(manifest, digest.Canonical } it would be 100% clear what the correspondence between the two functions is, and we would decrease the risk of divergence.

Comment on lines +103 to +105
sha256Digest, err := DigestWithAlgorithm(manifest, digest.SHA256)
require.NoError(t, err)
assert.NotEqual(t, sha256Digest, actualDigest, c.path)
Copy link
Contributor

Choose a reason for hiding this comment

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

No

require.NoError(t, err)
actualDigest, err := DigestWithAlgorithm(manifest, digest.SHA512)
require.NoError(t, err)
assert.Equal(t, digest.SHA512, actualDigest.Algorithm())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not particularly precise…

I think

  • The empty input can be reasonably included in the test case table
  • The test case table can contain exact sha256 and sha512 digests

Then TestDigest and TestDigestWithAlgorithm can work from a shared table, differing only in whether they process 1 / 2 values.

Alternatively, if Digest became just a wrapper over DigestWithAlgorithm, it would be acceptable to have comprehensive tests only for …WithAlgorithm (more precise than the current ones), and a ~smoke-test for Digest. (I weakly prefer the shared table and thorough testing of both.)

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

Labels

image Related to "image" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants