Skip to content

Conversation

@joejstuart
Copy link
Contributor

The ec validate vsa command enables validation of Verification Summary Attestations (VSAs) that contain policy evaluation results for container images. This feature allows users to verify that images meet enterprise contract requirements by validating pre-computed attestation data.

@codecov
Copy link

codecov bot commented Sep 5, 2025

Codecov Report

❌ Patch coverage is 60.20821% with 688 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/evaluator/conftest_evaluator.go 13.77% 219 Missing ⚠️
cmd/validate/vsa.go 70.00% 120 Missing ⚠️
internal/applicationsnapshot/report.go 0.00% 120 Missing ⚠️
internal/validate/vsa/validation.go 79.85% 86 Missing ⚠️
internal/utils/safe_arithmetic.go 0.00% 62 Missing ⚠️
internal/validate/vsa/rekor_retriever.go 56.63% 49 Missing ⚠️
internal/validate/vsa/types.go 91.46% 14 Missing ⚠️
internal/evaluator/rule_discovery.go 88.99% 12 Missing ⚠️
internal/applicationsnapshot/attestation.go 62.50% 3 Missing ⚠️
internal/validate/vsa/file_retriever.go 93.10% 2 Missing ⚠️
... and 1 more
Flag Coverage Δ
generative 66.17% <60.20%> (-1.09%) ⬇️
integration 66.17% <60.20%> (-1.09%) ⬇️
unit 66.17% <60.20%> (-1.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/validate/validate.go 100.00% <100.00%> (ø)
internal/applicationsnapshot/input.go 90.65% <100.00%> (+0.13%) ⬆️
internal/validate/vsa/storage_rekor.go 46.03% <100.00%> (+4.74%) ⬆️
internal/evaluator/filters.go 80.70% <87.50%> (-0.11%) ⬇️
internal/validate/vsa/file_retriever.go 93.10% <93.10%> (ø)
internal/applicationsnapshot/attestation.go 86.48% <62.50%> (-6.85%) ⬇️
internal/evaluator/rule_discovery.go 88.99% <88.99%> (ø)
internal/validate/vsa/types.go 91.46% <91.46%> (ø)
internal/validate/vsa/rekor_retriever.go 45.22% <56.63%> (+2.33%) ⬆️
internal/utils/safe_arithmetic.go 0.00% <0.00%> (ø)
... and 4 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joejstuart
Copy link
Contributor Author

This is a larger PR, but the commits are broken out pretty well to help review.

@joejstuart joejstuart marked this pull request as draft September 10, 2025 17:31
@joejstuart
Copy link
Contributor Author

Setting this to draft to merge this first - #2933

@joejstuart joejstuart force-pushed the vsa-commit-split branch 2 times, most recently from a81b210 to 82b6578 Compare September 11, 2025 22:02
}

// Safe capacity calculation with overflow protection
capacity := componentCount * 2

Check failure

Code scanning / CodeQL

Size computation for allocation may overflow High

This operation, which is used in an
allocation
, involves a
potentially large value
and might overflow.
This operation, which is used in an
allocation
, involves a
potentially large value
and might overflow.
totalRules = math.MaxInt / 4
} else {
// Safe to add - check for overflow
totalRules = successes + violations + warnings

Check failure

Code scanning / CodeQL

Size computation for allocation may overflow High

This operation, which is used in an
allocation
, involves a
potentially large value
and might overflow.
totalRules = math.MaxInt / 4
} else {
// Safe to add - check for overflow
totalRules = successes + violations + warnings

Check failure

Code scanning / CodeQL

Size computation for allocation may overflow High

This operation, which is used in an
allocation
, involves a
potentially large value
and might overflow.
"github.com/stretchr/testify/require"
)

func TestFileVSADataRetriever(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test functions in this file covered several functions from different files. These tests are grounped by functionality which is all VSA data retrieval related tests.

Summary of Files Covered:
internal/validate/vsa/file_retriever.go - File-based VSA data retrieval
internal/validate/vsa/rekor_retriever.go - Rekor-based VSA data retrieval
internal/validate/vsa/types.go - Type definitions and data structures
internal/validate/vsa/validation.go - Interface definitions

  1. TestFileVSADataRetriever
    File: internal/validate/vsa/file_retriever.go
    Functions tested:

NewFileVSADataRetriever(fs afero.Fs, vsaPath string) *FileVSADataRetriever
RetrieveVSA(ctx context.Context, imageDigest string) (*ssldsse.Envelope, error) (method on FileVSADataRetriever)

  1. TestRekorVSADataRetriever
    File: internal/validate/vsa/rekor_retriever.go
    Functions tested:

NewRekorVSADataRetriever(opts RetrievalOptions, imageDigest string) (*RekorVSADataRetriever, error)

  1. TestVSADataRetrieverInterface
    File: internal/validate/vsa/validation.go
    Interface tested:

VSADataRetriever interface
Ensures both FileVSADataRetriever and RekorVSADataRetriever implement this interface

  1. TestRetrievalOptions
    File: internal/validate/vsa/types.go
    Functions tested:

DefaultRetrievalOptions() RetrievalOptions
Tests the RetrievalOptions struct

  1. TestDSSEEnvelope
    File: internal/validate/vsa/types.go
    Types tested:

DSSEEnvelope struct
Tests JSON marshaling/unmarshaling of DSSE envelope structure

  1. TestSignature
    File: internal/validate/vsa/types.go
    Types tested:

Signature struct
Tests JSON marshaling/unmarshaling of signature structure

  1. TestDualEntryPair
    File: internal/validate/vsa/types.go
    Types tested:

DualEntryPair struct (lines 58-62)
Tests the structure used by Rekor for handling paired entries

}
}

func (m *MockPolicyResolver) GetRequiredRules(ctx context.Context, imageDigest string) (map[string]bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validator_test.go file comprehensively tests the VSA Rule Validation System

Summary of Files Covered:
internal/validate/vsa/types.go - Main VSA rule validation implementation
internal/validate/vsa/validation.go - Policy resolver adapter implementation
internal/validate/vsa/validator_test.go - Test file itself (contains mock implementations and test helpers)

  1. TestEvaluatorPolicyResolver
    File: internal/validate/vsa/validation.go
    Functions tested:

NewPolicyResolver(policyResolver interface{}, availableRules evaluator.PolicyRules) PolicyResolver
GetRequiredRules(ctx context.Context, imageDigest string) (map[string]bool, error) (method on policyResolverAdapter)

  1. TestVSARuleValidatorImpl_ValidateVSARules (Main comprehensive test)
    File: internal/validate/vsa/types.go
    Functions tested:

NewVSARuleValidator() VSARuleValidator
ValidateVSARules(ctx context.Context, vsaRecords []VSARecord, policyResolver PolicyResolver, imageDigest string) (*ValidationResult, error)
extractRuleResultsFromVSA(record VSARecord) (map[string]RuleResult, error)
convertEvaluatorResultToRuleResult(result map[string]interface{}, status, componentImage string) RuleResult

  1. TestVSARuleValidatorImpl_ExtractRuleID
    File: internal/validate/vsa/types.go
    Functions tested:

extractRuleID(result evaluator.Result) string

  1. TestVSARuleValidatorImpl_ExtractPackageFromRuleID
    File: internal/validate/vsa/types.go
    Functions tested:

extractPackageFromRuleID(ruleID string) string

Mock/Test Helper Functions:

  1. NewMockPolicyResolver (Test helper)
    File: internal/validate/vsa/validator_test.go
    Purpose: Creates mock policy resolver for testing

  2. MockPolicyResolver.GetRequiredRules (Test helper)
    File: internal/validate/vsa/validator_test.go
    Purpose: Mock implementation of PolicyResolver interface

  3. MockExistingPolicyResolver (Test helper)
    File: internal/validate/vsa/validator_test.go
    Purpose: Mock implementation of the existing evaluator.PolicyResolver interface
    Helper Functions for Test Data:

  4. createMockVSARecord (Test helper)
    File: internal/validate/vsa/validator_test.go
    Purpose: Creates mock VSA records for testing

  5. createRealisticVSARecord (Test helper)
    File: internal/validate/vsa/validator_test.go
    Purpose: Creates realistic VSA records with real-world data

  6. createRealisticVSARecordWithWarnings (Test helper)
    File: internal/validate/vsa/validator_test.go
    Purpose: Creates VSA records with warning scenarios

- Add VSARuleValidator interface and implementation
- Add ValidationResult, MissingRule, FailingRule types
- Add PolicyResolver interface for rule resolution
- Add comprehensive validation tests with realistic scenarios
- Establish foundation for VSA validation functionality
- Add FileVSADataRetriever for reading VSA from files
- Add RekorVSADataRetriever for fetching VSA from Rekor
- Add VSADataRetriever interface and implementations
- Add comprehensive tests for data retrieval
- Add rule discovery functionality for policy resolution
- Enhance conftest evaluator with VSA-specific metadata
- Improve filtering capabilities for VSA validation
- Add comprehensive tests for rule discovery
- Enhance input processing for VSA data
- Add VSA-specific report handling
- Update report tests for VSA functionality
- Add 'ec validate vsa' command for VSA validation
- Support validation from files and Rekor
- Integrate with existing validate command structure
- Add comprehensive VSA validation documentation
- Update CLI navigation for new command
- Update integration tests for VSA functionality
- Update go.mod and go.sum with VSA dependencies
- Update development configuration files
- Add comprehensive VSA data types and structures
- Define interfaces for VSA validation and retrieval
- Establish type safety for VSA operations
- Add comprehensive tests for VSA data retrieval
- Test file and Rekor retrieval scenarios
- Add mock implementations for testing
- Refactor VSA code organization
- Improve error handling and validation
- Clean up implementation details
- use retry logic with Rekor
- default to 4 workers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants