diff --git a/contrib/gitlab.tpl b/contrib/gitlab.tpl index bc5dc3dc9c28..187438776b72 100644 --- a/contrib/gitlab.tpl +++ b/contrib/gitlab.tpl @@ -1,6 +1,29 @@ {{- /* Template based on https://docs.gitlab.com/ee/user/application_security/container_scanning/#reports-json-format */ -}} { - "version": "14.0.6", + "version": "15.0.7", + "scan": { + "analyzer": { + "id": "trivy", + "name": "Trivy", + "vendor": { + "name": "Aqua Security" + }, + "version": "{{ appVersion }}" + }, + "end_time": "{{ now | date "2006-01-02T15:04:05" }}", + "scanner": { + "id": "trivy", + "name": "Trivy", + "url": "https://github.com/aquasecurity/trivy/", + "vendor": { + "name": "Aqua Security" + }, + "version": "{{ appVersion }}" + }, + "start_time": "{{ now | date "2006-01-02T15:04:05" }}", + "status": "success", + "type": "container_scanning" + }, "vulnerabilities": [ {{- $t_first := true }} {{- range . }} @@ -14,11 +37,8 @@ {{- end }} { "id": "{{ .VulnerabilityID }}", - "category": "container_scanning", - "message": {{ .Title | printf "%q" }}, + "name": {{ .Title | printf "%q" }}, "description": {{ .Description | printf "%q" }}, - {{- /* cve is a deprecated key, use id instead */}} - "cve": "{{ .VulnerabilityID }}", "severity": {{ if eq .Severity "UNKNOWN" -}} "Unknown" {{- else if eq .Severity "LOW" -}} @@ -37,10 +57,6 @@ {{- else -}} "No solution provided" {{- end }}, - "scanner": { - "id": "trivy", - "name": "trivy" - }, "location": { "dependency": { "package": { diff --git a/integration/testdata/alpine-310.gitlab.golden b/integration/testdata/alpine-310.gitlab.golden index e006c9a34db3..ad769b31959e 100644 --- a/integration/testdata/alpine-310.gitlab.golden +++ b/integration/testdata/alpine-310.gitlab.golden @@ -1,18 +1,35 @@ { - "version": "14.0.6", + "version": "15.0.7", + "scan": { + "analyzer": { + "id": "trivy", + "name": "Trivy", + "vendor": { + "name": "Aqua Security" + }, + "version": "dev" + }, + "end_time": "2021-08-25T12:20:30", + "scanner": { + "id": "trivy", + "name": "Trivy", + "url": "https://github.com/aquasecurity/trivy/", + "vendor": { + "name": "Aqua Security" + }, + "version": "dev" + }, + "start_time": "2021-08-25T12:20:30", + "status": "success", + "type": "container_scanning" + }, "vulnerabilities": [ { "id": "CVE-2019-1549", - "category": "container_scanning", - "message": "openssl: information disclosure in fork()", + "name": "openssl: information disclosure in fork()", "description": "OpenSSL 1.1.1 introduced a rewritten random number generator (RNG). This was intended to include protection in the event of a fork() system call in order to ensure that the parent and child processes did not share the same RNG state. However this protection was not being used in the default case. A partial mitigation for this issue is that the output from a high precision timer is mixed into the RNG state so the likelihood of a parent and child process sharing state is significantly reduced. If an application already calls OPENSSL_init_crypto() explicitly using OPENSSL_INIT_ATFORK then this problem does not occur at all. Fixed in OpenSSL 1.1.1d (Affected 1.1.1-1.1.1c).", - "cve": "CVE-2019-1549", "severity": "Medium", "solution": "Upgrade libcrypto1.1 to 1.1.1d-r0", - "scanner": { - "id": "trivy", - "name": "trivy" - }, "location": { "dependency": { "package": { @@ -76,16 +93,10 @@ }, { "id": "CVE-2019-1551", - "category": "container_scanning", - "message": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64", + "name": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64", "description": "There is an overflow bug in the x64_64 Montgomery squaring procedure used in exponentiation with 512-bit moduli. No EC algorithms are affected. Analysis suggests that attacks against 2-prime RSA1024, 3-prime RSA1536, and DSA1024 as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH512 are considered just feasible. However, for an attack the target would have to re-use the DH512 private key, which is not recommended anyway. Also applications directly using the low level API BN_mod_exp may be affected if they use BN_FLG_CONSTTIME. Fixed in OpenSSL 1.1.1e (Affected 1.1.1-1.1.1d). Fixed in OpenSSL 1.0.2u (Affected 1.0.2-1.0.2t).", - "cve": "CVE-2019-1551", "severity": "Medium", "solution": "Upgrade libcrypto1.1 to 1.1.1d-r2", - "scanner": { - "id": "trivy", - "name": "trivy" - }, "location": { "dependency": { "package": { @@ -169,16 +180,10 @@ }, { "id": "CVE-2019-1549", - "category": "container_scanning", - "message": "openssl: information disclosure in fork()", + "name": "openssl: information disclosure in fork()", "description": "OpenSSL 1.1.1 introduced a rewritten random number generator (RNG). This was intended to include protection in the event of a fork() system call in order to ensure that the parent and child processes did not share the same RNG state. However this protection was not being used in the default case. A partial mitigation for this issue is that the output from a high precision timer is mixed into the RNG state so the likelihood of a parent and child process sharing state is significantly reduced. If an application already calls OPENSSL_init_crypto() explicitly using OPENSSL_INIT_ATFORK then this problem does not occur at all. Fixed in OpenSSL 1.1.1d (Affected 1.1.1-1.1.1c).", - "cve": "CVE-2019-1549", "severity": "Medium", "solution": "Upgrade libssl1.1 to 1.1.1d-r0", - "scanner": { - "id": "trivy", - "name": "trivy" - }, "location": { "dependency": { "package": { @@ -242,16 +247,10 @@ }, { "id": "CVE-2019-1551", - "category": "container_scanning", - "message": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64", + "name": "openssl: Integer overflow in RSAZ modular exponentiation on x86_64", "description": "There is an overflow bug in the x64_64 Montgomery squaring procedure used in exponentiation with 512-bit moduli. No EC algorithms are affected. Analysis suggests that attacks against 2-prime RSA1024, 3-prime RSA1536, and DSA1024 as a result of this defect would be very difficult to perform and are not believed likely. Attacks against DH512 are considered just feasible. However, for an attack the target would have to re-use the DH512 private key, which is not recommended anyway. Also applications directly using the low level API BN_mod_exp may be affected if they use BN_FLG_CONSTTIME. Fixed in OpenSSL 1.1.1e (Affected 1.1.1-1.1.1d). Fixed in OpenSSL 1.0.2u (Affected 1.0.2-1.0.2t).", - "cve": "CVE-2019-1551", "severity": "Medium", "solution": "Upgrade libssl1.1 to 1.1.1d-r2", - "scanner": { - "id": "trivy", - "name": "trivy" - }, "location": { "dependency": { "package": { diff --git a/pkg/report/template.go b/pkg/report/template.go index 4904b8472ecb..d320a420f722 100644 --- a/pkg/report/template.go +++ b/pkg/report/template.go @@ -27,7 +27,7 @@ type TemplateWriter struct { } // NewTemplateWriter is the factory method to return TemplateWriter object -func NewTemplateWriter(output io.Writer, outputTemplate string) (*TemplateWriter, error) { +func NewTemplateWriter(output io.Writer, outputTemplate, appVersion string) (*TemplateWriter, error) { if strings.HasPrefix(outputTemplate, "@") { buf, err := os.ReadFile(strings.TrimPrefix(outputTemplate, "@")) if err != nil { @@ -54,6 +54,9 @@ func NewTemplateWriter(output io.Writer, outputTemplate string) (*TemplateWriter templateFuncMap["sourceID"] = func(input string) dbTypes.SourceID { return dbTypes.SourceID(input) } + templateFuncMap["appVersion"] = func() string { + return appVersion + } // Overwrite functions for k, v := range CustomTemplateFuncMap { diff --git a/pkg/report/template_test.go b/pkg/report/template_test.go index ded1fa8844c9..30db3595680e 100644 --- a/pkg/report/template_test.go +++ b/pkg/report/template_test.go @@ -178,7 +178,7 @@ func TestReportWriter_Template(t *testing.T) { }, } - w, err := report.NewTemplateWriter(&got, tc.template) + w, err := report.NewTemplateWriter(&got, tc.template, "dev") require.NoError(t, err) err = w.Write(inputReport) assert.NoError(t, err) diff --git a/pkg/report/writer.go b/pkg/report/writer.go index e53cad0e0463..c467f921d4d2 100644 --- a/pkg/report/writer.go +++ b/pkg/report/writer.go @@ -78,7 +78,7 @@ func Write(ctx context.Context, report types.Report, option flag.Options) (err e break } var err error - if writer, err = NewTemplateWriter(output, option.Template); err != nil { + if writer, err = NewTemplateWriter(output, option.Template, option.AppVersion); err != nil { return xerrors.Errorf("failed to initialize template writer: %w", err) } case types.FormatSarif: