Skip to content

Understand best practices to avoid kubeadm cert expiration #155

Open

Description

@garloff

As a Container Cluster Operator (KaaS operator), I want to understand what to do to avoid SSL cert expiration on kubeadm configured control nodes.

Definition of Ready:

  • User Story is small enough to be finished within one sprint
  • User Story is clear and understood by the whole team
  • Acceptance criteria are defined
  • Acceptance criteria are clear and understood by the whole team

Definition of Done:

  • All acceptance criteria are met
  • Changes have been reviewed
  • CI tests have run successfully
  • Documentation has been updated
  • Release Notes have been updated

Activity

  1. garloff commented on Aug 9, 2022

    @garloff
    MemberAuthor

    From Sven:
    See also https://kubernetes.slack.com/archives/C8TSNPY4T/p1644598355240599
    Usually a rollout is triggered. However, I see that we do not set rotateCertifactes: true. https://github.com/SovereignCloudStack/k8s-cluster-api-provider/blob/master/terraform/files/template/cluster-template.yaml#L50-L68

    So this is missing in the configuration. Also it would be recommended to set serverTLSBootstrap: true and to use a CSR controller so that also kubelet serving certificates are issued.

  2. garloff commented on Aug 9, 2022

    @garloff
    MemberAuthor

    From Thorsten:
    Yes, this is normal and and a normal task for the 2 day operations to upgrade the cluster. The docs[1] has any tasks in certain manner.
    On newer kubeadm version the cmd has changed from alpha to stable so the kubeadm alpha certs ... has moved to kubeadm certs ... instead.

    And be aware if there some other kubeconfigs in your cluster depends on certificates for accessing the kube-apiserver should be updated as well.
    The configuration for the kubelet and the kubelet server tls certificates on the nodes.

    [1] https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-certs/

  3. garloff commented on Aug 11, 2022

    @garloff
    MemberAuthor

    kubeadm [alpha] certs renew has not taken care of the kubelet server certificate in /var/lib/kubelet/pki/kubelet.crt.

    By switching on --rotate-server-certificates in /var/lib/kubelet/kubeadm-flags.env and restarting (systemctl restart kubelet) this can be addressed.
    The CSR needs to be approved manually kubectl get csr; kubectl certificate approve <CSR>, as signing server certificates needs care (for security reasons).
    For some reason, the signing still does not happen (soon) after approving, so we have a helper for this: SovereignCloudStack/k8s-cluster-api-provider#233

    With fresh kubelet server certs (in /var/lib/kubelet/pki/kubelet-server-current.pem), most things seem to work again.
    kubectl logs works after a fresh restart but fails after a while on some controllers ...

    ubuntu@capi-mgmtcluster:~$ k logs -n kube-system kube-controller-manager-testcluster-control-plane-x49h7 
    Error from server (InternalError): Internal error occurred: Authorization error (user=kube-apiserver-kubelet-client, verb=get, resource=nodes, subresource=proxy)
    

    So somehow, kube-proxy is still confused about its authorization? Some certificate that kubeadm has overlooked (and not the kubelet server cert)?
    The metrics service would not work either.

    Notes:

    1. This is an old cluster, using docker on the nodes (we don't do this since a long time) and k8s-1.18.x
    2. I would like to rescue the config and artifacts stored in the harbor app there
    3. We should avoid the need to manually intervene to keep clusters working, so enable cert rotation everywhere
    4. We should add a test case, where we put a very short expiration on certs, so we are sure this works
  4. batistein commented on Aug 15, 2022

    @batistein

    WIP not yet complete...

    • rotate-server-certificates flag with CSR Controller on Provider site or in cluster-api
    • EtcdEncryption
    • Best practices for flags (could follow CIS Benchmark, i could also provide a list but that's huge)
    • Admission control (eventrate limit, ResourceQuotaConfiguration, ImagePolicyWebhook, ValidationAdmissionWebhook etc.)
    • audit-policy
    • schedulerPolicyConfig (optional only necessary in some cases)
    • SELinux
    • konnectivity-service (server and client and requires EgressSelectorConfig, server should run non-containerized in uds mode with grpc)
    • node-problem-detector (standalone-mode, related to Operating System and components like container-runtime)
    • Logrotate configured on node
    • Network requirements (kernel, e.g. eBPF requirements)
    • SSH Hardening or no SSH
    • DNS Server configuration
    • NTP configuration
  5. added
    Container
    and removed on Aug 15, 2022
  6. garloff commented on Aug 22, 2022

    @garloff
    MemberAuthor

    Needs to be added in kubeadm's KUBELET EXTRA ARGS

  7. garloff commented on Aug 26, 2022

    @garloff
    MemberAuthor

    This issue is now a long collection, so let's track things in different issues:

  8. ajfriesen commented on Sep 12, 2022

    @ajfriesen

    Certificates in Kubernetes expire after 1 year.

    What does a provider need to do in order to NOT run into a certificate issue?

    1. Update the cluster at least once a year to rotate certificates automatically

      • Automatic certificate renewal for cluster upgrades
      • kubeadm renews all the certificates during control plane upgrade. This feature is designed for addressing the simplest use cases; if you don't have specific requirements on certificate renewal and perform Kubernetes version upgrades regularly (less than 1 year in between each upgrade), kubeadm will take care of keeping your cluster up to date and reasonably secure.

    2. Renew all certificates with kubeadm certs renew all

    Certificate Authority expires

    Another problem is that the CA might expire as well.

  9. garloff commented on Sep 14, 2022

    @garloff
    MemberAuthor

    Thanks, Andrej, I will add this to the maintenance docs in k8s-cluster-api-provider repo!

  10. added
    needs refinement
    on Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Containerneeds refinement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions