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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support importing sboms along with images #567

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

rchincha
Copy link
Contributor

When we import an image via the from: directive, also pull in the sbom if there is one. Else we need to rebuild the sbom and there may not be enough state/information to do so.

What type of PR is this?

Which issue does this PR fix:

What does this PR do / Why do we need it:

If an issue # is not available please add repro steps and logs showing the issue:

Testing done on this change:

Automation added to e2e:

Will this break upgrades or downgrades?

Does this PR introduce any user-facing change?:


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@rchincha rchincha force-pushed the from-bom branch 2 times, most recently from 626e78f to d15dd7a Compare November 30, 2023 20:01
Copy link

codecov bot commented Nov 30, 2023

Codecov Report

Attention: Patch coverage is 54.77528% with 161 lines in your changes are missing coverage. Please review.

Project coverage is 57.44%. Comparing base (b585bfb) to head (10d9371).

Files Patch % Lines
pkg/stacker/referrer.go 54.65% 116 Missing and 40 partials ⚠️
pkg/stacker/base.go 62.50% 2 Missing and 1 partial ⚠️
pkg/stacker/publisher.go 50.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #567      +/-   ##
==========================================
+ Coverage   57.38%   57.44%   +0.06%     
==========================================
  Files          64       65       +1     
  Lines        7566     7706     +140     
==========================================
+ Hits         4342     4427      +85     
- Misses       2481     2522      +41     
- Partials      743      757      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rchincha rchincha force-pushed the from-bom branch 7 times, most recently from bef9e9b to f3c12e3 Compare December 7, 2023 06:23
@rchincha rchincha added this to the v1.0.0 milestone Dec 8, 2023
@rchincha rchincha force-pushed the from-bom branch 12 times, most recently from d36431c to 2707c51 Compare December 15, 2023 07:03
@rchincha rchincha force-pushed the from-bom branch 6 times, most recently from 0d52e51 to dc97888 Compare December 19, 2023 22:56
@rchincha rchincha marked this pull request as ready for review December 20, 2023 01:17
Copy link
Contributor

@smoser smoser left a comment

Choose a reason for hiding this comment

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

there are some comments inline.

pkg/stacker/referrer.go Outdated Show resolved Hide resolved
pkg/stacker/referrer.go Show resolved Hide resolved
pkg/stacker/referrer.go Outdated Show resolved Hide resolved
pkg/stacker/referrer.go Show resolved Hide resolved
pkg/stacker/publisher.go Show resolved Hide resolved
pkg/stacker/base.go Outdated Show resolved Hide resolved
test/bom.bats Show resolved Hide resolved
pkg/stacker/referrer_test.go Show resolved Hide resolved
@rchincha rchincha force-pushed the from-bom branch 5 times, most recently from c1a5a6c to 4d0ae3f Compare March 14, 2024 22:51
When we import an image via the from: directive, also pull in the sbom
if there is one from the source registry. Else we need to rebuild the
sbom and there may not be enough state/information to do so.

Signed-off-by: Ramkumar Chinchani <[email protected]>
Copy link
Contributor

@hallyn hallyn left a comment

Choose a reason for hiding this comment

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

Thanks.

This looks good to me.

@rchincha rchincha merged commit f3a8d3b into project-stacker:main Mar 18, 2024
10 of 11 checks passed
@@ -46,7 +46,15 @@ func GetBase(o BaseLayerOpts) error {
case types.OCILayer:
fallthrough
case types.DockerLayer:
return importContainersImage(o.Layer.From, o.Config, o.Progress)
err := importContainersImage(o.Layer.From, o.Config, o.Progress)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment w.r.t when we take this path (similar to the comment for this PR)?

return importContainersImage(o.Layer.From, o.Config, o.Progress)
err := importContainersImage(o.Layer.From, o.Config, o.Progress)
if o.Layer.Bom != nil && o.Layer.Bom.Generate && (o.Layer.From.Type == types.DockerLayer) {
bomPath := path.Join(o.Config.StackerDir, "artifacts", o.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a common function off of o.Config which would return the "artifacts" dir?

err := importContainersImage(o.Layer.From, o.Config, o.Progress)
if o.Layer.Bom != nil && o.Layer.Bom.Generate && (o.Layer.From.Type == types.DockerLayer) {
bomPath := path.Join(o.Config.StackerDir, "artifacts", o.Name)
err = getArtifact(bomPath, "application/spdx+json", o.Layer.From.Url, "", "", o.Layer.From.Insecure)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have a const for the mimetype ?

bomPath := path.Join(o.Config.StackerDir, "artifacts", o.Name)
err = getArtifact(bomPath, "application/spdx+json", o.Layer.From.Url, "", "", o.Layer.From.Insecure)
if err != nil {
log.Errorf("sbom for image %s not found", o.Layer.From.Url)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Errorf("sbom for image %s not found", o.Layer.From.Url)
log.Errorf("sbom artifact for image %s not found", o.Layer.From.Url)

@@ -40,6 +40,8 @@ type BuildArgs struct {
SetupOnly bool
Progress bool
AnnotationsNamespace string
Username string
Password string
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need any sort of special handling so that the value is not leaked in logs?


// skipping additional OCI "artifact" checks
if err := downloadBlob(registry, repo, path, username, password, fh, manifest.Layers[0].Size, &manifest.Layers[0].Digest, skipTLS); err != nil {
log.Errorf("unable to download file:%s, err:%s", path, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Errorf("unable to download file:%s, err:%s", path, err)
log.Errorf("unable to download file:%q, err:%s", path, err)

return err
}

log.Infof("Copying artifact %s:%s done", path, mtype)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Infof("Copying artifact %s:%s done", path, mtype)
log.Infof("Copying artifact %q:%s done", path, mtype)

}

func downloadBlob(registry, repo, path, username, password string, writer io.Writer, size int64, dgst *godigest.Digest, skipTLS bool) error {
// upload with POST, PUT sequence
Copy link
Contributor

Choose a reason for hiding this comment

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

comment is stale

cases := map[string]*distspecUrl{
"docker://alpine:latest": &distspecUrl{Scheme: "docker", Host: "docker.io", Tag: "latest", Path: "/library/alpine"},
"docker://localhost:8080/alpine:latest": &distspecUrl{Scheme: "docker", Host: "localhost:8080", Tag: "latest", Path: "/alpine"},
"docker://localhost:8080/a/b/c/alpine:latest": &distspecUrl{Scheme: "docker", Host: "localhost:8080", Tag: "latest", Path: "/a/b/c/alpine"},
Copy link
Contributor

Choose a reason for hiding this comment

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

what about:

"docker://localhost:8080/a/b/c/alpine:latest:withcolon": &distspecUrl{Scheme: "docker", Host: "localhost:8080", Tag: "latest:withcolon", Path: "/a/b/c/alpine"},

killall zot
killall -KILL zot || true
Copy link
Contributor

Choose a reason for hiding this comment

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

ooof -- why do we have to kill so hard?

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.

4 participants