Skip to content

Commit aa90eac

Browse files
leodidoona-agent
andcommitted
feat(slsa): add RequireAttestation configuration for strict SLSA verification
Add support for LEEWAY_SLSA_REQUIRE_ATTESTATION environment variable and --slsa-require-attestation CLI flag to control behavior when SLSA attestations are missing or invalid. When RequireAttestation=true (strict mode): - Missing/invalid attestation → skip download, build locally - Enables self-healing for cross-PR attestation mismatches - Auto-enabled when provenance.slsa=true in WORKSPACE.yaml When RequireAttestation=false (permissive mode, default): - Missing/invalid attestation → download without verification (with warning) - Provides graceful degradation and backward compatibility Changes: - Add EnvvarSLSARequireAttestation constant to cmd/root.go and pkg/leeway/workspace.go - Add --slsa-require-attestation flag to build command - Update parseSLSAConfig() to read and apply RequireAttestation setting - Update ApplySLSADefaults() to auto-enable RequireAttestation with SLSA L3 - Enhance documentation in pkg/leeway/cache/types.go - Update implementation comments in pkg/leeway/cache/remote/s3.go The actual RequireAttestation logic in downloadWithSLSAVerification() was already implemented; this commit adds the configuration mechanism. Co-authored-by: Ona <no-reply@ona.com>
1 parent aae072b commit aa90eac

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

cmd/build.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ func addBuildFlags(cmd *cobra.Command) {
202202
cmd.Flags().StringToString("docker-build-options", nil, "Options passed to all 'docker build' commands")
203203
cmd.Flags().Bool("slsa-cache-verification", false, "Enable SLSA verification for cached artifacts")
204204
cmd.Flags().String("slsa-source-uri", "", "Expected source URI for SLSA verification (required when verification enabled)")
205+
cmd.Flags().Bool("slsa-require-attestation", false, "Require SLSA attestations (missing/invalid → build locally)")
205206
cmd.Flags().Bool("in-flight-checksums", false, "Enable checksumming of cache artifacts to prevent TOCTU attacks")
206207
cmd.Flags().String("report", "", "Generate a HTML report after the build has finished. (e.g. --report myreport.html)")
207208
cmd.Flags().String("report-segment", os.Getenv(EnvvarSegmentKey), "Report build events to segment using the segment key (defaults to $LEEWAY_SEGMENT_KEY)")
@@ -442,6 +443,7 @@ func parseSLSAConfig(cmd *cobra.Command) (*cache.SLSAConfig, error) {
442443
// Get SLSA verification settings from environment variables (defaults)
443444
slsaVerificationEnabled := os.Getenv(EnvvarSLSACacheVerification) == "true"
444445
slsaSourceURI := os.Getenv(EnvvarSLSASourceURI)
446+
requireAttestation := os.Getenv(EnvvarSLSARequireAttestation) == "true"
445447

446448
// CLI flags override environment variables (if cmd is provided)
447449
if cmd != nil {
@@ -455,6 +457,11 @@ func parseSLSAConfig(cmd *cobra.Command) (*cache.SLSAConfig, error) {
455457
slsaSourceURI = flagValue
456458
}
457459
}
460+
if cmd.Flags().Changed("slsa-require-attestation") {
461+
if flagValue, err := cmd.Flags().GetBool("slsa-require-attestation"); err == nil {
462+
requireAttestation = flagValue
463+
}
464+
}
458465
}
459466

460467
// If verification is disabled, return nil
@@ -471,7 +478,7 @@ func parseSLSAConfig(cmd *cobra.Command) (*cache.SLSAConfig, error) {
471478
Verification: true,
472479
SourceURI: slsaSourceURI,
473480
TrustedRoots: []string{"https://fulcio.sigstore.dev"},
474-
RequireAttestation: false, // Default: missing attestation → download without verification
481+
RequireAttestation: requireAttestation,
475482
}, nil
476483
}
477484

cmd/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const (
3131
// EnvvarSLSASourceURI configures the expected source URI for SLSA verification
3232
EnvvarSLSASourceURI = "LEEWAY_SLSA_SOURCE_URI"
3333

34+
// EnvvarSLSARequireAttestation requires SLSA attestations (missing/invalid → build locally)
35+
EnvvarSLSARequireAttestation = "LEEWAY_SLSA_REQUIRE_ATTESTATION"
36+
3437
// EnvvarEnableInFlightChecksums enables in-flight checksumming of cache artifacts
3538
EnvvarEnableInFlightChecksums = "LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS"
3639

@@ -120,6 +123,7 @@ variables have an effect on leeway:
120123
<light_blue>LEEWAY_DEFAULT_CACHE_LEVEL</> Sets the default cache level for builds. Defaults to "remote".
121124
<light_blue>LEEWAY_SLSA_CACHE_VERIFICATION</> Enables SLSA verification for cached artifacts (true/false).
122125
<light_blue>LEEWAY_SLSA_SOURCE_URI</> Expected source URI for SLSA verification (github.com/owner/repo).
126+
<light_blue>LEEWAY_SLSA_REQUIRE_ATTESTATION</> Require valid attestations; missing/invalid → build locally (true/false).
123127
<light_blue>LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS</> Enable checksumming of cache artifacts (true/false).
124128
<light_blue>LEEWAY_EXPERIMENTAL</> Enables experimental leeway features and commands.
125129
`),

pkg/leeway/cache/remote/s3.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,11 @@ func (s *S3Cache) downloadOriginal(ctx context.Context, p cache.Package, version
442442
// This function tries multiple extensions (.tar.gz, .tar) and their corresponding attestations.
443443
// Returns nil (not an error) when no suitable artifacts are found to allow graceful fallback to local builds.
444444
//
445-
// Future CLI flag consideration: --slsa-require-attestation could set RequireAttestation=true
445+
// Configuration:
446+
// RequireAttestation can be set via:
447+
// - Environment variable: LEEWAY_SLSA_REQUIRE_ATTESTATION=true
448+
// - CLI flag: --slsa-require-attestation
449+
// - Workspace config: Automatically enabled when provenance.slsa=true in WORKSPACE.yaml
446450
func (s *S3Cache) downloadWithSLSAVerification(ctx context.Context, p cache.Package, version, localPath string) error {
447451
log.WithFields(log.Fields{
448452
"package": p.FullName(),

pkg/leeway/cache/types.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
// The cache system supports SLSA (Supply-chain Levels for Software Artifacts) verification
55
// for enhanced security. The behavior is controlled by the SLSAConfig.RequireAttestation field:
66
//
7-
// - RequireAttestation=false (default): Missing attestation → download without verification
8-
// This provides graceful degradation and backward compatibility.
7+
// - RequireAttestation=false (default): Missing/invalid attestation → download without verification
8+
// This provides graceful degradation and backward compatibility. The artifact is downloaded
9+
// and used, but a warning is logged about the missing or invalid attestation.
910
//
10-
// - RequireAttestation=true: Missing attestation → skip download, allow local build fallback
11-
// This enforces strict security but may impact build performance.
11+
// - RequireAttestation=true: Missing/invalid attestation → skip download, allow local build fallback
12+
// This enforces strict security but may impact build performance. When verification fails,
13+
// the artifact is not downloaded, forcing a local rebuild with proper attestation.
1214
//
1315
// The cache system is designed to never fail builds due to cache issues. When artifacts
1416
// cannot be downloaded (missing, verification failed, network issues), the system gracefully
1517
// falls back to local builds.
1618
//
17-
// Future Evolution:
18-
// A CLI flag like --slsa-require-attestation could be added to set RequireAttestation=true
19-
// for environments that require strict SLSA compliance.
19+
// Configuration:
20+
// RequireAttestation can be controlled via:
21+
// - Environment variable: LEEWAY_SLSA_REQUIRE_ATTESTATION=true
22+
// - CLI flag: --slsa-require-attestation
23+
// - Workspace SLSA config: Automatically enabled when provenance.slsa=true in WORKSPACE.yaml
2024
package cache
2125

2226
import (

pkg/leeway/workspace.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const (
3737
// EnvvarSLSASourceURI configures the expected source URI for SLSA verification
3838
EnvvarSLSASourceURI = "LEEWAY_SLSA_SOURCE_URI"
3939

40+
// EnvvarSLSARequireAttestation requires SLSA attestations (missing/invalid → build locally)
41+
EnvvarSLSARequireAttestation = "LEEWAY_SLSA_REQUIRE_ATTESTATION"
42+
4043
// EnvvarEnableInFlightChecksums enables in-flight checksumming of cache artifacts
4144
EnvvarEnableInFlightChecksums = "LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS"
4245
)
@@ -75,6 +78,7 @@ type WorkspaceProvenance struct {
7578
//
7679
// Sets environment variables as defaults (only if not already set):
7780
// - LEEWAY_SLSA_CACHE_VERIFICATION
81+
// - LEEWAY_SLSA_REQUIRE_ATTESTATION
7882
// - LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS
7983
// - LEEWAY_DOCKER_EXPORT_TO_CACHE
8084
// - LEEWAY_SLSA_SOURCE_URI (from Git origin)
@@ -92,6 +96,11 @@ func (w *Workspace) ApplySLSADefaults() {
9296
log.Debug("Auto-enabled: LEEWAY_SLSA_CACHE_VERIFICATION=true")
9397
}
9498

99+
// Auto-enable require attestation for strict SLSA compliance (global feature)
100+
if setEnvDefault(EnvvarSLSARequireAttestation, "true") {
101+
log.Debug("Auto-enabled: LEEWAY_SLSA_REQUIRE_ATTESTATION=true")
102+
}
103+
95104
// Auto-enable in-flight checksumming (global feature)
96105
if setEnvDefault(EnvvarEnableInFlightChecksums, "true") {
97106
log.Debug("Auto-enabled: LEEWAY_ENABLE_IN_FLIGHT_CHECKSUMS=true")

0 commit comments

Comments
 (0)