Skip to content

SBOM generation and CVE scanning #220

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

Draft
wants to merge 32 commits into
base: clu/fix-leeway-build
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ff2191b
Add Syft and Grype dependencies
corneliusludmann Apr 1, 2025
a7685eb
Add inital SBOM stubs
corneliusludmann Apr 1, 2025
17a23e8
Add SBOM generation implementation
corneliusludmann Apr 2, 2025
6b40f95
grype 1
corneliusludmann Apr 2, 2025
c6ebccd
grype 2
corneliusludmann Apr 2, 2025
d404061
scanCVE
corneliusludmann Apr 2, 2025
84dcd06
use reporter
corneliusludmann Apr 2, 2025
36cb02f
all sbom formats
corneliusludmann Apr 2, 2025
4bcb17d
small improvements
corneliusludmann Apr 2, 2025
552f03e
fail on findings
corneliusludmann Apr 2, 2025
835a3a8
Always log vuln per severity
corneliusludmann Apr 2, 2025
deff09f
Add more vuln output formats
corneliusludmann Apr 2, 2025
3ff1ec8
Add db info to output files
corneliusludmann Apr 2, 2025
af744d2
minor fixes
corneliusludmann Apr 2, 2025
8fe7497
Ignroe rules
corneliusludmann Apr 2, 2025
b60744c
Ignore rule 2
corneliusludmann Apr 2, 2025
c3bdccc
Add section to README.md
corneliusludmann Apr 2, 2025
8977e60
rename ScanCVE to ScanVulnerabilities
corneliusludmann Apr 2, 2025
9203fb8
Remove AccessSBOMInCachedArchive for now.
corneliusludmann Apr 2, 2025
208bc37
Handle Docker packages for SBOM generation
corneliusludmann Apr 2, 2025
e225318
Vuln scan independent from build also for cached
corneliusludmann Apr 3, 2025
f69b114
error logging
corneliusludmann Apr 3, 2025
caf5f7d
try to fix docker
corneliusludmann Apr 3, 2025
6aa9786
tmp debug output
corneliusludmann Apr 3, 2025
592f653
Add sbom files to package cache
corneliusludmann Apr 3, 2025
47c4a14
remove tmp debug output
corneliusludmann Apr 3, 2025
2ca2491
Remove vuln scan config from version calculation since we scan vuln o…
corneliusludmann Apr 3, 2025
529d578
Fix docker scan
corneliusludmann Apr 3, 2025
5cfd4a6
Add sbom to docker source path when no image name
corneliusludmann Apr 3, 2025
32f6e0f
Try to fix
corneliusludmann Apr 3, 2025
5256d88
sbom extraction fails
corneliusludmann Apr 3, 2025
a0aa916
Fix package ignore rules
corneliusludmann Apr 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"version": "lts"
},
"ghcr.io/devcontainers/features/go:1": {
"version": "1.24.0"
"version": "1.24.1"
},
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers-contrib/features/shfmt:1": {
Expand Down
113 changes: 113 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,119 @@ environmentManifest:

Using this mechanism you can also overwrite the default manifest entries, e.g. "go" or "yarn".

## SBOM and Vulnerability Scanning

Leeway includes built-in support for Software Bill of Materials (SBOM) generation and vulnerability scanning. This feature helps you identify and manage security vulnerabilities in your software supply chain.

### Enabling SBOM Generation

SBOM generation is configured in your `WORKSPACE.yaml` file:

```yaml
sbom:
enabled: true # Enable SBOM generation
scanVulnerabilities: true # Enable vulnerability scanning
failOn: ["critical", "high"] # Fail builds with vulnerabilities of these severities
ignoreVulnerabilities: # Workspace-level ignore rules
- vulnerability: "CVE-2023-1234"
reason: "Not exploitable in our context"
```

When enabled, Leeway automatically generates SBOMs for each package during the build process in multiple formats (CycloneDX, SPDX, and Syft JSON) using [Syft](https://github.com/anchore/syft). These SBOMs are included in the package's build artifacts.

### Vulnerability Scanning

When `scanVulnerabilities` is enabled, Leeway scans the generated SBOMs for vulnerabilities using [Grype](https://github.com/anchore/grype). The scan results are written to the build directory in multiple formats:

- `vulnerabilities.txt` - Human-readable table format
- `vulnerabilities.json` - Detailed JSON format
- `vulnerabilities.cdx.json` - CycloneDX format
- `vulnerabilities.sarif` - SARIF format for integration with code analysis tools

#### Configuring Build Failure Thresholds

The `failOn` setting determines which vulnerability severity levels will cause a build to fail. For example:

```yaml
failOn: ["critical", "high"] # Fail on critical and high vulnerabilities
```

Supported severity levels are: `critical`, `high`, `medium`, `low`, `negligible`, and `unknown`.

### Ignoring Vulnerabilities

Leeway provides a flexible system for ignoring specific vulnerabilities. Ignore rules can be defined at both the workspace level (in `WORKSPACE.yaml`) and the package level (in `BUILD.yaml`). For detailed documentation on ignore rules, see [Grype's documentation on specifying matches to ignore](https://github.com/anchore/grype/blob/main/README.md#specifying-matches-to-ignore).

#### Ignore Rule Configuration

Ignore rules use Grype's powerful filtering capabilities:

```yaml
# In WORKSPACE.yaml (workspace-level rules)
sbom:
ignoreVulnerabilities:
# Basic usage - ignore a specific CVE
- vulnerability: "CVE-2023-1234"
reason: "Not exploitable in our context"

# Advanced usage - ignore a vulnerability only for a specific package
- vulnerability: "GHSA-abcd-1234-efgh"
reason: "Mitigated by our application architecture"
package:
name: "vulnerable-pkg"
version: "1.2.3"

# Using fix state
- vulnerability: "CVE-2023-5678"
reason: "Will be fixed in next dependency update"
fix-state: "fixed"

# Using VEX status
- vulnerability: "CVE-2023-9012"
reason: "Not affected as we don't use the vulnerable component"
vex-status: "not_affected"
vex-justification: "vulnerable_code_not_in_execute_path"
```

#### Package-Level Ignore Rules

You can also specify ignore rules for specific packages in their `BUILD.yaml` file:

```yaml
# In package BUILD.yaml
packages:
- name: my-package
type: go
# ... other package configuration ...
sbom:
ignoreVulnerabilities:
- vulnerability: "GHSA-abcd-1234-efgh"
reason: "Mitigated by our application architecture"
```

Package-level rules are combined with workspace-level rules during vulnerability scanning.

#### Available Ignore Rule Fields

Leeway's ignore rules support all of Grype's filtering capabilities:

- `vulnerability`: The vulnerability ID to ignore (e.g., "CVE-2023-1234")
- `reason`: The reason for ignoring this vulnerability (required)
- `namespace`: The vulnerability namespace (e.g., "github:golang")
- `fix-state`: The fix state to match (e.g., "fixed", "not-fixed", "unknown")
- `package`: Package-specific criteria (see below)
- `vex-status`: VEX status (e.g., "affected", "fixed", "not_affected")
- `vex-justification`: Justification for the VEX status
- `match-type`: The type of match to ignore (e.g., "exact-direct-dependency")

The `package` field can contain:
- `name`: Package name (supports regex)
- `version`: Package version
- `language`: Package language
- `type`: Package type
- `location`: Package location (supports glob patterns)
- `upstream-name`: Upstream package name (supports regex)

# Configuration
Leeway is configured exclusively through the WORKSPACE.yaml/BUILD.yaml files and environment variables. The following environment
variables have an effect on leeway:
Expand Down
9 changes: 8 additions & 1 deletion WORKSPACE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ environmentManifest:
provenance:
enabled: true
slsa: true
sbom:
enabled: true
scanVulnerabilities: true
failOn: ["critical", "high"]
ignoreVulnerabilities:
- vulnerability: GHSA-265r-hfxg-fhmg
reason: "TESTING REMOVE ME"
variants:
- name: nogit
srcs:
exclude:
- "**/.git"
- "**/.git"
Loading