-
Notifications
You must be signed in to change notification settings - Fork 54
feat: add a hasher for spdx #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+58
−29
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright (c) 2026 Sidero Labs, Inc. | ||
| // | ||
| // Use of this software is governed by the Business Source License | ||
| // included in the LICENSE file. | ||
|
|
||
| //go:build enterprise | ||
|
|
||
| package builder | ||
|
|
||
| import ( | ||
| "crypto/sha256" | ||
| "encoding/hex" | ||
| ) | ||
|
|
||
| // Hash returns a content hash describing the inputs and extraction logic that | ||
| // produce an SPDX bundle. It is used directly as the OCI cache tag, so that | ||
| // fixes to the SPDX extraction/merge logic can invalidate previously cached | ||
| // bundles even though the schematic, version and architecture are unchanged. | ||
| // | ||
| // This mirrors internal/profile.Hash (whose output is likewise used as the | ||
| // asset cache tag): the inputs are checksummed and then errata strings are | ||
| // mixed in, bumping the hash (and therefore the cache key) whenever a bug in a | ||
| // previously cached SPDX bundle needs to be invalidated. | ||
| // | ||
| // Operators are expected to use distinct cache repositories for OSS vs | ||
| // Enterprise deployments since the bundle content differs by build flavor. | ||
| func Hash(schematicID, version, arch string) string { | ||
| hasher := sha256.New() | ||
|
|
||
| // NUL-separate inputs so distinct fields can't collide via concatenation. | ||
| hasher.Write([]byte(schematicID)) | ||
| hasher.Write([]byte{0}) | ||
| hasher.Write([]byte(version)) | ||
| hasher.Write([]byte{0}) | ||
| hasher.Write([]byte(arch)) | ||
|
|
||
| // Errata: append a marker string whenever the SPDX bundle content or | ||
| // extraction logic changes in a way that must invalidate existing cached | ||
| // bundles. Add new entries below; never remove or reorder existing ones. | ||
| // Guard entries with conditions (version/arch) when the fix is scoped. | ||
|
|
||
| return hex.EncodeToString(hasher.Sum(nil)) | ||
| } | ||
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like us to move way forward on this one, and do proper caching for SBOMs.
If we just depend on schematic IDs, two schematics with e.g. just a different kernel args will not produce same SBOM ID.
Let's reconsider this, probably @shanduur can help here.
It feels like we only need list of extensions from the schematic (plus overlay?), but let's do a proper tested hashing here to avoid recomputing the SPDX.
Same applies to scan results - if a scan is requested, if the SPDX hash is same, don't re-run the scan unless vulndb/VEX changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh that's bad already, we should rely on extensions only, overlays don't ship sboms, unless we want them to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, schematicID is too fragile, we should cache on Version+Arch+Extensions.