Skip to content

Conversation

lsm5
Copy link
Member

@lsm5 lsm5 commented Oct 6, 2025

Depends on (and includes changes from) #374 and #375 . Maybe better to let those go in separately before this one.

(cursor assisted).

@github-actions github-actions bot added storage Related to "storage" package common Related to "common" package image Related to "image" package labels Oct 6, 2025
Copy link
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

Just an extremely brief skim.

I strongly suspect that the existing approach of accepting arbitraryRepo:arbitraryTag and sha256:digestValue in the same strings does not scale and is not sustainable . Doesn’t this break existing deployments where the repo name is sha512?

I don’t know what to actually do here, mind.

imageName = "sha256:" + storageName[1:]
// Use the configured digest algorithm for the image name
digestAlgorithm := supportedDigests.Get()
imageName = digestAlgorithm.String() + ":" + storageName[1:]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for imageID

Copy link
Contributor

Choose a reason for hiding this comment

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

(See below about getImageID)

return "sha256:" + name, nil
// Use the configured digest algorithm for the image ID
digestAlgorithm := supportedDigests.Get()
return digestAlgorithm.String() + ":" + name, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

getImageID knows which algorithm was used, and it’s not necessarily this one. Applies in several other places.

Comment on lines 170 to 183
// Test SHA512 digest computation
sha512Digest1 := digest.SHA512.FromBytes(manifest1)
sha512Digest2 := digest.SHA512.FromBytes(manifest2)
sha512Digest3 := digest.SHA512.FromBytes(manifest3)

// Verify that SHA512 and SHA256 produce different digests
assert.NotEqual(t, digest1, sha512Digest1, "SHA512 and SHA256 digests should be different")
assert.NotEqual(t, digest2, sha512Digest2, "SHA512 and SHA256 digests should be different")
assert.NotEqual(t, digest3, sha512Digest3, "SHA512 and SHA256 digests should be different")

// Verify algorithm strings
assert.Equal(t, "sha256", digest1.Algorithm().String(), "original digest should be SHA256")
assert.Equal(t, "sha512", sha512Digest1.Algorithm().String(), "SHA512 digest should have correct 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 testing anything in this package?!

@lsm5 lsm5 force-pushed the common-agile-digest branch 2 times, most recently from 5c325c0 to 7ef06bb Compare October 8, 2025 00:45
@lsm5
Copy link
Member Author

lsm5 commented Oct 8, 2025

I strongly suspect that the existing approach of accepting arbitraryRepo:arbitraryTag and sha256:digestValue in the same strings does not scale and is not sustainable . Doesn’t this break existing deployments where the repo name is sha512?

Added a common/pkg/digestutils package to handle this and other cases. With this vendored into buildah, and a Containerfile like:

FROM fedora@sha256:40f5b359d76ac10a563387e9e95efaa09db979b12b0ff8ad17bde1ac89c594b4
RUN dnf -y install bats

and buildah build --digest sha512 -f $CONTAINERFILE -t sha512 , I get:

$ ./bin/buildah images --no-trunc 
REPOSITORY                          TAG      IMAGE ID                                                                                                                                  CREATED              SIZE
localhost/sha512                    latest   sha512:4f41c3cc5184119d2e6263ed6031948ae9f73613b245bfb13485bad562cd9e67ae42d7de9f6dd105fc811980418ca5d91976e60eff6048bf88e50637c94286d9   About a minute ago   306 MB
registry.fedoraproject.org/fedora   latest   sha256:6d1eb9616ac6246b3c2fe49ec5fef7a913eee5bf28e919f6dd8ea7604cc088c2                                                                   42 hours ago         170 MB

Let me know if that still doesn't address your concern.

Accounted for getImageID too and cleaned up the unnecessary tests.

PTAL. Thanks again!

@lsm5 lsm5 marked this pull request as ready for review October 8, 2025 01:18
@lsm5 lsm5 mentioned this pull request Oct 8, 2025
lsm5 added 2 commits October 8, 2025 09:10
- Replace hardcoded SHA256 with configurable digest algorithms using storage/pkg/supported-digests
- Add centralized digest validation utilities in image/pkg/digestvalidation
- Implement parameterized digest computation in image/copy/single.go
- Rename DigestIfCanonicalUnknown to DigestIfConfiguredUnknown for clarity

Signed-off-by: Lokesh Mandvekar <lsm5@redhat.com>
- Create common/pkg/digestutils package with comprehensive digest handling functions
  * IsDigestReference() for robust digest detection using go-digest library
  * ExtractAlgorithmFromDigest() for parsing digest strings with validation
  * HasDigestPrefix(), GetDigestPrefix(), TrimDigestPrefix() for scalable prefix handling
- Update libimage to use digestutils instead of hardcoded SHA256/SHA512 checks
  * Replace strings.HasPrefix() calls in filters.go, image.go, runtime.go
  * Support only SHA256 and SHA512 algorithms as per container-libs requirements
- Update existing libimage tests to work with new digestutils functions

Signed-off-by: Lokesh Mandvekar <lsm5@redhat.com>
@lsm5 lsm5 force-pushed the common-agile-digest branch from 7ef06bb to 64cf4e0 Compare October 8, 2025 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to "common" package image Related to "image" package storage Related to "storage" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants