cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

Certs generation fails, complains about lifetime shorter than CA

Open neeral opened this issue 9 years ago • 6 comments

BUG REPORT I'm having an issue with certs generation that appeared when we started using v1.1-beta.20170921. It was working fine before in v1.0.4. We create the CA cert and then client and node certs. The generation of certs after the CA is failing because of the lifetime we're passing to it.

> cockroach cert create-ca --lifetime 240000h0m0s --certs-dir=/tmp/foo --ca-key=/tmp/ca.key
> cockroach cert create-client root  --lifetime 240000h0m0s --certs-dir=/tmp/foo --ca-key=/tmp/ca.key 
Error: failed to generate client certificate and key: error creating client certificate and key: CA lifetime is 239999.998105h, shorter than the requested 240000.000000h. Renew CA certificate, or rerun with --lifetime=239999h for a shorter duration.
Failed running "cert"

After some time it gives following, and CA lifetime keeps decreasing in error message.

> cockroach cert create-client root  --lifetime 240000h0m0s --certs-dir=/tmp/foo --ca-key=/tmp/ca.key 
Error: failed to generate client certificate and key: error creating client certificate and key: CA lifetime is 239999.951772h, shorter than the requested 240000.000000h. Renew CA certificate, or rerun with --lifetime=239999h for a shorter duration.
Failed running "cert"

It looks like the certs created after the CA must their lifetime extending beyond the CA's, because they are created a few seconds afterwards. Is this a new check that was added in 1.1? What is the best way to have all our certificates have a uniform expiration date?

When I create CA and client certs without specifying --lifetime, it doesn't complain. However, the client cert is given a 5 year lifetime and the CA is given a 10 year lifetime.

neeral avatar Sep 27 '17 01:09 neeral

It's recommended to keep the CA lifetime longer than the node and client lifetimes, allowing for CA rotation on a different schedule. We set them to 10 years (for CA) and 5 years for node/client explicitly for this purpose. The check verifies that the requested expiration date of the node/client certs do not exceed the CA lifetime. However, it's a very strict check, so creating the node/client certs even a second after the CA will trigger the error.

You have two options:

  • keep the CA lifetime considerably longer
  • request a "just slightly" shorter lifetime for the node/client certs so that the check won't fail

mberhault avatar Sep 27 '17 02:09 mberhault

Thanks for the clarification, Mark. Could you confirm that the strict check was added in v1.1 and wasn't present before?

neeral avatar Sep 27 '17 04:09 neeral

You are correct, this change (#16055) was merged back in May but never made it into v1.0.x since it was not a critical fix. It's new in v1.1.

mberhault avatar Sep 27 '17 12:09 mberhault

@jseldess: are we collecting a list of behavior changes for 1.1? This is not a huge change, but can cause surprises.

mberhault avatar Sep 27 '17 12:09 mberhault

These details are simply missing from 1.0 and 1.1 docs. @Amruta-Ranade, can you take this on after completing your docs on certificate rotation? If we add details to the --lifetime flag description for 1.0, we can then change those details in the 1.1 doc and add a "changed in 1.1" callout.

jseldess avatar Sep 27 '17 14:09 jseldess

Thanks @jseldess, and thank you @neeral for pointing out the change in behavior. I don't think there's anything left to do here, so closing this. Feel free to reopen if you disagree.

mberhault avatar Sep 27 '17 14:09 mberhault