-
Notifications
You must be signed in to change notification settings - Fork 20
Implement SLSA Level 3 Cache Verification #242
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
Conversation
- Add github.com/slsa-framework/slsa-verifier/v2 v2.6.0 - Enables SLSA Level 3 verification for cached artifacts - Direct Go API integration without external processes Co-authored-by: Ona <no-reply@ona.com>
- Add SLSAVerification bool for enabling verification - Add TrustedRoots []string for CA configuration - Add RequireAttestation bool for strict mode - Add SourceURI string for repository validation - Support YAML/JSON serialization for configuration files Co-authored-by: Ona <no-reply@ona.com>
Features: - SLSA Level 3 verification using slsa-verifier/v2 Go API - SHA256 artifact hash calculation and validation - Source URI verification for supply chain security - Attestation key generation (.att file naming) - Comprehensive error handling with context support Security: - Prevents repository substitution attacks via SourceURI validation - Validates artifact integrity through cryptographic hashing - Follows official slsa-verifier CLI implementation patterns Testing: - 90% test coverage with unit tests - Exact hash verification for deterministic testing - Error handling validation for missing files - Edge case coverage for robustness Co-authored-by: Ona <no-reply@ona.com>
- Define VerifierInterface for testable SLSA verification - Implement MockVerifier with configurable behavior for testing - Add helper functions for simulating verification scenarios - Enable comprehensive testing of SLSA verification logic Co-authored-by: Ona <no-reply@ona.com>
- Add direct dependency on golang.org/x/time/rate - Required for S3 API rate limiting to prevent service abuse - Ensures proper dependency management for production deployment Co-authored-by: Ona <no-reply@ona.com>
Critical production fixes: - Fix channel reading race conditions in parallel operations - Add context timeout protection (30-60s) for all storage calls - Implement rate limiting (100 RPS, 200 burst) to prevent API abuse - Add goroutine count limiting (max 50) for scalability - Add file cleanup race condition protection with mutex - Use VerifierInterface for testable SLSA verification - Add proper error handling and graceful degradation Performance improvements: - Maintain backward compatibility for non-SLSA workflows - Preserve throughput while adding safety mechanisms - Add monitoring for high resource usage detection Co-authored-by: Ona <no-reply@ona.com>
- Test successful SLSA verification with mock verifier - Test missing attestation scenarios (required vs optional) - Test backward compatibility when verification disabled - Test network error handling during attestation download - Test mock verifier integration and behavior - Add race-safe mock storage with mutex protection - Verify performance overhead targets and logging Co-authored-by: Ona <no-reply@ona.com>
- Initialize rateLimiter and semaphore in all test S3Cache instances - Add required imports for golang.org/x/time/rate - Fix nil pointer dereferences that caused segmentation violations - Ensure all tests properly initialize production-ready S3Cache fields - Maintain test compatibility with new concurrency safety features Fixes critical issue where tests created S3Cache directly without going through constructor, leaving essential fields uninitialized. Co-authored-by: Ona <no-reply@ona.com>
- Add EnvvarSLSACacheVerification and EnvvarSLSASourceURI constants - Update CLI help text to document new environment variables - Follow existing Leeway patterns for environment variable naming Co-authored-by: Ona <no-reply@ona.com>
- Add --slsa-cache-verification and --slsa-source-uri flags - Implement flag override logic with proper error handling - Add validation requiring source-uri when verification enabled - Support GCP compatibility with graceful degradation warning - Maintain backward compatibility with getRemoteCacheFromEnv() Priority order: CLI flags → environment variables → defaults Co-authored-by: Ona <no-reply@ona.com>
Remove unused golang.org/x/time v0.11.0 entry, keep only v0.13.0 Co-authored-by: Ona <no-reply@ona.com>
- Add proper error handling for os.Remove calls during cleanup - Add proper error handling for file.Close calls - Remove unused createInvalidAttestation function Co-authored-by: Ona <no-reply@ona.com>
Overall the changes make sense, but the PR is quite meaty, so hard to tell for sure. I'd say whatever we can do to simplify/reduce it would be a big plus! 👍 |
- Create dedicated SLSAConfig struct to encapsulate SLSA settings - Extract parseSLSAConfig() function with proper CLI/env priority handling - Update getRemoteCache() to use clean configuration structure - Add comprehensive documentation for RequireAttestation behavior - Preserve RequireAttestation field for future CLI flag extensibility This refactoring addresses architectural feedback while maintaining backward compatibility and production readiness. Co-authored-by: Ona <no-reply@ona.com>
…hitecture - Extract downloadFileAsync() function to eliminate duplication between artifact/attestation downloads - Refactor downloadBothParallel() to use shared download logic - Update constructor to use new SLSA configuration structure - Simplify verification check to use s.slsaVerifier != nil pattern - Add comprehensive documentation for RequireAttestation behavior and graceful fallback design - Maintain all rate limiting, concurrency controls, and error handling This reduces code duplication while preserving all production safety features. Co-authored-by: Ona <no-reply@ona.com>
- Create helper functions createTestConfig() and createTestConfigWithRequiredAttestation() - Update all test cases to use new SLSAConfig structure - Add comprehensive documentation for RequireAttestation test behavior - Document expected behavior: RequireAttestation=true + missing attestation → skip download, allow local build fallback - Maintain all existing test coverage and expectations All tests pass, confirming the architectural changes preserve functionality. Co-authored-by: Ona <no-reply@ona.com>
- Add downloadResult struct with proper error attribution by kind - Update downloadFileAsync to use structured results instead of plain errors - Refactor downloadBothParallel with improved context cancellation handling - Replace fragile string matching with reliable kind-based error attribution - Improve error messages for context cancellation scenarios Benefits: ✅ Reliable Error Attribution: No more fragile string matching ✅ Better Context Cancellation: Proper error reporting when operations are cancelled ✅ Cleaner Code: Structured approach is more maintainable ✅ Better Debugging: Clear error messages show exactly what failed and why Co-authored-by: Ona <no-reply@ona.com>
// parseSLSAConfig parses SLSA configuration from CLI flags and environment variables | ||
func parseSLSAConfig(cmd *cobra.Command) (*cache.SLSAConfig, error) { | ||
// Get SLSA verification settings from environment variables (defaults) | ||
slsaVerificationEnabled := os.Getenv(EnvvarSLSACacheVerification) == "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: os.Getenv
lends itself to be passed into cmd.Flags().Bool(
as bool, which is an established pattern and would simpify this method a lot.
// Returns nil (not an error) when no suitable artifacts are found to allow graceful fallback to local builds. | ||
// | ||
// Future CLI flag consideration: --slsa-require-attestation could set RequireAttestation=true | ||
func (s *S3Cache) downloadWithSLSAVerification(ctx context.Context, p cache.Package, version, localPath string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this whole method tree and the changes make sense.
Yet some of the code around synchronization and rate-limiting feels not very idiomatic, or even overly complex. But as I can't put the finger on something, and given that a) it works well and b) there's also a lot of aspects handled here (2 download artifacts, retry attempts, parallel download, rate-limiting, SLSA correctness), let's move with it. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's mostly the "too many aspects mixed into one hierachy" kind of thing 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left one nit and one concern (too much complexity), but otherwise LGTM!
✔️ to unblock
Description
This PR implements comprehensive SLSA Level 3 cache verification for Leeway, ensuring cached artifacts are verified before use. The implementation provides production-ready security with zero breaking changes to existing workflows.
🏗️ Implementation Details
Phase 1: Core Infrastructure
Phase 2: Production-Ready S3Cache
Phase 3: CLI Integration
🛡️ Security & Reliability
Concurrency Safety
Resource Management
Error Handling
📈 Testing
🔄 Backward Compatibility
-All cache modes (none, local, remote) preserved
🚦 Validation
Related Issue(s)
Closes https://linear.app/ona-team/issue/CLC-1961/implement-cache-verification-during-download-leeway
How to test
Environment Variables
CLI Flags
CI/CD Ready
Documentation
/hold