Skip to content

Commit 588e059

Browse files
committed
add uti and digest
1 parent 856221c commit 588e059

File tree

6 files changed

+71
-24
lines changed

6 files changed

+71
-24
lines changed

.github/workflows/on-tag.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: tag-cli
1+
name: tag-release
22
on:
33
push:
44
tags:

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.3.1
1+
v0.3.2

README.md

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,61 @@
77

88
# vulctl
99

10-
Vulnerability scanners export tool.
11-
10+
Vulnerability scanners result processing tool. Generalizes vulnerability reports from common OSS scanners into a generic format which then can be used to compare data across scanners or persist in database.
1211

1312
```shell
14-
vulctl import --source $image \
15-
--file report.json \
16-
--format snyk
17-
--output results.json
13+
export image="docker.io/redis@sha256:7b83a0167532d4320a87246a815a134e19e31504d85e8e55f0bb5bb9edf70448"
1814
```
1915

2016
The currently supported scanners/formats include:
2117

22-
* [grype](https://github.com/anchore/grype)
23-
24-
`grype --add-cpes-if-none -s AllLayers -o json --file report.json $image`
25-
26-
* [snyk](https://github.com/snyk/cli)
18+
* [grype](https://github.com/anchore/grype) `grype --add-cpes-if-none -s AllLayers -o json --file report.json $image`
19+
* [snyk](https://github.com/snyk/cli) `snyk container test --app-vulns --json-file-output=report.json $image`
20+
* [trivy](https://github.com/aquasecurity/trivy) `trivy image --format json --output report.json $image`
2721

28-
`snyk container test --app-vulns --json-file-output=report.json $image`
22+
Then, to process the vulnerability report output from `grype`:
2923

30-
* [trivy](https://github.com/aquasecurity/trivy)
24+
```shell
25+
vulctl --source $image --file report.json --format grype
26+
```
3127

32-
`trivy image --format json --output report.json $image`
28+
The resulting file or stdout output will look something like this:
29+
30+
```json
31+
{
32+
"uri": "https://docker.io/redis",
33+
"digest": "sha256:7b83a0167532d4320a87246a815a134e19e31504d85e8e55f0bb5bb9edf70448",
34+
"processed_at": "2023-04-01T21:53:11.616Z",
35+
"record_count": 82,
36+
"vulnerabilities": [
37+
{
38+
"id": "GHSA-vpvm-3wq2-2wvm",
39+
"package": "github.com/opencontainers/runc",
40+
"version": "v1.1.0",
41+
"severity": "high",
42+
"score": 7,
43+
"fixed": true
44+
},
45+
{
46+
"id": "CVE-2023-0466",
47+
"package": "libssl1.1",
48+
"version": "1.1.1n-0+deb11u4",
49+
"severity": "unknown",
50+
"score": 0,
51+
"fixed": false
52+
},
53+
{
54+
"id": "CVE-2022-1304",
55+
"package": "e2fsprogs",
56+
"version": "1.46.2-2",
57+
"severity": "high",
58+
"score": 6.8,
59+
"fixed": false
60+
},
61+
...
62+
]
63+
}
64+
```
3365

3466

3567
## Installation

internal/processor/input.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package processor
22

33
import (
44
"net/url"
5+
"strings"
56

67
"github.com/pkg/errors"
78
)
@@ -36,6 +37,9 @@ type Options struct {
3637

3738
// Quiet suppresses output
3839
Quiet bool
40+
41+
uri string
42+
digest string
3943
}
4044

4145
func (o *Options) validate() error {
@@ -52,6 +56,19 @@ func (o *Options) validate() error {
5256
}
5357
o.Source = u.String()
5458

59+
if strings.Contains(o.Source, "@") {
60+
parts := strings.Split(o.Source, "@")
61+
o.uri = parts[0]
62+
o.digest = parts[1]
63+
} else {
64+
if strings.Contains(o.Source, ":") {
65+
parts := strings.Split(o.Source, ":")
66+
o.uri = parts[0]
67+
} else {
68+
o.uri = o.Source
69+
}
70+
}
71+
5572
if o.File == "" {
5673
return ErrMissingPath
5774
}

internal/processor/process.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ func Process(opt *Options) error {
3636
log.Info().Msgf("found %d vulnerabilities", len(uniques))
3737

3838
scan := &data.Scan{
39-
URI: opt.Source,
40-
Digest: "",
41-
PerformedAt: time.Now().UTC(),
42-
Count: len(uniques),
39+
URI: opt.uri,
40+
Digest: opt.digest,
41+
ProcessedAt: time.Now().UTC(),
42+
RecordCount: len(uniques),
4343
Vulnerabilities: uniques,
4444
}
4545

@@ -58,8 +58,6 @@ func output(in *Options, result *data.Scan) error {
5858
return errors.New("vulnerabilities required")
5959
}
6060

61-
log.Debug().Msgf("found: %d", result.Count)
62-
6361
// output to stdout
6462
if in.Output == nil || *in.Output == "" {
6563
je := json.NewEncoder(os.Stdout)

pkg/data/scan.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "time"
66
type Scan struct {
77
URI string `json:"uri"`
88
Digest string `json:"digest"`
9-
PerformedAt time.Time `json:"performed_at"`
9+
ProcessedAt time.Time `json:"processed_at"`
10+
RecordCount int `json:"record_count"`
1011
Vulnerabilities []*Vulnerability `json:"vulnerabilities"`
11-
Count int `json:"count"`
1212
}

0 commit comments

Comments
 (0)