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

Add proto definition for vuln predicate type #345

Merged
merged 9 commits into from
Nov 5, 2024
Merged
3 changes: 3 additions & 0 deletions protos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ predicates have protobuf definitions:
artifact.
- [SCAI]: Evidence-based assertions about software artifact and supply
chain attributes.
- [VULNS]: Describes how to store the results of scanners when detecting vulnerabilities in a software artifact.
chain attributes.
- [Test Result]: Expresses the result of a test run in the software supply
chain.

Expand Down Expand Up @@ -50,6 +52,7 @@ testing the supported language bindings.
[SCAI]: in_toto_attestation/predicates/scai/
[SLSA Provenance]: in_toto_attestation/predicates/provenance/
[SLSA Verification Summary]: in_toto_attestation/predicates/vsa/
[VULNS]: in_toto_attestation/predicates/vulns/
[in-toto Link]: in_toto_attestation/predicates/link/
[Test Result]: in_toto_attestation/predicates/test_result/
[documentation]: ../docs/protos.md
Expand Down
49 changes: 49 additions & 0 deletions protos/in_toto_attestation/predicates/vulns/v0.1/vulns.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
syntax = "proto3";

package in_toto_attestation.predicates.vulns.v01;

import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/in-toto/attestation/go/predicates/vulns/v01";
option java_package = "io.github.intoto.attestation.predicates.vulns.v01";

// Validation of all fields is left to the users of this proto.
message Vulns {
Scanner scanner = 1;
ScanMetadata scan_metadata = 2;
}

message Scanner {
string uri = 1;
optional string version = 2;
VulnDatabase database = 3;
Result result = 4;
}

message VulnDatabase {
optional string uri = 1;
optional string version = 2;
google.protobuf.Timestamp last_update = 3;
}

message Result {
repeated Vulnerability vulnerabilities = 3;
}

message Vulnerability {
string id = 1;
repeated Severity severity = 2;

message Severity {
string method = 1;
string score = 2;
}

repeated google.protobuf.Struct annotations = 3;
}

message ScanMetadata {
google.protobuf.Timestamp scan_started_on = 1;
google.protobuf.Timestamp scan_finished_on = 2;
}
45 changes: 45 additions & 0 deletions protos/in_toto_attestation/predicates/vulns/v0.2/vulns.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
syntax = "proto3";

package in_toto_attestation.predicates.vulns.v02;

import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/in-toto/attestation/go/predicates/vulns/v02";
option java_package = "io.github.intoto.attestation.predicates.vulns.v02";

// Validation of all fields is left to the users of this proto.
message Vulns {
Scanner scanner = 1;
ScanMetadata scan_metadata = 2;
}

message Scanner {
string uri = 1;
optional string version = 2;
VulnDatabase database = 3;
repeated Result result = 4;
}

message VulnDatabase {
optional string uri = 1;
optional string version = 2;
google.protobuf.Timestamp last_update = 3;
}

message Result {
string id = 1;
repeated Severity severity = 2;

message Severity {
string method = 1;
string score = 2;
}

repeated google.protobuf.Struct annotations = 3;
}

message ScanMetadata {
google.protobuf.Timestamp scan_started_on = 1;
google.protobuf.Timestamp scan_finished_on = 2;
}
4 changes: 2 additions & 2 deletions spec/predicates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ our [vetting process], and may be of general interest:
artifact.
- [SPDX]: SPDX-formatted BOM for software artifacts.
- [CycloneDX]: CycloneDX BOM for software artifacts.
- [Vulnerability]: Defines the metadata to share the results of vulnerability scanning on software artifacts.
- [VULNS]: Defines the metadata to share the results of vulnerability scanning on software artifacts.
- [Release]: Details an artifact that is part of a given release version.
- [Test Result]: A generic schema to express results of any type of tests.
- [Reference]: References documents that are relevant to some resource.
Expand All @@ -34,7 +34,7 @@ our [vetting process], and may be of general interest:
[Release]: release.md
[Runtime Traces]: runtime-trace.md
[SCAI Report]: scai.md
[Vulnerability]: vuln.md
[VULNS]: vulns_02
[SLSA Provenance]: https://slsa.dev/provenance
[SLSA Verification Summary]: vsa.md
[SPDX]: spdx.md
Expand Down
10 changes: 9 additions & 1 deletion spec/predicates/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ fit because it doesn't support standardizing an attribute (which would be
desired here), the use case is distinct, and it is a larger prequisite.
A more opinionated predicate will increase usability and encourage adoption.


## Prerequisites

The
[in-toto Attestation Framework](https://github.com/in-toto/attestation/blob/main/spec/README.md)
and an SBOM specification such as [SPDX](https://spdx.dev/).

## Model

This predicate is intended to be generated and consumed throughout the software
supply chain. In addition, it is intended to be used in the analysis of it as a
whole.
Expand All @@ -56,6 +57,7 @@ whole.
```

### Parsing Rules

This predicate follows the
[in-toto Attestation Framework's parsing rules](../v1/README.md#parsing-rules).

Expand All @@ -68,6 +70,7 @@ being independently associated with each subject. See the
[example](#reference-to-an-sbom-for-multiple-artifacts) with two subjects.

### Fields

`attester.id`: string ([TypeUri](../v1/field_types.md#typeuri)), *required*

An identifier for the system that provides the document.
Expand All @@ -79,7 +82,9 @@ for each. If the file type is unknown, `application/octet-stream` SHOULD be
used.

## Examples

### Reference to an SBOM for an image

```json
{
"_type": "https://in-toto.io/Statement/v1",
Expand All @@ -104,11 +109,14 @@ used.
}
}
```

### Reference to an SBOM for multiple artifacts

In this example, a single SBOM was generated for a set of build outputs by
scanning the source file system. Per the [parsing rules](#parsing-rules), this
attestation SHOULD be interpreted to mean that the SBOM was generated for both
subjects -- it will list dependencies of both foo and bar.

```json
{
"_type": "https://in-toto.io/Statement/v1",
Expand Down
3 changes: 3 additions & 0 deletions spec/predicates/vuln.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Type URI: https://in-toto.io/attestation/vulns

Version: 0.1

You can check the latest version: [v0.2]

## Purpose

The definition of a vulnerability attestation type has been discussed in the past in [in-toto attestation](https://github.com/in-toto/attestation/issues/58) and [issue](https://github.com/sigstore/cosign/issues/442). However we need to identify two different purposes from these initial conversations:
Expand Down Expand Up @@ -158,3 +160,4 @@ The `predicate` contains a JSON-encoded data with the following fields:
Not applicable for this initial version.

[Attestation]: ../README.md
[v0.2]: vulns_0.2.md
156 changes: 156 additions & 0 deletions spec/predicates/vulns_02.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# Predicate type: Vulnerabilities

Type URI: https://in-toto.io/attestation/vulns

Version: 0.2

## Purpose

The definition of a vulnerability attestation type has been discussed in the past in [in-toto attestation](https://github.com/in-toto/attestation/issues/58) and [issue](https://github.com/sigstore/cosign/issues/442). However we need to identify two different purposes from these initial conversations:

- The definition of a common format to represent the results of a vulnerability report.
- The definition of a certain set of metadata fields that could help to consume these vulnerability attestations from the different scanning tools.

Obviously the first goal is quite challenging and requires a bigger community to agree upon a specific format. As a consequence, the following attestation type focuses on the definition of that common metadata which could enable the beginning of an exportable and manageable vulnerability attestation.

This document describes a vulnerability attestation type to represent vulnerability reports from the scanners in an "exportable" manner and independently of the format chosen to output the results.

## Prerequisites

The in-toto [attestation] framework and a Vulnerability scanner tools such as [Grype](https://github.com/anchore/grype), [Trivy](https://github.com/aquasecurity/trivy) and others.

## Use cases

When sharing the results of a vulnerability scan using an attestation, there is certain metadata that is crucial to trust and reuse this information.
Information about the scanner used during the scanning is relevant to trust these results. The state of the vulnerability database used to search for vulnerabilities defines the accuracy of the results. Other metadata information such as the timestamp when the scan finished could define the reusability of these results.

## Model

This is a predicate type that fits within the larger [Attestation] framework.
The following model aims to provide a well defined list of fields so that consumers know how to start exchanging their scanner results.

This predicate model is inspired by [cosign vulnerability attestation](https://github.com/sigstore/cosign/blob/main/specs/COSIGN_VULN_ATTESTATION_SPEC.md).

## Schema

The schema of this predicate type is documented below.

### Fields

The fields that make up this predicate type are:

The `subject` contains whatever software artifacts are to be associated with this vulnerability report document.
The `predicate` contains a JSON-encoded data with the following fields:

**scanner, required** object

> There are lots of container image scanners such as Trivy, Grype, Clair, etc.
> This field describes which scanner is used while performing a container image scan,
> as well as version information and which Vulnerability DB is used.

**scanner.uri, required** string (ResourceURI)

> > URI indicating the identity of the source of the scanner.

**scanner.version, optional** string (ResourceURI)

> > The version of the scanner.

**scanner.db.uri, optional** string (ResourceURI)

> > > URI indicating the identity of the source of the Vulnerability DB.

**scanner.db.version, optional** string

> > > The version of the Vulnerability DB.

**scanner.db.lastUpdate, required** string (timestamp)

> > > The timestamp of when the vulnerability DB was updated last time.

**scanner.result, required** object list

> > The result contains a list of vulnerabilities. Note that an empty list means the **scanner** found no vulnerabilities.
> > This is the most important part of this field because it'll store the scan result as a whole. So, people might want
> > to use this field to take decisions based on them by making use of Policy Engines tooling whether allow or deny these images.

**scanner.result.[*].id, required** string

> > > > This is the identifier of the vulnerability, e.g. [GHSA-fxph-q3j8-mv87](https://github.com/advisories/GHSA-fxph-q3j8-mv87) whose CVE id is [CVE-2017-5645](https://nvd.nist.gov/vuln/detail/CVE-2017-5645).

**scanner.result.[*].severity, required** object

> > > > The severity contains a list to describe the severity of a vulnerability using one or more quantitative scoring method.

**scanner.result.[*].severity.method, required** string

> > > > > The method describes the quantitative method used to calculate the associated severity score such as nvd, cvss and others.

**scanner.result.[*].severity.score, required** string

> > > > > This is a string representing the severity score based on the selected method.

**scanner.result.[*].annotations, optional** list, map <string, value>

> > > > > This is a list of key/value pairs where scanners can add additional custom information.

**metadata.scanStartedOn, required** Timestamp

> > The timestamp of when the scan started.

**metadata.scanFinishedOn, required** Timestamp

> > The timestamp of when the scan completed.

## Example

```jsonc
{
"_type": "https://in-toto.io/Statement/v1",
"subject": [
{
"name": "foo.jar",
"digest": {"sha256": "fe4fe40ac7250263c5dbe1cf3138912f3f416140aa248637a60d65fe22c47da4"}
}
],
// Predicate:
"predicateType": "https://in-toto.io/attestation/vulns/v0.2",
"predicate": {
"invocation": {
"parameters": [],
"uri": "https://github.com/developer-guy/alpine/actions/runs/1071875574",
"event_id": "1071875574",
"builder.id": "GitHub Actions"
},
"scanner": {
"uri": "pkg:github/aquasecurity/trivy@244fd47e07d1004f0aed9",
"version": "0.19.2",
"db": {
"uri": "pkg:github/aquasecurity/trivy-db/commit/4c76bb580b2736d67751410fa4ab66d2b6b9b27d",
"version": "v1-2021080612",
"lastUpdate": "2021-08-06T17:45:50.52Z"
},
"result": [
{
"id": "CVE-123",
"severity": [
{ "method": "nvd", "score": "medium"},
{ "method": "cvss_score", "score", "5.2" }
]
},
{...}
]
},
"metadata": {
"scanStartedOn": "2021-08-06T17:45:50.52Z",
"scanFinishedOn": "2021-08-06T17:50:50.52Z"
}
}
}
```

## Changelog and Migrations

Not applicable for this initial version.

[Attestation]: ../README.md