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

check for renewing status #13666

Merged
merged 5 commits into from
Feb 22, 2023
Merged

Conversation

KauzClay
Copy link
Contributor

@KauzClay KauzClay commented Feb 2, 2023

Fixes # knative-extensions/net-certmanager#416
Related to # knative-extensions/net-certmanager#482

Proposed Changes

Release Note

Fixes issue where certificates would not get renewed when using auto-tls.

@knative-prow knative-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 2, 2023
@knative-prow knative-prow bot added area/API API objects and controllers area/networking size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 2, 2023
@codecov
Copy link

codecov bot commented Feb 3, 2023

Codecov Report

Base: 86.22% // Head: 86.14% // Decreases project coverage by -0.08% ⚠️

Coverage data is based on head (02a1c3f) compared to base (b4d7a28).
Patch coverage: 46.66% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13666      +/-   ##
==========================================
- Coverage   86.22%   86.14%   -0.08%     
==========================================
  Files         197      197              
  Lines       14783    14790       +7     
==========================================
- Hits        12746    12741       -5     
- Misses       1735     1745      +10     
- Partials      302      304       +2     
Impacted Files Coverage Δ
pkg/reconciler/route/route.go 79.70% <46.66%> (-1.53%) ⬇️
pkg/reconciler/revision/resolve.go 77.50% <0.00%> (-7.50%) ⬇️
pkg/reconciler/route/resources/ingress.go 94.80% <0.00%> (-0.20%) ⬇️
pkg/queue/sharedmain/main.go 0.61% <0.00%> (-0.01%) ⬇️

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

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@KauzClay
Copy link
Contributor Author

KauzClay commented Feb 3, 2023

For visibility, I've been testing this by changing the cmCert spec to add a RenewBefore field.

Since I'm using letsencrypt, the default lifetime of a cert is 90 days, and you can't really change it. But you can edit the RenewBefore field to force a renewal.

Because of some letsencrypt + certmanager stuff I don't understand, the notBefore time is actually an hour before the cert is created. So if you set it to renew 1hr2mins after it was ready, you can force a renewal every 2 minutes. If you do exactly an hour, it gets kinda stuck in a renewal loop.

anway, the cmCert spec then looks something like this:

cert := &cmv1.Certificate{
		ObjectMeta: metav1.ObjectMeta{
			Name:            knCert.Name,
			Namespace:       knCert.Namespace,
			OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(knCert)},
			Annotations:     knCert.GetAnnotations(),
			Labels:          knCert.GetLabels(),
		},
		Spec: cmv1.CertificateSpec{
			CommonName: commonName,
			SecretName: knCert.Spec.SecretName,
			DNSNames:   dnsNames,
			IssuerRef:  *cmConfig.IssuerRef,
			RenewBefore: &metav1.Duration{
				Duration: 129538 * time.Minute,
			},
			SecretTemplate: &cmv1.CertificateSecretTemplate{
				Labels: map[string]string{
					networking.CertificateUIDLabelKey: string(knCert.GetUID()),
				}},
		},
	}

Unfortunately, this doesn't seem to create the new http01 challenge endpoints. So I can't fully validate if the renewal change actually works. Still trying to understand why that is.

UPDATE: I asked around and learned that LetsEncrypt will cache challenge authorizations for 30 days, see here. So even though I can force a renew, no challenge gets created since it is in the cache.

UPDATE 2: So, you can clear this cache by deleting the letsencrypt issuer + secret and recreating the issuer, as explained here. I was able to do this, and could see the certificate get renewed, and see that the new HTTP01 Challenges were added to the kcert status.

@KauzClay KauzClay force-pushed the ck-handle-renewing-certs branch 2 times, most recently from 0b82832 to 529f7d7 Compare February 3, 2023 21:51
@KauzClay KauzClay changed the title [wip] check for renewing status check for renewing status Feb 6, 2023
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 6, 2023
* when reconciling routes
* adde extra logging around the renewing codepath
Copy link
Member

@dprotaso dprotaso left a comment

Choose a reason for hiding this comment

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

We should add a unit test.

Similarly, we might be able to add an e2e test that users our self-signed cluster issuer

logger.Infof("Renewing Condition detected on Cert (%s), will attempt creating new challenges.", cert.Name)
}
}
if cert.IsReady() && !isRenewing {
r.Status.MarkCertificateReady(cert.Name)
tls = append(tls, resources.MakeIngressTLS(cert, dnsNames.List()))
Copy link
Member

Choose a reason for hiding this comment

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

Going into the else flow will mark the route not ready - which we don't want since it can still serve traffic.

@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 13, 2023
@KauzClay KauzClay changed the title check for renewing status [wip] check for renewing status Feb 13, 2023
@knative-prow knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 13, 2023
@KauzClay
Copy link
Contributor Author

@dprotaso I added the unit test

Regarding this though:

Similarly, we might be able to add an e2e test that users our self-signed cluster issuer

I don't know of a way to make a self signed issuer to http01 challenges. The selfsigned issuer definition doesn't have a place to define solvers from what I can tell:

❯ k explain clusterissuer.spec.selfSigned
W0213 14:08:10.927054   69927 gcp.go:119] WARNING: the gcp auth plugin is deprecated in v1.22+, unavailable in v1.26+; use gcloud instead.
To learn more, consult https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke
KIND:     ClusterIssuer
VERSION:  cert-manager.io/v1

RESOURCE: selfSigned <Object>

DESCRIPTION:
     SelfSigned configures this issuer to 'self sign' certificates using the
     private key used to create the CertificateRequest object.

FIELDS:
   crlDistributionPoints	<[]string>
     The CRL distribution points is an X.509 v3 certificate extension which
     identifies the location of the CRL from which the revocation of this
     certificate can be checked. If not set certificate will be issued without
     CDP. Values are strings.

@KauzClay KauzClay changed the title [wip] check for renewing status check for renewing status Feb 13, 2023
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 13, 2023
Copy link
Member

@dprotaso dprotaso left a comment

Choose a reason for hiding this comment

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

Leaving the hold in case you want to address the nit - feel free to drop it

/lgtm
/approve
/hold

// The starting state is a route and ingress is ready with AutoTLS enabled, and
// a kcert that is ready, and has the renewing = true condition.
func TestAutoTLSCertRenewel(t *testing.T) {
ctx, informers, ctl, _, cf := newTestSetupWithConfigMaps(t, autoTLSConfigMaps)
Copy link
Member

Choose a reason for hiding this comment

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

nit: You might be able to simplify this test by lumping it into the following table test

func TestReconcileEnableAutoTLS(t *testing.T) {

Those table tests test a single Reconcile call and will assert create/update etc. occurs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah okay, I'll give that a try

@knative-prow knative-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 21, 2023
@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Feb 21, 2023
@knative-prow
Copy link

knative-prow bot commented Feb 21, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, KauzClay

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed lgtm Indicates that a PR is ready to be merged. labels Feb 21, 2023
* it is a little simpler than doing it in route_test.go
@dprotaso
Copy link
Member

/lgtm
/hold cancel

@knative-prow knative-prow bot added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Feb 21, 2023
@KauzClay
Copy link
Contributor Author

/test istio-latest-no-mesh

@knative-prow knative-prow bot merged commit f4792e4 into knative:main Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/API API objects and controllers area/networking lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants