Skip to content

Commit 2b4be5a

Browse files
Add SBOM generation and vulnerabilities scan
1 parent b5e8cd3 commit 2b4be5a

File tree

9 files changed

+3502
-110
lines changed

9 files changed

+3502
-110
lines changed

.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "lts"
77
},
88
"ghcr.io/devcontainers/features/go:1": {
9-
"version": "1.24.0"
9+
"version": "1.24.1"
1010
},
1111
"ghcr.io/devcontainers/features/common-utils:2": {},
1212
"ghcr.io/devcontainers-contrib/features/shfmt:1": {

README.md

+113
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,119 @@ environmentManifest:
322322

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

325+
## SBOM and Vulnerability Scanning
326+
327+
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.
328+
329+
### Enabling SBOM Generation
330+
331+
SBOM generation is configured in your `WORKSPACE.yaml` file:
332+
333+
```yaml
334+
sbom:
335+
enabled: true # Enable SBOM generation
336+
scanVulnerabilities: true # Enable vulnerability scanning
337+
failOn: ["critical", "high"] # Fail builds with vulnerabilities of these severities (default: build does not fail)
338+
ignoreVulnerabilities: # Workspace-level ignore rules
339+
- vulnerability: "CVE-2023-1234"
340+
reason: "Not exploitable in our context"
341+
```
342+
343+
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.
344+
345+
### Vulnerability Scanning
346+
347+
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:
348+
349+
- `vulnerabilities.txt` - Human-readable table format
350+
- `vulnerabilities.json` - Detailed JSON format
351+
- `vulnerabilities.cdx.json` - CycloneDX format
352+
- `vulnerabilities.sarif` - SARIF format for integration with code analysis tools
353+
354+
#### Configuring Build Failure Thresholds
355+
356+
The `failOn` setting determines which vulnerability severity levels will cause a build to fail. Omit this configuration to generate only the reports without causing the build to fail. For example:
357+
358+
```yaml
359+
failOn: ["critical", "high"] # Fail on critical and high vulnerabilities
360+
```
361+
362+
Supported severity levels are: `critical`, `high`, `medium`, `low`, `negligible`, and `unknown`.
363+
364+
### Ignoring Vulnerabilities
365+
366+
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).
367+
368+
#### Ignore Rule Configuration
369+
370+
Ignore rules use Grype's powerful filtering capabilities:
371+
372+
```yaml
373+
# In WORKSPACE.yaml (workspace-level rules)
374+
sbom:
375+
ignoreVulnerabilities:
376+
# Basic usage - ignore a specific CVE
377+
- vulnerability: "CVE-2023-1234"
378+
reason: "Not exploitable in our context"
379+
380+
# Advanced usage - ignore a vulnerability only for a specific package
381+
- vulnerability: "GHSA-abcd-1234-efgh"
382+
reason: "Mitigated by our application architecture"
383+
package:
384+
name: "vulnerable-pkg"
385+
version: "1.2.3"
386+
387+
# Using fix state
388+
- vulnerability: "CVE-2023-5678"
389+
reason: "Will be fixed in next dependency update"
390+
fix-state: "fixed"
391+
392+
# Using VEX status
393+
- vulnerability: "CVE-2023-9012"
394+
reason: "Not affected as we don't use the vulnerable component"
395+
vex-status: "not_affected"
396+
vex-justification: "vulnerable_code_not_in_execute_path"
397+
```
398+
399+
#### Package-Level Ignore Rules
400+
401+
You can also specify ignore rules for specific packages in their `BUILD.yaml` file:
402+
403+
```yaml
404+
# In package BUILD.yaml
405+
packages:
406+
- name: my-package
407+
type: go
408+
# ... other package configuration ...
409+
sbom:
410+
ignoreVulnerabilities:
411+
- vulnerability: "GHSA-abcd-1234-efgh"
412+
reason: "Mitigated by our application architecture"
413+
```
414+
415+
Package-level rules are combined with workspace-level rules during vulnerability scanning.
416+
417+
#### Available Ignore Rule Fields
418+
419+
Leeway's ignore rules support all of Grype's filtering capabilities:
420+
421+
- `vulnerability`: The vulnerability ID to ignore (e.g., "CVE-2023-1234")
422+
- `reason`: The reason for ignoring this vulnerability (required)
423+
- `namespace`: The vulnerability namespace (e.g., "github:golang")
424+
- `fix-state`: The fix state to match (e.g., "fixed", "not-fixed", "unknown")
425+
- `package`: Package-specific criteria (see below)
426+
- `vex-status`: VEX status (e.g., "affected", "fixed", "not_affected")
427+
- `vex-justification`: Justification for the VEX status
428+
- `match-type`: The type of match to ignore (e.g., "exact-direct-dependency")
429+
430+
The `package` field can contain:
431+
- `name`: Package name (supports regex)
432+
- `version`: Package version
433+
- `language`: Package language
434+
- `type`: Package type
435+
- `location`: Package location (supports glob patterns)
436+
- `upstream-name`: Upstream package name (supports regex)
437+
325438
# Configuration
326439
Leeway is configured exclusively through the WORKSPACE.yaml/BUILD.yaml files and environment variables. The following environment
327440
variables have an effect on leeway:

WORKSPACE.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ environmentManifest:
99
provenance:
1010
enabled: true
1111
slsa: true
12+
sbom:
13+
enabled: true
14+
scanVulnerabilities: true
15+
# failOn: ["critical", "high"]
16+
# ignoreVulnerabilities:
17+
# - vulnerability: GHSA-265r-hfxg-fhmg
18+
# reason: "Not exploitable in our context"
1219
variants:
1320
- name: nogit
1421
srcs:
1522
exclude:
16-
- "**/.git"
23+
- "**/.git"

0 commit comments

Comments
 (0)