fix(sbom): key artifact fallback index tag by image name - #219
Open
reyreavman wants to merge 1 commit into
Open
Conversation
Two werf images with identical content share one digest, and the fallback index was keyed by that digest alone. Both images then attached their SBOM to the same mutable index, so concurrent attaches read the same state and overwrote each other's entry: `werf sbom merge` failed with "no artifact of type ... found for digest". Serializing the read-modify-write in-process was not enough, because the index is re-read from the registry, which gives no read-after-write guarantee. Key the tag by the parent digest and the image name instead, so that each image owns its index and there is no shared object left to lose updates on. An empty image name keeps the digest-only form, which is also the form written by previous versions, and cleanup keeps recognizing both. Readers that are not scoped to an image, `werf sbom get --digest` and attestation listing, now merge the per-image indexes of a digest into one view, so their behaviour is unchanged. Signed-off-by: Radmir Khurum <radmir.khurum@flant.com>
reyreavman
marked this pull request as ready for review
August 4, 2026 13:23
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.
Summary
Two werf images with identical content share one digest, and the SBOM fallback
index was keyed by that digest alone, so both images wrote into the same mutable
index and lost each other's entries. The tag is now keyed by digest and image
name, which removes the shared object instead of guarding it.
Key changes
pkg/oci/artifact/fallback.goFallbackTag(parentDigest, imageName)producessha256-<hex>-<slug(imageName)>;the image name is encoded with
slug.LimitedSlugwithin a 56-char budget(128 tag limit − prefix − digest hex − separator). An empty image name keeps
the digest-only form written by previous versions.
FallbackTagDigestPrefixandParseFallbackTagDigest; the latter acceptsboth the per-image and the legacy digest-only form.
imageNamethreaded throughAttach,waitForConsistency,tagMutexKey,pullFallbackIndexandpushFallbackIndex.PullFallbackIndexnow merges the per-image indexes of a digest into oneread-only view, so digest-scoped readers keep their previous semantics.
pkg/storage/repo_stages_storage.go:GetOrphanedArtifactNamesparses thedigest via
ParseFallbackTagDigestinstead of trimming the whole suffix.pkg/sbom/image/image.go:FallbackTagwrapper takes the image name.ParseFallbackTagDigestcases indigest_test.go, updatedtagMutexKeycases, andregressions_test.gonowasserts one annotated entry per per-image tag.
Why
werf sbom mergefailed withno artifact of type "application/vnd.dsse.envelope.v1+json" found for digest ...whenever two images resolved to the same digest: their SBOMattaches raced on one index and one entry was dropped.
Serializing the read-modify-write in-process (#210) is not sufficient, because the
index is re-read from the registry between lock acquisition and push, and a registry
gives no read-after-write guarantee. The e2e job of #217 already contains that fix
and still reproduced the failure. Keying the tag per image leaves no shared object
to lose updates on, on any number of processes or hosts.
Review focus / risks
found by name anymore and are regenerated on the next build (cache miss, not an
error). Old indexes stay until cleanup collects them with the parent digest.
Mixed werf versions will not see each other's SBOMs until a rebuild.
GetAttachedContentAny(werf sbom get --digest, attestation get) now listsrepository tags instead of fetching a single tag.
writes to the same tag.
pkg/oci/artifact/store.go:123passess.opts...instead of
s.remoteOptions(ctx), unlike the neighbouringGetAttached, so thatpath runs without registry auth. Worth a separate issue.