fix: match image digests with any algorithm, not only sha256 (#6167)

* fix: match image digests with any algorithm, not only sha256

IsImageMatched hard-coded '@sha256:' in its regex, while Split accepts any
digest algorithm. An image pinned with a non-sha256 digest (e.g.
nginx@sha512:...) was not matched, so the ImageTagTransformer silently left
it unchanged and the user's images: override was ignored. Generalize the
digest algorithm in the regex to match what Split accepts.

Signed-off-by: Seonghyun Hong <s3onghyun.hong@gmail.com>

* Address review: match OCI digest grammar and test spec example algorithms

Broaden the digest-algorithm match to the OCI grammar (algorithm components
separated by +._-), so multihash+base58 and other registered/unregistered
algorithms match, not just [a-zA-Z][a-zA-Z0-9]*. Add test cases using the
descriptor example algorithms: a full-length sha512 digest and
multihash+base58.

Signed-off-by: Seonghyun Hong <s3onghyun.hong@gmail.com>

---------

Signed-off-by: Seonghyun Hong <s3onghyun.hong@gmail.com>
This commit is contained in:
SEONGHYUN HONG
2026-06-20 18:55:40 +09:00
committed by GitHub
parent 313aacedd3
commit 9f89960cf2
2 changed files with 36 additions and 1 deletions

View File

@@ -14,7 +14,14 @@ func IsImageMatched(s, t string) bool {
// Tag values are limited to [a-zA-Z0-9_.{}-].
// Some tools like Bazel rules_k8s allow tag patterns with {} characters.
// More info: https://github.com/bazelbuild/rules_k8s/pull/423
pattern, _ := regexp.Compile("^" + t + "(:[a-zA-Z0-9_.{}-]*)?(@sha256:[a-zA-Z0-9_.{}-]*)?$")
//
// The digest algorithm is matched following the OCI grammar
// (algorithm-component separated by one of [+._-], e.g. sha256, sha512,
// multihash+base58) rather than hard-coded to sha256, so that references
// using any OCI-valid digest algorithm match consistently with Split,
// which accepts any algorithm.
// See https://github.com/opencontainers/image-spec/blob/main/descriptor.md#digests
pattern, _ := regexp.Compile("^" + t + "(:[a-zA-Z0-9_.{}-]*)?(@[a-zA-Z0-9]+([.+_-][a-zA-Z0-9]+)*:[a-zA-Z0-9_.{}-]*)?$")
return pattern.MatchString(s)
}