Skip to content

Fix bugs in SBOM layer comment generation#3594

Merged
tonistiigi merged 5 commits into
moby:masterfrom
jedevc:sbom-supplement-fixes
Feb 10, 2023
Merged

Fix bugs in SBOM layer comment generation#3594
tonistiigi merged 5 commits into
moby:masterfrom
jedevc:sbom-supplement-fixes

Conversation

@jedevc
Copy link
Copy Markdown
Member

@jedevc jedevc commented Feb 7, 2023

BuildKit should generate comments for each file indicating what layer the file can be found in. However, when buildkit-syft-scanner switched to using chroot as a temporary hack (see docker/buildkit-syft-scanner#13), all paths in the SBOM were prefixed with /. This minor format change meant that the exporter's layer finder would not find this file, as they would be discovered without the / prefix.

To fix this, we just need to canonicalize the file paths, both on entry to the function, and for each file discovered.

Additionally, I also noticed a bug in the whiteout detection - we should only be checking the final path component for whiteouts, not the entire path... and also a panic with a scratch layer, and an issue with checking the core SBOM metadata field. Not quite sure why the code is so bug-full, I'm kinda surprised I wrote it in the first place 😢

I've added a test to check the file comment behavior doesn't break again.

Comment thread exporter/containerimage/attestations.go Outdated
//
// find is not concurrency-safe.
func (c *fileLayerFinder) find(ctx context.Context, s session.Group, filename string) (cache.ImmutableRef, *ocispecs.Descriptor, error) {
filename = filepath.Clean("/" + filename)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isn't this supposed to be filepath.Join("/", filename)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thinking about the use of filepath as well. I think these paths should be unix normalized, but that can be follow-up when wcow becomes more realistic.

Signed-off-by: Justin Chadwell <me@jedevc.com>
Signed-off-by: Justin Chadwell <me@jedevc.com>
Signed-off-by: Justin Chadwell <me@jedevc.com>
Signed-off-by: Justin Chadwell <me@jedevc.com>
Signed-off-by: Justin Chadwell <me@jedevc.com>
@jedevc jedevc force-pushed the sbom-supplement-fixes branch from 64a79e1 to 1c55dc2 Compare February 10, 2023 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants