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

Connect: Verify the leaf cert to determine if its ready. #4540

Merged
merged 2 commits into from
Sep 7, 2018

Conversation

mkeeler
Copy link
Member

@mkeeler mkeeler commented Aug 17, 2018

This improves the checking so that if a certificate were to expire or the roots changed then we will go into a non-ready state.

This also caches the parsed x509 certificate in the tls certificate so that future checks shouldn't need to parse anything but rather just validate against the roots and cert expiration.

@mkeeler mkeeler requested review from banks and kyhavlov August 17, 2018 20:07
Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

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

Looks good!

Potential racey update there but I could be wrong about scope somehow.

connect/tls.go Outdated

if cfg.leaf.Leaf == nil {
if cert, err := x509.ParseCertificate(cfg.leaf.Certificate[0]); err == nil {
cfg.leaf.Leaf = cert
Copy link
Member

Choose a reason for hiding this comment

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

This is modifying state while only holding an RLock. Is that dangerous?

Copy link
Member

Choose a reason for hiding this comment

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

Should we update the comment on ReadyWait to be strong than "which we assume are valid"? Happy to leave it as only triggering on the first ready state change rather than being a more elaborate watch mechanism.

@mkeeler
Copy link
Member Author

mkeeler commented Aug 20, 2018

I still need one more thing for this PR. Ignore reviewing for the time being.

@mkeeler mkeeler force-pushed the connect-tls-verify-ready branch 3 times, most recently from 69d3e0b to 7e39155 Compare August 20, 2018 18:06
This improves the checking so that if a certificate were to expire or the roots changed then we will go into a non-ready state.

This parses the x509 certificates from the TLS certificate when the leaf is set and whenever the leaf is set or the roots are set will perform x509 verification to ensure that the given roots can verify the leaf cert. Only when a valid roots/leaf cert pair are loaded will the notify function be called and the readyCh be closed.

The Ready function will now also perform x509 verification of the certificate which will in addition to verifying the signatures also verify the cert has not expired. In this way repeated calls to Ready will return a non-Ready state when a certificate expires.
@mkeeler
Copy link
Member Author

mkeeler commented Aug 20, 2018

@banks I made a bunch of changes. The latest implementation only writes to the TLS certs when using a write lock (SetLeaf) or in the constructor newDynamicTLSConfig.

I had experimented with the idea of needing to have x509 verification of the leaf cert succeed before closing the readyCh. The one case that doesn't work so well for is where the certificate is valid from a certain point in the future (either it was created that way or due to clock skew on the node where it is being used). We could spawn a go routine to periodically check for validity before closing the readyCh but then we would need more chans for communication with it in addition to the readyCh. I started implementing this but it was getting ugly and seemed unnecessary. So instead I left ReadyWait semantics the same. Once all the data is installed (whether valid or not) that chan will be unblocked.

Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

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

Looks good. Minor nit about logging the swallowed error but it doesn't matter much so approving.

connect/tls.go Show resolved Hide resolved
Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

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

👍

@mkeeler mkeeler merged commit 89ba649 into master Sep 7, 2018
@mkeeler mkeeler deleted the connect-tls-verify-ready branch October 24, 2018 13:48
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

2 participants