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

fix(kubeconfig-rotate): adding rotation of kubeconfig #341

Closed
wants to merge 1 commit into from

Conversation

jds9090
Copy link
Contributor

@jds9090 jds9090 commented Aug 2, 2023

Closes #340.

@netlify
Copy link

netlify bot commented Aug 2, 2023

Deploy Preview for kamaji-documentation canceled.

Name Link
🔨 Latest commit dcf3a39
🔍 Latest deploy log https://app.netlify.com/sites/kamaji-documentation/deploys/64ca065124997d00081bdb8c

Copy link
Member

@prometherion prometherion left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix.

I'd like to think about this more in a different way to tackle this. With your proposal change, we need to wait for a TCP reconciliation before having the rotation of the kubeconfig.

Furthermore, we need to have the same logic also for certificates, such as the API server one, or the Front Proxy.

What we could do, my 2 cents, is to leverage the same principle we're suggesting in operating Kamaji, such as deleting the Secret to perform a rotation since this will trigger the TCP reconciliation, thus the Secret creation.

I'm thinking of a Secret controller which is looking up Secret resources and, according to the type, extracts the NotAfter field for the given x509 certificate, and enqueue it back according to the expiration.

Once this has been achieved (with a minimum gap, such as a day) the Controller will take care of deleting it to trigger the TCP reconciliation.

WDYT?

@jds9090
Copy link
Contributor Author

jds9090 commented Aug 2, 2023

Thanks for the quick fix.

I'd like to think about this more in a different way to tackle this. With your proposal change, we need to wait for a TCP reconciliation before having the rotation of the kubeconfig.

Furthermore, we need to have the same logic also for certificates, such as the API server one, or the Front Proxy.

What we could do, my 2 cents, is to leverage the same principle we're suggesting in operating Kamaji, such as deleting the Secret to perform a rotation since this will trigger the TCP reconciliation, thus the Secret creation.

I'm thinking of a Secret controller which is looking up Secret resources and, according to the type, extracts the NotAfter field for the given x509 certificate, and enqueue it back according to the expiration.

Once this has been achieved (with a minimum gap, such as a day) the Controller will take care of deleting it to trigger the TCP reconciliation.

WDYT?

Yes, That was also my second consideration. I want to give you another option and you can decide which one is nicer for kamaji.

In terms of the kubeadm control plane provider, it uses the sync-period option(https://github.com/kubernetes-sigs/cluster-api/blob/1f5fcd22fceccdd6286914bfb0ac494639f4d000/controlplane/kubeadm/main.go#L137) and they provide users certificatesExpiryDays(https://cluster-api.sigs.k8s.io/tasks/certs/auto-rotate-certificates-in-kcp.html).

Like kubeadm control plane provider, we can add the sync-period option for TCPs' reconciliation and modify the checkCertificateValidity function(

func checkCertificateValidity(cert x509.Certificate) bool {
) to check if certificates are going to expire in advance (ref. https://github.com/kubernetes-sigs/cluster-api/blob/1f5fcd22fceccdd6286914bfb0ac494639f4d000/util/collections/machine_filters.go#L187).

@jds9090
Copy link
Contributor Author

jds9090 commented Aug 2, 2023

I think TCPs should be reconciled regularly with two reasons and we can check the validity of the certificates before expiration on the regular basis.

Please, refer https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/manager.

A period sync happens for two reasons:

  1. To insure against a bug in the controller that causes an object to not be requeued, when it otherwise should be requeued.
  2. To insure against an unknown bug in controller-runtime, or its dependencies, that causes an object to not be requeued, when it otherwise should be requeued, or to be removed from the queue, when it otherwise should not be removed.

@prometherion
Copy link
Member

prometherion commented Aug 7, 2023

Closed in favour of #342.

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.

Add rotation for kubeconfig
2 participants