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

Consolidate certificate expiry logic #2504

Merged
merged 26 commits into from
Dec 7, 2022
Merged

Conversation

mtrmac
Copy link
Contributor

@mtrmac mtrmac commented Dec 2, 2022

Summary

This is a subset of #2482 as requested in #2482 (comment) (a bit larger than that):

  • User-observable: verify RFC 3161 timestamps, and Rekor data, first, before processing certificates. Conceptually we need to do that because certificate processing requires a timestamp (although that’s not yet what this PR finishes doing). This can affect user-observable error messages, which can now complain about untrusted signed Rekor data instead of untrusted signed certificates.
  • Behavior change: If there is a certificate, always verify it against some timestamp (in particular, the current time, if there is neither a RFC 3161 timestamp nor any Rekor data. (This is more than was asked — I included it because the current behavior is such a surprise for callers, and because always verifying actually makes the code simpler. I can split that into some future PR, and add an explicit “are we dealing with Rekor” condition instead, to preserve the current behavior.)
  • Code consolidation: verifyInternal now has one place (although not yet the correct place) to do certificate expiry checks, instead of that happening in VerifyRFC3161Timestamp

See #2482 for previous discussion, and the general rationale of only using data after it is verified (which is not what this PR really does, but it’s a prerequisite).

Release Note

cosign verify-blob --cert-chain … --certificate … --skip-tlog-verify now requires the leaf certificate to not be expired.

Documentation

@codecov-commenter
Copy link

codecov-commenter commented Dec 2, 2022

Codecov Report

Merging #2504 (22e5a0e) into main (7813599) will decrease coverage by 0.01%.
The diff coverage is 51.42%.

@@            Coverage Diff             @@
##             main    #2504      +/-   ##
==========================================
- Coverage   30.16%   30.14%   -0.02%     
==========================================
  Files         139      139              
  Lines        8583     8595      +12     
==========================================
+ Hits         2589     2591       +2     
- Misses       5621     5629       +8     
- Partials      373      375       +2     
Impacted Files Coverage Δ
pkg/cosign/verify.go 41.31% <51.42%> (-0.35%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@haydentherapper haydentherapper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for splitting this up! This looks great.

pkg/cosign/verify.go Outdated Show resolved Hide resolved
cmd/cosign/cli/verify/verify_blob_test.go Outdated Show resolved Hide resolved
pkg/cosign/verify.go Outdated Show resolved Hide resolved
pkg/cosign/verify.go Show resolved Hide resolved
pkg/cosign/verify.go Outdated Show resolved Hide resolved
pkg/cosign/verify.go Outdated Show resolved Hide resolved
asraa
asraa previously approved these changes Dec 2, 2022
cmd/cosign/cli/verify/verify.go Outdated Show resolved Hide resolved
@haydentherapper
Copy link
Contributor

@cpanato Any idea about why the windows test is failing? Not sure how best to debug this.

pkg/cosign/verify.go Outdated Show resolved Hide resolved
Copy link
Contributor

@asraa asraa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awaiting the rebase, but lgtm! don't block on that comment, since it's fairly minor

mtrmac and others added 14 commits December 6, 2022 23:04
Should not change behavior now, but this should make it easier
to move code around.

Signed-off-by: Miloslav Trmač <[email protected]>
Let's decrease the risk of a caller not noticing an error,
and make it a bit shorter to read and more clear that they are
all, in fact, error paths.

This may change the return value in some cases.

Signed-off-by: Miloslav Trmač <[email protected]>
Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
This will allow us to move the certificate expiry responsibility
to the caller.

Should not change behavior, assuming timestamp.ParseResponse can't
fail for an alraedy verified response.

Signed-off-by: Miloslav Trmač <[email protected]>
... from VerifyRFC3161Timestamp, which has no reason to care,
to verifyInternal.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Don't repeat the conditions, and make the flow a bit clearer.

Should not change behavior, unless there are multiple
reasons to reject the signature.

Signed-off-by: Miloslav Trmač <[email protected]>
We will use them to decouple the bundle handling from certificate
expiry verification.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Should not change behavior, just to prepare a further move

Signed-off-by: Miloslav Trmač <[email protected]>
Another small step. Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Now, we always validate certificate expiration against _some_ time.

Even if we don't interact with Rekor bundles at all, we validate it against
the current time.

Signed-off-by: Miloslav Trmač <[email protected]>
Consolidate all the expiry checks into one place.

Should not change behavior, unless there are multiple
reasons to reject the signature.

Signed-off-by: Miloslav Trmač <[email protected]>
Do them before looking at the certificate at all; we need
to do this first to obtain signature creation times.

This may affect user-visible error messages; adjust a test.

Signed-off-by: Miloslav Trmač <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
Signed-off-by: Hayden Blauzvern <[email protected]>
@asraa asraa enabled auto-merge (squash) December 7, 2022 20:13
@asraa asraa merged commit 09f023f into sigstore:main Dec 7, 2022
@github-actions github-actions bot added this to the v1.14.0 milestone Dec 7, 2022
@mtrmac mtrmac deleted the processing-order-1 branch December 7, 2022 21:04
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.

4 participants