fix(sbom): regenerate the SBOM when the GOST configuration changes - #271
Merged
Conversation
The SBOM artifact checksum is compared against the annotation on the already attached artifact to decide whether a cached SBOM can be reused for the same parent stage digest. GOST settings reached that checksum only indirectly, through the base and imported documents that prepareGostComponents happens to upsert, and not at all when an image has neither - a scratch image, for example. Since the SBOM section feeds no stage digest, changing build.sbom.gost left both halves of the cache key intact and the user kept receiving an SBOM without the requested GOST properties, even though the documented behavior is that the artifact is regenerated with the new requirements. Give the effective GOST configuration its own checksum parts so it is accounted for through exactly one explicit channel, independent of whether any base or imported document exists. While the layout changes, drop the separator-joined encoding: parts were concatenated with "-" and the platform part was appended only when non-empty, so a value containing the separator absorbed a slot boundary and distinct inputs collapsed onto the same checksum. Every part is now always present and keyed, hashed as individual arguments. Mutation testing on the collision case drove this: the first version of the test passed under the old encoding too. The os-pm packages directive and the scratch base stay out of the checksum deliberately: the directive compiles into the generated install command that feeds the Packages stage digest, and the stage appears and disappears along with it, so any change already moves the parent digest. The exclusions and the reasoning now live next to the computation. Existing projects regenerate each SBOM once on the first build after upgrading, then resume reusing the cache. Signed-off-by: Radmir Khurum <radmir.khurum@flant.com>
Collaborator
Author
Verification
Review focus
Follow-up
|
Signed-off-by: Radmir Khurum <radmir.khurum@flant.com>
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
Changing
build.sbom.gostdid not regenerate the attached SBOM: the build reused the artifact from the previous run, so the document kept the old GOST properties. Reproduces from a clean checkout on any image whose SBOM has no base or imported document:Build with
--repo, flipattackSurfacetono, build again —werf sbom get appstill reportsyes.What
build.sbom.gost, the next build regenerates the SBOM artifact instead of reusing the attached one, including for images with no base or imported SBOM document, where the setting previously reached the checksum through nothing at all.-used to absorb the platform slot boundary.packagesdirective (os-pm) and a scratch base stay out of the checksum — both already move the parent stage digest, which is the other half of the SBOM cache key.MergeOpts.Checksum()still covers only base and imported document content.Why
The SBOM section feeds no stage digest, and the GOST configuration reached the artifact checksum only as a side effect:
prepareGostComponentsupserts GOST properties into base and imported documents before the checksum is computed. An image with neither left the setting invisible to both halves of the cache key, whilegost.Upsertstill applied it to the result document at generation time — a silently stale compliance artifact.wiki/pages/sbom-cache-invalidation.mdalready documented the opposite behavior.Putting the configuration inside
MergeOpts.Checksum()was rejected: GOST is post-processing configuration rather than a merge input, and that channel would count the same setting twice for images that do have base or imported documents.