Skip to content

Commit 9894dc1

Browse files
committed
report: improve functionality with locally saved images
Previously the locally saved image flow was at best confusing and at worst just wrong for some cases. This change simplified the handling of local images and reduces resources that were previously allocated for no good reason. Tests were also added to verify both docker and podman saved images work as expected. The application now expects all saved images to follow the OCI spec https://github.com/opencontainers/image-spec/blob/v1.1.1/image-layout.md Signed-off-by: crozzy <[email protected]>
1 parent 526ec1b commit 9894dc1

File tree

9 files changed

+484
-307
lines changed

9 files changed

+484
-307
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ Following inputs can be used as `step.with` keys
253253
| Name | Type | Required | default | Description |
254254
| ------------------- | ------ | -------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
255255
| `image-ref` | String | yes* | - | The reference to an image in a container registry, currently this needs to be public (e.g., `quay.io/projectquay/clair:nightly`) |
256-
| `image-path` | String | yes* | - | Where on the filesystem the image was saved, i.e. the --output-flag from the `docker save` command the action require either this or `image-ref` to be defined (e.g., `/tmp/my-image.tar`) |
256+
| `image-path` | String | yes* | - | Where on the filesystem the image was saved, i.e. the --output-flag from the `docker save` command the action require either this or `image-ref` to be defined (e.g., `/tmp/my-image.tar`). The image must follow the OCI Image Spec https://github.com/opencontainers/image-spec/blob/v1.1.1/image-layout.md (this means using the `--format oci-archive` flag for `podman save`).|
257257
| `format` | String | no | `clair` | The output format of the report, currently `clair`, `sarif` and `quay` are supported. |
258258
| `output` | String | yes | - | The file path where the report gets saved (e.g., /tmp/my-image-report.sarif) |
259259
| `return-code` | String | no | `0` | A code to return from the process if Clair found vulnerabilities. (e.g., `1`) |

cmd/clair-action/report.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111
"time"
1212

13+
"github.com/quay/claircore"
1314
"github.com/quay/claircore/enricher/cvss"
1415
"github.com/quay/claircore/indexer"
1516
"github.com/quay/claircore/libindex"
@@ -127,8 +128,8 @@ func report(c *cli.Context) error {
127128
)
128129

129130
var (
130-
img image.Image
131-
fa indexer.FetchArena
131+
mf *claircore.Manifest
132+
fa indexer.FetchArena
132133
)
133134
switch {
134135
case imgRef != "":
@@ -138,17 +139,25 @@ func report(c *cli.Context) error {
138139
if err != nil {
139140
return fmt.Errorf("error setting DOCKER_CONFIG env var")
140141
}
141-
img = image.NewDockerRemoteImage(ctx, imgRef)
142+
mf, err = image.ManifestFromRemote(ctx, imgRef)
143+
if err != nil {
144+
return fmt.Errorf("error getting image information: %v", err)
145+
}
142146
case imgPath != "":
143147
fa = &LocalFetchArena{}
144148
var err error
145-
img, err = image.NewDockerLocalImage(ctx, imgPath, os.TempDir())
149+
mf, err = image.ManifestFromLocal(ctx, imgPath, os.TempDir())
146150
if err != nil {
147151
return fmt.Errorf("error getting image information: %v", err)
148152
}
149153
default:
150154
return fmt.Errorf("no $IMAGE_PATH / --image-path or $IMAGE_REF / --image-ref set")
151155
}
156+
defer func() {
157+
for _, l := range mf.Layers {
158+
l.Close()
159+
}
160+
}()
152161

153162
switch {
154163
case dbPath != "":
@@ -186,11 +195,6 @@ func report(c *cli.Context) error {
186195
return fmt.Errorf("error creating Libvuln: %v", err)
187196
}
188197

189-
mf, err := img.GetManifest(ctx)
190-
if err != nil {
191-
return fmt.Errorf("error creating manifest: %v", err)
192-
}
193-
194198
indexerOpts := &libindex.Options{
195199
Store: datastore.NewLocalIndexerStore(),
196200
Locker: NewLocalLockSource(),

image/docker.go

Lines changed: 0 additions & 139 deletions
This file was deleted.

image/docker_test.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

image/inspect.go

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)