Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Have the policy-tester library check policy result. #809

Merged
merged 1 commit into from
May 31, 2023

Conversation

mattmoor
Copy link
Member

馃悰 The policy tester library blindly checked the errors, but with multiple authorities we might have errors, but still successfully evaluated the policy.

Here is the comment from the ~equivalent call to ValidatePolicy( from validator.go for comparison:

			switch {
			// Return AuthorityMatches before errors, since even if there
			// are errors, if there are 0 or more authorities that match,
			// it will pass the Policy. Of course, a CIP level policy can
			// override this behaviour, but that has been checked above and
			// if it failed, it will nil out the policyResult.
			case result.policyResult != nil:
				policyResults[result.name] = result.policyResult
			case len(result.errors) > 0:
				ret[result.name] = append(ret[result.name], result.errors...)
			default:
				ret[result.name] = append(ret[result.name], fmt.Errorf("failed to process policy: %s", result.name))
			}

... with this I was able to successfully run the policy tester using a policy that had a separate authority for SLSA v0.2 and v1 predicate types without it failing.

/kind bug

Release Note

The policy tester library now properly treats authorities as an OR instead of erroring if any of them surface errors.

Documentation

馃悰 The policy tester library blindly checked the errors, but with multiple authorities we might have errors, but still successfully evaluated the policy.

Here is the comment from the ~equivalent call to `ValidatePolicy(` from `validator.go` for comparison:

```go
			switch {
			// Return AuthorityMatches before errors, since even if there
			// are errors, if there are 0 or more authorities that match,
			// it will pass the Policy. Of course, a CIP level policy can
			// override this behaviour, but that has been checked above and
			// if it failed, it will nil out the policyResult.
			case result.policyResult != nil:
				policyResults[result.name] = result.policyResult
			case len(result.errors) > 0:
				ret[result.name] = append(ret[result.name], result.errors...)
			default:
				ret[result.name] = append(ret[result.name], fmt.Errorf("failed to process policy: %s", result.name))
			}

```

... with this I was able to successfully run the policy tester using a policy that had a separate authority for SLSA `v0.2` and `v1` predicate types without it failing.

/kind bug

Signed-off-by: Matt Moore <mattmoor@chainguard.dev>
@codecov
Copy link

codecov bot commented May 30, 2023

Codecov Report

Merging #809 (b4622d1) into main (1b402ff) will increase coverage by 0.03%.
The diff coverage is 87.50%.

@@            Coverage Diff             @@
##             main     #809      +/-   ##
==========================================
+ Coverage   54.95%   54.98%   +0.03%     
==========================================
  Files          45       45              
  Lines        4786     4790       +4     
==========================================
+ Hits         2630     2634       +4     
  Misses       1946     1946              
  Partials      210      210              
Impacted Files Coverage 螖
pkg/policy/verifier.go 66.32% <87.50%> (+1.43%) 猬嗭笍

@mattmoor
Copy link
Member Author

cc @vaikas @hectorj2f

@vaikas vaikas merged commit 4f2910d into sigstore:main May 31, 2023
76 checks passed
@mattmoor mattmoor deleted the check-policy-result branch May 31, 2023 00:36
@github-actions github-actions bot added this to the v1 milestone May 31, 2023
mattmoor added a commit to mattmoor/terraform-provider-cosign that referenced this pull request May 31, 2023
ref: sigstore/policy-controller#809

Signed-off-by: Matt Moore <mattmoor@chainguard.dev>
mattmoor added a commit to chainguard-dev/terraform-provider-cosign that referenced this pull request May 31, 2023
ref: sigstore/policy-controller#809

Signed-off-by: Matt Moore <mattmoor@chainguard.dev>
@hectorj2f
Copy link
Collaborator

Thanks @mattmoor

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.

None yet

3 participants