-
Couldn't load subscription status.
- Fork 7.3k
Update verification results printing #9937
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f48e6b5
verify cert extensions function should return filtered result list
malancas b5788f2
wrap sigstore and cert ext verification into a single function
malancas 3e6861e
clean up
malancas 4671b8d
update test
malancas ff8844a
update test
malancas 5601149
naming
malancas 19afe45
update test with new test bundle
malancas 4d277df
add more testing testing fixtures
malancas 7a271b0
undo change
malancas 28565dc
remove unused test file
malancas 2d41225
pr feedback
malancas 27a268c
Merge branch 'trunk' into verify-result-processing
malancas fed3c81
Update pkg/cmd/attestation/verify/attestation_integration_test.go
malancas 0fd09eb
pr feedback
malancas f92d703
pr feedback
malancas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
pkg/cmd/attestation/verify/attestation_integration_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| //go:build integration | ||
|
|
||
| package verify | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/cli/cli/v2/pkg/cmd/attestation/api" | ||
| "github.com/cli/cli/v2/pkg/cmd/attestation/artifact" | ||
| "github.com/cli/cli/v2/pkg/cmd/attestation/io" | ||
| "github.com/cli/cli/v2/pkg/cmd/attestation/test" | ||
| "github.com/cli/cli/v2/pkg/cmd/attestation/verification" | ||
| "github.com/sigstore/sigstore-go/pkg/fulcio/certificate" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func getAttestationsFor(t *testing.T, bundlePath string) []*api.Attestation { | ||
| t.Helper() | ||
|
|
||
| attestations, err := verification.GetLocalAttestations(bundlePath) | ||
| require.NoError(t, err) | ||
|
|
||
| return attestations | ||
| } | ||
|
|
||
| func TestVerifyAttestations(t *testing.T) { | ||
| sgVerifier := verification.NewLiveSigstoreVerifier(verification.SigstoreConfig{ | ||
| Logger: io.NewTestHandler(), | ||
| }) | ||
|
|
||
| certSummary := certificate.Summary{} | ||
| certSummary.SourceRepositoryOwnerURI = "https://github.com/sigstore" | ||
| certSummary.SourceRepositoryURI = "https://github.com/sigstore/sigstore-js" | ||
| certSummary.Issuer = verification.GitHubOIDCIssuer | ||
|
|
||
| ec := verification.EnforcementCriteria{ | ||
| Certificate: certSummary, | ||
| PredicateType: verification.SLSAPredicateV1, | ||
| SANRegex: "^https://github.com/sigstore/", | ||
| } | ||
| require.NoError(t, ec.Valid()) | ||
|
|
||
| artifactPath := test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0.tgz") | ||
| a, err := artifact.NewDigestedArtifact(nil, artifactPath, "sha512") | ||
| require.NoError(t, err) | ||
|
|
||
| t.Run("all attestations pass verification", func(t *testing.T) { | ||
| attestations := getAttestationsFor(t, "../test/data/sigstore-js-2.1.0_with_2_bundles.jsonl") | ||
| require.Len(t, attestations, 2) | ||
| results, errMsg, err := verifyAttestations(*a, attestations, sgVerifier, ec) | ||
| require.NoError(t, err) | ||
| require.Zero(t, errMsg) | ||
| require.Len(t, results, 2) | ||
| }) | ||
|
|
||
| t.Run("passes verification with 2/3 attestations passing Sigstore verification", func(t *testing.T) { | ||
| invalidBundle := getAttestationsFor(t, "../test/data/sigstore-js-2.1.0-bundle-v0.1.json") | ||
| attestations := getAttestationsFor(t, "../test/data/sigstore-js-2.1.0_with_2_bundles.jsonl") | ||
| attestations = append(attestations, invalidBundle[0]) | ||
| require.Len(t, attestations, 3) | ||
|
|
||
| results, errMsg, err := verifyAttestations(*a, attestations, sgVerifier, ec) | ||
| require.NoError(t, err) | ||
| require.Zero(t, errMsg) | ||
| require.Len(t, results, 2) | ||
| }) | ||
|
|
||
| t.Run("fails verification when Sigstore verification fails", func(t *testing.T) { | ||
| invalidBundle := getAttestationsFor(t, "../test/data/sigstore-js-2.1.0-bundle-v0.1.json") | ||
| invalidBundle2 := getAttestationsFor(t, "../test/data/sigstore-js-2.1.0-bundle-v0.1.json") | ||
| attestations := append(invalidBundle, invalidBundle2...) | ||
| require.Len(t, attestations, 2) | ||
|
|
||
| results, errMsg, err := verifyAttestations(*a, attestations, sgVerifier, ec) | ||
| require.Error(t, err) | ||
| require.Contains(t, errMsg, "✗ Sigstore verification failed") | ||
| require.Nil(t, results) | ||
| }) | ||
|
|
||
| t.Run("attestations fail to verify when cert extensions don't match enforcement criteria", func(t *testing.T) { | ||
| sgjAttestation := getAttestationsFor(t, "../test/data/sigstore-js-2.1.0_with_2_bundles.jsonl") | ||
| reusableWorkflowAttestations := getAttestationsFor(t, "../test/data/reusable-workflow-attestation.sigstore.json") | ||
| attestations := []*api.Attestation{sgjAttestation[0], reusableWorkflowAttestations[0], sgjAttestation[1]} | ||
| require.Len(t, attestations, 3) | ||
|
|
||
| rwfResult := verification.BuildMockResult(reusableWorkflowAttestations[0].Bundle, "", "https://github.com/malancas", "", verification.GitHubOIDCIssuer) | ||
| sgjResult := verification.BuildSigstoreJsMockResult(t) | ||
| mockResults := []*verification.AttestationProcessingResult{&sgjResult, &rwfResult, &sgjResult} | ||
| mockSgVerifier := verification.NewMockSigstoreVerifierWithMockResults(t, mockResults) | ||
|
|
||
| // we want to test that attestations that pass Sigstore verification but fail | ||
| // cert extension verification are filtered out properly in the second step | ||
| // in verifyAttestations. By using a mock Sigstore verifier, we can ensure | ||
| // that the call to verification.VerifyCertExtensions in verifyAttestations | ||
| // is filtering out attestations as expected | ||
| results, errMsg, err := verifyAttestations(*a, attestations, mockSgVerifier, ec) | ||
| require.NoError(t, err) | ||
| require.Zero(t, errMsg) | ||
| require.Len(t, results, 2) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ideally i'd like to check that the rwfResult is specifically the one being excluded. can we do an array comparison for |
||
| for _, result := range results { | ||
| require.NotEqual(t, result.Attestation.Bundle, reusableWorkflowAttestations[0].Bundle) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("fails verification when cert extension verification fails", func(t *testing.T) { | ||
| attestations := getAttestationsFor(t, "../test/data/sigstore-js-2.1.0_with_2_bundles.jsonl") | ||
| require.Len(t, attestations, 2) | ||
|
|
||
| expectedCriteria := ec | ||
| expectedCriteria.Certificate.SourceRepositoryOwnerURI = "https://github.com/wrong" | ||
|
|
||
| results, errMsg, err := verifyAttestations(*a, attestations, sgVerifier, expectedCriteria) | ||
| require.Error(t, err) | ||
| require.Contains(t, errMsg, "✗ Policy verification failed") | ||
| require.Nil(t, results) | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
yesterday we had a conversation where we realized it's not obvious WHY we verifyCertExtensions separately from the CertificateIdentity provided in sigstore-go (and frankly, maybe we should just upstream how we've done it here) and
after some mild effort,
we discovered it's so we can support case insensitivity around repo & owner names.
given that conversation let's add a wee comment to
func verifyCertExtensiosndenoting that - "this func exists so we can do case insensitive comparisons"