-
Notifications
You must be signed in to change notification settings - Fork 34
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
Conversation
626e78f
to
d15dd7a
Compare
Codecov ReportAttention: Patch coverage is
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. |
bef9e9b
to
f3c12e3
Compare
d36431c
to
2707c51
Compare
0d52e51
to
dc97888
Compare
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.
there are some comments inline.
c1a5a6c
to
4d0ae3f
Compare
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]>
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.
Thanks.
This looks good to me.
@@ -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) |
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.
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) |
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.
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) |
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.
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) |
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.
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 |
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.
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) |
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.
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) |
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.
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 |
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.
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"}, |
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.
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 |
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.
ooof -- why do we have to kill so hard?
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.