Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: Sertac Ozercan <[email protected]>
  • Loading branch information
sozercan committed Aug 28, 2023
1 parent dbcf2d3 commit 92a5385
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
3 changes: 2 additions & 1 deletion pkg/patch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ func patchWithContext(ctx context.Context, buildkitAddr, image, reportFile, patc
validatedManifest.Updates = append(validatedManifest.Updates, update)
}

Check warning on line 155 in pkg/patch/patch.go

View check run for this annotation

Codecov / codecov/patch

pkg/patch/patch.go#L146-L155

Added lines #L146 - L155 were not covered by tests
}
if output != "" {
// vex document must contain at least one statement
if output != "" && len(validatedManifest.Updates) > 0 {
return vex.TryOutputVexDocument(validatedManifest, pkgmgr, format, output)
}
return nil

Check warning on line 161 in pkg/patch/patch.go

View check run for this annotation

Codecov / codecov/patch

pkg/patch/patch.go#L158-L161

Added lines #L158 - L161 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion pkg/vex/openvex.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (o *OpenVex) CreateVEXDocument(updates *types.UpdateManifest, pkgmgr pkgmgr
product := vex.Product{
Component: vex.Component{
// syntax is "pkg:<pkgType>/<osType>/<packageName>@<installedVersion>?arch=<arch>"
ID: "pkg:" + pkgType + "/" + updates.OSType + "/" + u.Name + "@" + u.InstalledVersion + "?arch=" + updates.Arch,
ID: "pkg:" + pkgType + "/" + updates.OSType + "/" + u.Name + "@" + u.FixedVersion + "?arch=" + updates.Arch,
},
}

Expand Down
21 changes: 8 additions & 13 deletions pkg/vex/openvex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ func TestOpenVex_CreateVEXDocument(t *testing.T) {
updates: &types.UpdateManifest{
Updates: []types.UpdatePackage{
{
Name: "test",
Name: "test1",
InstalledVersion: "1.0",
FixedVersion: "1.1",
VulnerabilityID: "CVE-2020-1234",
},
},
Expand All @@ -64,7 +65,7 @@ func TestOpenVex_CreateVEXDocument(t *testing.T) {
},
"products": [
{
"@id": "pkg:apk/alpine/test@1.0?arch=x86_64"
"@id": "pkg:apk/alpine/test1@1.1?arch=x86_64"
}
],
"status": "fixed"
Expand All @@ -80,19 +81,16 @@ func TestOpenVex_CreateVEXDocument(t *testing.T) {
args: args{
updates: &types.UpdateManifest{
Updates: []types.UpdatePackage{
{
Name: "test",
InstalledVersion: "1.0",
VulnerabilityID: "CVE-2020-1234",
},
{
Name: "test2",
InstalledVersion: "1.0",
FixedVersion: "1.2",
VulnerabilityID: "CVE-2020-1234",
},
{
Name: "test3",
InstalledVersion: "1.0",
FixedVersion: "1.3",
VulnerabilityID: "CVE-2020-1235",
},
},
Expand All @@ -115,13 +113,10 @@ func TestOpenVex_CreateVEXDocument(t *testing.T) {
},
"products": [
{
"@id": "pkg:apk/alpine/[email protected]?arch=x86_64"
},
{
"@id": "pkg:deb/debian/[email protected]?arch=x86_64"
"@id": "pkg:apk/alpine/[email protected]?arch=x86_64"
},
{
"@id": "pkg:deb/debian/test2@1.0?arch=x86_64"
"@id": "pkg:deb/debian/test2@1.2?arch=x86_64"
}
],
"status": "fixed"
Expand All @@ -132,7 +127,7 @@ func TestOpenVex_CreateVEXDocument(t *testing.T) {
},
"products": [
{
"@id": "pkg:deb/debian/test3@1.0?arch=x86_64"
"@id": "pkg:deb/debian/test3@1.3?arch=x86_64"
}
],
"status": "fixed"
Expand Down
16 changes: 14 additions & 2 deletions website/docs/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
title: Output
---

:::caution

Experimental: This feature might change without preserving backwards compatibility.

:::

Copa optionally outputs a Vulnerability Exploitability eXchange (VEX) file as a result of the patching process to surface the vulnerabilities and packages that were patched.

Currently, Copa supports the [OpenVEX](https://github.com/openvex) format, but it can be extended to support other formats.
Expand All @@ -10,14 +16,20 @@ Currently, Copa supports the [OpenVEX](https://github.com/openvex) format, but i

OpenVEX is an implementation of Vulnerability Exploitability eXchange (VEX) format. For more information, see [OpenVEX specification](https://github.com/openvex/spec/).

:::tip

- Use `COPA_VEX_AUTHOR` environment variable to set the author of the VEX document. If it's not set, the author will default to `Project Copacetic`.

- A VEX document must contain at least one VEX statement. If there are no fixed vulnerabilities, Copa will not generate a VEX document.

:::

To generate a VEX document using OpenVEX, use `--format="openvex"` flag, and use `--output` to specify a file path. For example:

```bash
copa patch -i docker.io/library/nginx:1.21.6 -r nginx.1.21.6.json -t 1.21.6-patched --format="openvex" --output "nginx.1.21.6-vex.json"
```

Use `COPA_VEX_AUTHOR` environment variable to set the author of the VEX document. If it's not set, the author will default to `Project Copacetic`.

This will generate a VEX Document that looks like:

```json
Expand Down

0 comments on commit 92a5385

Please sign in to comment.