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

Attestations + policy in cip. #1772

Merged
merged 22 commits into from Apr 23, 2022
Merged

Conversation

vaikas
Copy link
Contributor

@vaikas vaikas commented Apr 18, 2022

Summary

  • Start of adding support for parity with verify-attestations in cosigned webhook
  • Add support for cue in validating a CIP after signatures / attestations have been verified
  • Fix a bug where CTLog was not plumbed through for custom verification
  • Add 'name' field to authorities (gets defaulted to authority-) for making it easier to write CIP level policies

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

 * Start of adding support for parity with verify-attestations in cosigned webhook
 * Add support for cue in validating a CIP _after_ signatures / attestations have been verified
 * Fix a bug where CTLog was not plumbed through for custom verification
 * Add 'name' field to authorities (gets defaulted to authority-<index>) for making it easier to write CIP level policies

@vaikas vaikas force-pushed the attestations-in-cip branch 2 times, most recently from e0e7287 to e6f3573 Compare April 18, 2022 21:52
@codecov-commenter
Copy link

codecov-commenter commented Apr 18, 2022

Codecov Report

Merging #1772 (1541a0c) into main (8368bad) will increase coverage by 0.53%.
The diff coverage is 56.21%.

@@            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     
Impacted Files Coverage Δ
...apis/cosigned/v1alpha1/clusterimagepolicy_types.go 0.00% <0.00%> (ø)
...kg/apis/cosigned/v1alpha1/zz_generated.deepcopy.go 0.00% <0.00%> (ø)
pkg/policy/eval.go 51.85% <51.85%> (ø)
pkg/cosign/kubernetes/webhook/validation.go 74.00% <56.00%> (-6.77%) ⬇️
pkg/cosign/kubernetes/webhook/validator.go 74.44% <63.18%> (-8.13%) ⬇️
pkg/apis/config/image_policies.go 69.38% <100.00%> (ø)
...s/cosigned/v1alpha1/clusterimagepolicy_defaults.go 100.00% <100.00%> (+100.00%) ⬆️
...cosigned/v1alpha1/clusterimagepolicy_validation.go 94.11% <100.00%> (+1.55%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8368bad...1541a0c. Read the comment docs.

@vaikas vaikas changed the title [WIP] Attestations + policy in cip. Attestations + policy in cip. Apr 19, 2022
@vaikas vaikas changed the title Attestations + policy in cip. [WIP] Attestations + policy in cip. Apr 19, 2022
keylessAttestationsErr: "error"
keylessAttestationsErr: "Did not get both keyless attestations"
keylessAttestationsErr: 1
keylessAttestationsErrMsg: "Did not get both keyless attestations"
Copy link
Contributor Author

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.

Copy link
Member

@mattmoor mattmoor left a 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 🙏

@@ -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>
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

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?

Comment on lines +155 to +157
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" {
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

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

pkg/policy/eval_test.go Outdated Show resolved Hide resolved
pkg/cosign/kubernetes/webhook/validator.go Outdated Show resolved Hide resolved
vaikas and others added 17 commits April 22, 2022 16:42
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>
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>
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
@vaikas vaikas changed the title [WIP] Attestations + policy in cip. Attestations + policy in cip. Apr 23, 2022
url: http://rekor.rekor-system.svc
policy:
type: cue
data: |
Copy link
Contributor

@hectorj2f hectorj2f Apr 23, 2022

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)
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

@hectorj2f hectorj2f left a 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.

@dlorenc dlorenc merged commit e1469ba into sigstore:main Apr 23, 2022
@github-actions github-actions bot added this to the v1.8.0 milestone Apr 23, 2022
@vaikas vaikas deleted the attestations-in-cip branch April 23, 2022 16:11
mlieberman85 pushed a commit to mlieberman85/cosign that referenced this pull request May 6, 2022
* 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>
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

5 participants