Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in SBOM layer comment generation #3594

Merged
merged 5 commits into from
Feb 10, 2023

Conversation

jedevc
Copy link
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.

@@ -172,6 +176,8 @@ func newFileLayerFinder(target cache.ImmutableRef, remote *solver.Remote) (fileL
//
// 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
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
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>
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.

None yet

3 participants