-
Notifications
You must be signed in to change notification settings - Fork 547
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
Attestations + policy in cip. #1772
Conversation
e0e7287
to
e6f3573
Compare
Codecov Report
@@ Coverage Diff @@
## main #1772 +/- ##
==========================================
+ Coverage 31.45% 31.98% +0.53%
==========================================
Files 144 145 +1
Lines 8896 9161 +265
==========================================
+ Hits 2798 2930 +132
- Misses 5761 5888 +127
- Partials 337 343 +6
Continue to review full report at Codecov.
|
a959510
to
3290b2e
Compare
keylessAttestationsErr: "error" | ||
keylessAttestationsErr: "Did not get both keyless attestations" | ||
keylessAttestationsErr: 1 | ||
keylessAttestationsErrMsg: "Did not get both keyless attestations" |
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.
Haha, this was my super hack to raise an error because I don't understand enough of cue yet :) So, we only execute this if if there's a failure and because there's a mismatch the policy will fail. So, all of these 'branches' really should be:
if len(...) < expected {
raiseEvaluationError
}
But, I don't know how to do the raiseEvaluationError, so I just added a statement that will result in an error.
2f9cf6f
to
8610c0d
Compare
12cd3d1
to
654f9fe
Compare
22086bb
to
ac9c492
Compare
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.
Thanks for all the tests and detailed comments 🙏
config/300-clusterimagepolicy.yaml
Outdated
@@ -99,6 +129,9 @@ spec: | |||
type: string | |||
url: | |||
type: string | |||
name: | |||
description: Name is the name for this authority. Used by the CIP Policy validator to be able to reference matching signature or attestation verifications. If not specified, the name will be attestation-<index in array> |
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.
attestation-%d
? Why not authority-%d
?
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 failed to update comment, I originally had it as attestation, and realized it was not good so I changed it to authority-%d, but forgot to update the comment.
func (spec *ClusterImagePolicySpec) SetDefaults(ctx context.Context) { | ||
for i, authority := range spec.Authorities { | ||
if authority.Name == "" { | ||
spec.Authorities[i].Name = fmt.Sprintf("authority-%d", i) |
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.
Same question... attestation
seems weird.
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.
lol, I originally had it as attestation, thought it seemed wierd, so changed it to authority-%d like here, but it's correct here? Or how do you mean? Above, yes I had neglected to update the comment, but the code is right here, no?
if a.PredicateType == "" { | ||
errs = errs.Also(apis.ErrMissingField("predicateType")) | ||
} else if a.PredicateType != "custom" && a.PredicateType != "slsaprovenance" && a.PredicateType != "spdx" && a.PredicateType != "link" && a.PredicateType != "vuln" { |
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.
seems like a good use of switch
?
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.
Doesn't cosign attest
support taking a full predicate type URL as well? Should we also allow full-blown URLs?
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'd rather not pollute this with the switch only because I'd rather use the TODO (refactor where the options come from and use that), also attest may take the uri but verify-attest does not. It looks for the short name in the map and pulls the URL from it. Again, I think that should be done as part of a follow on PR to refactor that code a bit to pull the map out of the cli/options so it can be reused here.
https://github.com/sigstore/cosign/blob/main/pkg/policy/attestation.go#L43
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
…policy. Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Start adding UT for ValidatePolicy. Getting ready for rebase. Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: hectorj2f <hectorf@vmware.com>
Add start of UT for ValidatePolicy. Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
CIP tests, will follow up with those. Add validation for attestations in CIPs Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
from the remoteopts instead consistently. Address PR feedback. Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
ac9c492
to
d402a02
Compare
url: http://rekor.rekor-system.svc | ||
policy: | ||
type: cue | ||
data: | |
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 can get this working in a separate PR, this PR one is big enough for now.
logging.FromContext(ctx).Infof("Evaluating attestation: %s", string(attestation)) | ||
cueCtx := cuecontext.New() | ||
v := cueCtx.CompileString(evaluator) | ||
return cuejson.Validate(attestation, v) |
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.
As discussed, we have to use a different set of functions here, as cuejson.Validate expects the CUE to be self-contained and applied as a schema to the JSON.
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.
We can improve this function in a different PR.
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.
LGTM from now, let's iterate over it.
* Modify types, introduce name defaults, codegen. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * Start refactoring and adding verify-attestation pieces. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * Sort of works e2e. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * E2E tests. Plumb rekor through for key-ful signing too. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * bad rebase. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * more bad rebases. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * regen keys. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * at the right place. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * forgot one rekor-url. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * Lint. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * remove these manually. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * Cleanups, do not unnecessarily eval empty json bytes for attestation policy. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * Add name to attestations for easier referencing from cip policy. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * Do not return empty PolicyResult when errors. Start adding UT for ValidatePolicy. Getting ready for rebase. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * fix: cue policy missing double-quotes Signed-off-by: hectorj2f <hectorf@vmware.com> * Add start of unit tests for policy validation stuff. Add start of UT for ValidatePolicy. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * Refactor policy eval code. Remove the attestation CIP from normal CIP tests, will follow up with those. Add validation for attestations in CIPs Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * loving yaml, thanks validation! Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * Starting to break apart the attestation tests. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * checkpoint Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * Remove unused keychain from the Validate* calls and use one from the remoteopts instead consistently. Address PR feedback. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> * lint. Signed-off-by: Ville Aikas <vaikas@chainguard.dev> Co-authored-by: hectorj2f <hectorf@vmware.com>
Summary
Missing:
I'd like to get this in and start experimenting so we can get real policies implemented and get
experience on what works.
Starts putting scaffolding in place for this:
#1769
Ticket Link
Fixes
Release Note