Skip to content

Conversation

lsm5
Copy link
Member

@lsm5 lsm5 commented Oct 6, 2025

Adds Get and Set methods for configuring digest. Currently, only sha256 and sha512 are supported, but should make future additions easier.

Defaults to sha256.

(cursor assisted)

Will create separate PRs for image and common.

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

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

@github-actions github-actions bot added the storage Related to "storage" package label Oct 6, 2025
@lsm5
Copy link
Member Author

lsm5 commented Oct 6, 2025

No other changes to storage for now. This will get used in other repos that depend on storage.

@lsm5 lsm5 marked this pull request as ready for review October 6, 2025 15:16
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.

What is the precise semantics of the “current” value? “digests to use when creating new things”? “the expected level of collision-resistance when pulling”? “digests to convert to when pushing”?

@lsm5
Copy link
Member Author

lsm5 commented Oct 6, 2025

“digests to use when creating new things”?

@mtrmac This. Let me know if I need to account for anything additionally here itself, unless it can wait for future work.

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.

  • Per the Podman PR, “digest to use when creating new objects” is conceptually more of a per-operation parameter. It’s not at all clear to me that we should have a c/storage-scoped per-process global for this. (E.g. perhaps we do need a global default for this, set in containers.conf or storage.conf, but the decision which algorithm to use might plausibly be best placed into the Podman CLI layer, and be passed as an explicit parameter. Also consider podman-remote, client-side vs. server-side configs)
  • Although not as pedantic about it as c/image, c/storage is generally promising to have a stable API. In that sense, supporteddigests.Get is not quite an explanatory name for ”digests to use when creating new things”, and I’d like the long-term-committed name to be more specific (and less confusing, “supported digests” vs. “digests for new things”)

Ultimately, I appreciate that we need to start somewhere, and that building a digest parameter passing infrastructure all over the codebase before we understand the semantics really well would be a lot of tedious work with uncertain payoff.

WDYT about:

  • very explicitly documenting that these functions are a WIP API and should not be called outside of Podman+friends, even if they ship in a stable release
  • (absolutely optional) perhaps, even, naming them TemporaryGet/TemporarySet, or, I don’t know, TemporaryDigestForNewObjects/TemporarySetDigestForNewObjects?

?


The implementation LGTM other than concurrency.

@lsm5 lsm5 marked this pull request as draft October 7, 2025 16:37
@lsm5 lsm5 force-pushed the storage-agile-digest branch from 94df9c1 to 58c51d2 Compare October 7, 2025 16:37
podmanbot pushed a commit to podmanbot/buildah that referenced this pull request Oct 7, 2025
@lsm5 lsm5 force-pushed the storage-agile-digest branch from 58c51d2 to 79f1c23 Compare October 7, 2025 17:08
podmanbot pushed a commit to podmanbot/buildah that referenced this pull request Oct 7, 2025
@lsm5
Copy link
Member Author

lsm5 commented Oct 7, 2025

  • function documentation updated
  • function names updated
  • cautinonary notes added
  • concurrency added
  • additional logic for digest validation, digest detection that can be reused in libraries (RE: your comment on my image/ PR).

PTAL.

@lsm5 lsm5 marked this pull request as ready for review October 7, 2025 17:29
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.

Thanks!

With the explicit non-promise of API stability, I’m much less worried about getting this perfect.

Some of the new parts seem unnecessary and not a clear improvement compared to using go-digest directly. Let me know if you want this merge as is anyway.

[Man the AI is verbose…]

Comment on lines +97 to +102
// calls from multiple goroutines. It is typically used for validation before
// calling TmpSetDigestForNewObjects().
Copy link
Contributor

Choose a reason for hiding this comment

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

I don’t know why anything would (“typically”) call this prior to …TmpSetDigest…, it can just call the setter and handle an error.


// Check against the list of supported algorithms
supportedAlgorithms := GetSupportedDigestAlgorithms()
for _, supported := range supportedAlgorithms {
Copy link
Contributor

Choose a reason for hiding this comment

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

(slices.Contains)

// This is a pure function with no side effects and is thread-safe for concurrent
// calls from multiple goroutines. It is typically used for logging and user-facing
// display purposes.
func GetDigestAlgorithmName(algorithm digest.Algorithm) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to exist, distinctly from algorithm.String()? Also see below about the “canonical” code path.

Having a go-digest format that uses lowercase, and this function that uses uppercase, seems potentially confusing. I mean, if we do need to have two distinct string types, then making the two string sets distinct / incompatible is better than making strings ambiguous, but, still…


(I can, sort of, see a case for a logging/debugging utility that formats values specifically for error texts, maybe highlighting unsupported algorithms with an extra text. But I think "%q", algo.String() is good enough and adding an extra utility is not clearly necessary.)

case "sha512":
return "SHA512"
default:
if algorithm == digest.Canonical {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that digest.Canonical == digest.SHA256, AFAICS this is never reachable; so if the primary purpose of this function is this code path, that doesn’t work.

// This is a pure function with no side effects and is thread-safe for concurrent
// calls from multiple goroutines. It is typically used for validation and algorithm
// detection from hex string lengths.
func GetDigestAlgorithmExpectedLength(algorithm digest.Algorithm) (int, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Algorithm.Size() exists — do we need to hard-code a table, or even have this at all?

{"Unknown", digest.Digest("unknown:invalid").Algorithm(), "unknown"},
// Case-insensitive tests
{"sha256 lowercase", digest.Algorithm("sha256"), "SHA256"},
{"SHA256 uppercase", digest.Algorithm("SHA256"), "SHA256"},
Copy link
Contributor

Choose a reason for hiding this comment

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

I don’t know why this should silently work - any operations on digest.Algorithm("SHA256") is going to fail (or panic if not checked via Available); in that sense at least, such a value of a digest.Algorithm is simply invalid.


// Validate the digest type
switch algorithm {
case digest.SHA256, digest.SHA512:
Copy link
Contributor

Choose a reason for hiding this comment

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

(It might be valuable for this to rely on GetSupportedDigestAlgorithm, or for the two functions to refer to the same data.)

@lsm5
Copy link
Member Author

lsm5 commented Oct 8, 2025

Thanks!

With the explicit non-promise of API stability, I’m much less worried about getting this perfect.

Some of the new parts seem unnecessary and not a clear improvement compared to using go-digest directly. Let me know if you want this merge as is anyway.

I would prefer a merge to get the other parts moving forward. If you'd prefer a TODO: refactor using go-digest before we can even consider calling this stable note in the pkg warning, I could add that. Let me know

@mtrmac
Copy link
Contributor

mtrmac commented Oct 8, 2025

Sure, I think some kind of a TODO marker pointing back here would be nice.

@lsm5 lsm5 force-pushed the storage-agile-digest branch from 79f1c23 to 50b724f Compare October 8, 2025 12:41
@lsm5
Copy link
Member Author

lsm5 commented Oct 8, 2025

Added a FIXME at the top of storage/pkg/supported-digests/algorithm.go. Thanks.

podmanbot pushed a commit to podmanbot/buildah that referenced this pull request Oct 8, 2025
- TmpDigestForNewObjects() and TmpSetDigestForNewObjects() for global state
- IsSupportedDigestAlgorithm() and GetSupportedDigestAlgorithms() for validation
- GetDigestAlgorithmName() with case-insensitive support
- GetDigestAlgorithmExpectedLength() for algorithm-to-length mapping
- DetectDigestAlgorithmFromLength() for length-based algorithm detection

Signed-off-by: Lokesh Mandvekar <lsm5@redhat.com>
@lsm5 lsm5 force-pushed the storage-agile-digest branch from 50b724f to 0d11523 Compare October 8, 2025 12:49
@mtrmac mtrmac enabled auto-merge October 8, 2025 12:49
@lsm5
Copy link
Member Author

lsm5 commented Oct 8, 2025

Added a FIXME at the top of storage/pkg/supported-digests/algorithm.go. Thanks.

updated the FIXME with a note saying it's a blocker for WIP removal.

podmanbot pushed a commit to podmanbot/buildah that referenced this pull request Oct 8, 2025
@mtrmac mtrmac merged commit 647a384 into containers:main Oct 8, 2025
37 checks passed
@lsm5 lsm5 deleted the storage-agile-digest branch October 8, 2025 13:08
@lsm5 lsm5 mentioned this pull request Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage Related to "storage" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants