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

Use cert rotate parameter #2541

Merged
merged 6 commits into from
Feb 25, 2020
Merged

Use cert rotate parameter #2541

merged 6 commits into from
Feb 25, 2020

Conversation

anyasabo
Copy link
Contributor

Fix #2540

Previously we did not actually use the certificate rotation parameters, and only used the CA rotation parameters.

Also increases the NotBefore buffer from 1 minute to 10 minutes for the CA to match the certificate buffer. If clock skews are that far out there's probably other issues, but it definitely happens.

I didn't add tests for the new behavior because currently we do not really have tests at this level. I can def see how adding integration tests for this would be helpful though, so if you want me to add them I'm happy to do so.

@anyasabo anyasabo added >bug Something isn't working v1.1.0 labels Feb 10, 2020
)
if err != nil {
return results.WithError(err)
}

// handle CA expiry via requeue
results.WithResult(reconcile.Result{
RequeueAfter: certificates.ShouldRotateIn(time.Now(), httpCa.Cert.NotAfter, rotation.RotateBefore),
RequeueAfter: certificates.ShouldRotateIn(time.Now(), httpCa.Cert.NotAfter, caRotation.RotateBefore),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also make that call for the other certs?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure I follow your comment here @sebgl. Do you mean we should requeue within the validity period of the individual certificates and not just before the CA expires?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I mean also requeueing after we reconcile HTTP certificates below. Since we have caRotation and certRotation that can be different, it would make sense to make sure we requeue before any of these are reached? Maybe I'm missing something here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we not requeue on the minimum of the two?

Copy link
Contributor

@sebgl sebgl Feb 24, 2020

Choose a reason for hiding this comment

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

Yes! That's why I thought we would call results.WithResult () twice (one for CA, one for cert 10 lines below), and then we let the results aggregation do its job of picking the most appropriate requeue?

Copy link
Collaborator

@pebrc pebrc Feb 24, 2020

Choose a reason for hiding this comment

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

SGTM (I always forget that we already pick the shortest requeue in the aggregation)

pebrc
pebrc previously approved these changes Feb 24, 2020
Copy link
Collaborator

@pebrc pebrc left a comment

Choose a reason for hiding this comment

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

LGTM

)
if err != nil {
return results.WithError(err)
}

// handle CA expiry via requeue
results.WithResult(reconcile.Result{
RequeueAfter: certificates.ShouldRotateIn(time.Now(), httpCa.Cert.NotAfter, rotation.RotateBefore),
RequeueAfter: certificates.ShouldRotateIn(time.Now(), httpCa.Cert.NotAfter, caRotation.RotateBefore),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure I follow your comment here @sebgl. Do you mean we should requeue within the validity period of the individual certificates and not just before the CA expires?

@pebrc pebrc dismissed their stale review February 24, 2020 13:54

Let's do the additional WithResult call with the cert level rotation params before merging

@anyasabo
Copy link
Contributor Author

Yep! That was the plan, sorry I was on call so I let this sit. I should have put in an update though indicating the changes @sebgl suggested out of band

Copy link
Collaborator

@pebrc pebrc left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -74,6 +74,15 @@ func Reconcile(
if err != nil {
return results.WithError(err)
}

primaryCert, err := certificates.GetPrimaryCertificate(httpCertificates.CertPem())
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is a bit unfortunate that we have to parse the PEM again that we just parsed and or encoded in the reconcile function. But I guess changing this would be a larger refactoring of our certificate generation logic, so happy to track this in a follow up task.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I wasn't very happy about it, but the needs of both of them are discrete enough (one needs to construct the whole chain, the other just needs the expiration date of one cert) that I couldn't think of a better way to fix it without a larger scale change. One option might be for ReconcileHTTPCertificates() to return a Results, which could include errors and a resync time.

@anyasabo anyasabo merged commit 4e31ad3 into elastic:master Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug Something isn't working v1.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cert-validity is ignored
3 participants