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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug where an error would send duplicate results. #1797

Merged
merged 1 commit into from Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/cosign/kubernetes/webhook/validator.go
Expand Up @@ -267,9 +267,9 @@ func validatePolicies(ctx context.Context, ref name.Reference, policies map[stri
logging.FromContext(ctx).Infof("Validating CIP level policy for %s", cipName)
policyJSON, err := json.Marshal(result.policyResult)
if err != nil {
results <- result
result.errors = append(result.errors, err)
} else {
logging.FromContext(ctx).Infof("Validating CIP level policy against %s", string(policyJSON))
logging.FromContext(ctx).Debugf("Validating CIP level policy against %s", string(policyJSON))
err = policy.EvaluatePolicyAgainstJSON(ctx, "ClusterImagePolicy", cip.Policy.Type, cip.Policy.Data, policyJSON)
if err != nil {
result.errors = append(result.errors, err)
Expand Down
48 changes: 48 additions & 0 deletions pkg/cosign/kubernetes/webhook/validator_test.go
Expand Up @@ -341,6 +341,54 @@ UoJou2P8sbDxpLiE/v3yLw1/jyOrCPWYHWFXnyyeGlkgSVefG54tNoK7Uw==
return errs
}(),
cvs: fail,
}, {
name: "simple, authority keyless checks out, good fulcio, bad cip policy",
ps: &corev1.PodSpec{
InitContainers: []corev1.Container{{
Name: "setup-stuff",
Image: digest.String(),
}},
Containers: []corev1.Container{{
Name: "user-container",
Image: digest.String(),
}},
},
customContext: config.ToContext(context.Background(),
&config.Config{
ImagePolicyConfig: &config.ImagePolicyConfig{
Policies: map[string]webhookcip.ClusterImagePolicy{
"cluster-image-policy-keyless": {
Images: []v1alpha1.ImagePattern{{
Regex: ".*",
}},
Authorities: []webhookcip.Authority{
{
Keyless: &webhookcip.KeylessRef{
URL: fulcioURL,
},
},
},
Policy: &webhookcip.AttestationPolicy{
Name: "invalid json policy",
Type: "cue",
Data: `{"wontgo}`,
},
},
},
},
},
),
want: func() *apis.FieldError {
var errs *apis.FieldError
fe := apis.ErrGeneric("failed policy: cluster-image-policy-keyless", "image").ViaFieldIndex("initContainers", 0)
fe.Details = fmt.Sprintf("%s failed evaluating cue policy for ClusterImagePolicy : string literal not terminated", digest.String())
errs = errs.Also(fe)
fe2 := apis.ErrGeneric("failed policy: cluster-image-policy-keyless", "image").ViaFieldIndex("containers", 0)
fe2.Details = fmt.Sprintf("%s failed evaluating cue policy for ClusterImagePolicy : string literal not terminated", digest.String())
errs = errs.Also(fe2)
return errs
}(),
cvs: pass,
}, {
name: "simple, no error, authority keyless, good fulcio",
ps: &corev1.PodSpec{
Expand Down