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

Add an OCSP responder to Vault's PKI plugin #16723

Merged
merged 15 commits into from Aug 22, 2022

Conversation

stevendpclark
Copy link
Contributor

Add an OCSP responder to Vault's PKI plugin. This is a simplistic responder that at the moment will only accept a single query at a time with no support for any extensions defined within RFC 6960, mainly due to the limitations in Go's OCSP libraries.

An end-user will be able to disable the responder through the existing config/crl endpoint with the newly added key ocsp_disable. The responder will be enabled by default, if the key is set to true to disable the responder, an OCSP response of Unauthorized will be returned to the caller.

Copy link
Contributor

@cipherboy cipherboy left a comment

Choose a reason for hiding this comment

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

Some thoughts to get discussions started :-)

Overall, I think it is well written and tested. Just some behavior discussions below that I wonder if we want to change?

builtin/logical/pki/cert_util.go Outdated Show resolved Hide resolved
builtin/logical/pki/crl_test.go Show resolved Hide resolved
builtin/logical/pki/storage.go Outdated Show resolved Hide resolved
builtin/logical/pki/storage.go Outdated Show resolved Hide resolved
builtin/logical/pki/storage.go Outdated Show resolved Hide resolved
http/logical.go Outdated Show resolved Hide resolved
website/content/api-docs/secret/pki.mdx Show resolved Hide resolved
builtin/logical/pki/test_helpers.go Show resolved Hide resolved
builtin/logical/pki/path_config_crl.go Show resolved Hide resolved

info.ocspStatus = ocsp.Revoked
info.revocationTimeUTC = &revEntry.RevocationTimeUTC
info.issuerID = revEntry.CertificateIssuer // This might be empty if the CRL hasn't been rebuilt
Copy link
Contributor

Choose a reason for hiding this comment

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

So I'm kinda of two minds here.

If the CRL is never rebuilt, we're stuck always incurring the iteration over all issuers down in lookupOcspIssuer. This increases request time, and isn't strictly correct (w.r.t. if the issuer hash/... doesn't match as expected).

However, if the CRL is eventually rebuilt, we'd be doing extra work for potentially no reason.

My 2c., but I'd kinda prefer that we refactor the CRL rebuilding logic so that it can be reused here: https://github.com/hashicorp/vault/blob/main/builtin/logical/pki/crl_util.go#L523-L567

That way, if there is no issuer entry, we can help future lookups of the same cert and avoid recomputing the value each time (when CRL isn't used).

Then, down below, in the lookupIsssuerIds, we only need to compare the expected issuer's hashes against the actual issuer ID's backing issuer's hashes (since they're correct up to isomorphism) and if they mismatch, we can give a proper error (malformed request probably).

The reason for this is, IMO, I'd love to see a standalone (CRL disabled), performant OCSP server. If we require the CRL to be rebuilt to pick up new issuer revocations, I think that's less than ideal.

Alternatively (or additionally) we could also move issuer association to revocation time if we wanted?

Copy link
Contributor

@kitography kitography left a comment

Choose a reason for hiding this comment

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

I'm going to take another look tomorrow, but this hard parts here (caching/locking/figuring out how to pipe in the OCSP requests), are looking really good. I do have some nits, and would love to fool around with this a bit more before approving.

changelog/16723.txt Outdated Show resolved Hide resolved
website/content/api-docs/secret/pki.mdx Outdated Show resolved Hide resolved
builtin/logical/pki/storage.go Show resolved Hide resolved
builtin/logical/pki/path_config_crl.go Show resolved Hide resolved
@stevendpclark
Copy link
Contributor Author

stevendpclark commented Aug 19, 2022

Updated all feedback, I did not change the atomic boolean/setOcspStatus stuff as there is another PR that will update that. Also this has been rebased on top of the latest main branch.

@cipherboy @kitography this should be ready for re-review!

Copy link
Contributor

@cipherboy cipherboy left a comment

Choose a reason for hiding this comment

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

Finally got around to looking through the tests, I think this makes sense and looks good!

I think there's one interesting inline question about forwarding, but the rest are nits. :-)

builtin/logical/pki/cert_util.go Outdated Show resolved Hide resolved
builtin/logical/pki/ocsp.go Show resolved Hide resolved
builtin/logical/pki/ocsp_test.go Show resolved Hide resolved
builtin/logical/pki/ocsp_test.go Show resolved Hide resolved
website/content/api-docs/secret/pki.mdx Outdated Show resolved Hide resolved
Copy link
Contributor

@kitography kitography left a comment

Choose a reason for hiding this comment

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

I am well into nits, these tests are super cool.

builtin/logical/pki/ocsp.go Outdated Show resolved Hide resolved
builtin/logical/pki/ocsp.go Outdated Show resolved Hide resolved
builtin/logical/pki/ocsp.go Outdated Show resolved Hide resolved
builtin/logical/pki/ocsp.go Outdated Show resolved Hide resolved

if matches {
if !issuer.Usage.HasUsage(OCSPSigningUsage) {
// We found the correct issuer, but it's not allowed to sign the
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it not possible for there to be more than one matching issuer here? (Same name, key, different expiry/certificate usages?)

Copy link
Contributor

@cipherboy cipherboy Aug 22, 2022

Choose a reason for hiding this comment

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

Hmm, this is a good point. I'd probably suggest addressing it in a follow-up though, so as not to block too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup noted, I'll address this feedback in a different PR, but great catch @kitography!

builtin/logical/pki/ocsp_test.go Outdated Show resolved Hide resolved
 - Leverage ocsp response constant
 - Remove duplicate errors regarding unknown issuers
@@ -0,0 +1,4 @@
```release-note:feature
Copy link
Contributor

Choose a reason for hiding this comment

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

👋🏻 This changelog entry isn't correctly formatted for new features.

**OCSP Responder**: <text>

You can check out the 1.11 changelog for a reference, and there's also a wiki page about this. Could you please update this file on main so that it formats correctly in the final version of the 1.12 changelog?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants