Repository navigation
Join CKS nodes with a fresh token and a pinned CA - #14769
bhouse-nexthop wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A recreated worker joined again with the token in its user data, which only works while that token exists. With short-lived join tokens (apache#14769) it is gone after the create or scale. - before the drain of a batch with workers to recreate, the rollout runs kubeadm token create --print-join-command on a control node, with a TTL of the node timeout, and reads the token and CA hash. - before the restore, the kubeadm join of the VM's user data gets that token and --discovery-token-ca-cert-hash, in place of the old token and --discovery-token-unsafe-skip-ca-verification or an older hash. The rest of the user data is kept. The VM is stopped, so the network gets it when it starts. - a worker whose user data has no kubeadm join is refused before the drain. - the token is deleted once the batch ends, unless a recreated VM that is not back is running and may still be joining; it then expires on its own. A token whose output can't be parsed is deleted at once. - a restore refused before the root disk was replaced puts the old user data back. Works with or without apache#14769: the token comes from kubeadm and the join line is rewritten whichever form it has. Signed-off-by: Brad House <bhouse@nexthop.ai>
A recreated worker joined again with the token in its user data, which only works while that token exists. With short-lived join tokens (apache#14769) it is gone after the create or scale. - before the drain of a batch with workers to recreate, the rollout runs kubeadm token create --print-join-command on a control node, with a TTL of the node timeout, and reads the token and CA hash. - before the restore, the kubeadm join of the VM's user data gets that token and --discovery-token-ca-cert-hash, in place of the old token and --discovery-token-unsafe-skip-ca-verification or an older hash. The rest of the user data is kept. The VM is stopped, so the network gets it when it starts. - a worker whose user data has no kubeadm join is refused before the drain. - the token is deleted once the batch ends, unless a recreated VM that is not back is running and may still be joining; it then expires on its own. A token whose output can't be parsed is deleted at once. - a restore refused before the root disk was replaced puts the old user data back. Works with or without apache#14769: the token comes from kubeadm and the join line is rewritten whichever form it has. Signed-off-by: Brad House <bhouse@nexthop.ai>
|
Also passed on a 4.22-based build (4.22.1.1-nexthop with this change, Kubernetes v1.32.3, nested KVM lab):
|
8d5faa0 to
435e47c
Compare
With external etcd the kubeadm config advertised the public IP, so the API server certificate was valid only for the public IP and the service IP, not for the control node's own IP: | field | was | now | |---|---|---| | localAPIEndpoint.advertiseAddress (external etcd) | public IP | control node IP | | apiServer.certSANs, --apiserver-cert-extra-sans | public IP | control node IP, public IP | | controlPlaneEndpoint | public IP | public IP (unchanged) | - Nodes join on the control node's own IP. Today they skip CA verification; once they pin the CA (apache#14769), kubeadm checks the certificate and fails with "x509: certificate is valid for 10.96.0.1, <public IP>, not <control node IP>". - Advertising the node's own IP matches the stacked case, where kubeadm picks it by default. The kubernetes Service endpoint and the apiserver probes then stay on the guest network instead of going out through the public IP's port forward. - The control node IP is also listed explicitly in the SANs, in both the config and the flag path, so the certificate does not depend on which address kubeadm picks. - kubeconfig and the API rule still use the public IP. Signed-off-by: Brad House <bhouse@nexthop.ai>
With external etcd the kubeadm config advertised the public IP, so the API server certificate was valid only for the public IP and the service IP, not for the control node's own IP: | field | was | now | |---|---|---| | localAPIEndpoint.advertiseAddress (external etcd) | public IP | control node IP | | apiServer.certSANs, --apiserver-cert-extra-sans | public IP | control node IP, public IP | | controlPlaneEndpoint | public IP | public IP (unchanged) | - Nodes join on the control node's own IP. Today they skip CA verification; once they pin the CA (apache#14769), kubeadm checks the certificate and fails with "x509: certificate is valid for 10.96.0.1, <public IP>, not <control node IP>". - Advertising the node's own IP matches the stacked case, where kubeadm picks it by default. The kubernetes Service endpoint and the apiserver probes then stay on the guest network instead of going out through the public IP's port forward. - The control node IP is also listed explicitly in the SANs, in both the config and the flag path, so the certificate does not depend on which address kubeadm picks. - kubeconfig and the API rule still use the public IP. Signed-off-by: Brad House <bhouse@nexthop.ai>
24.0 counterpart of the add-node part of apache#14769. - Add-node joins on the address `kubeadm token create --print-join-command` prints (the controlPlaneEndpoint, else the advertise address), which the API server certificate always covers. - External etcd clusters created before the certificate fix have only the public IP in their certificate, so a pinned-CA join on the control node's private IP fails there. Signed-off-by: Brad House <bhouse@nexthop.ai>
Follow-up to "Join CKS nodes with a fresh token and a pinned CA", the changes amended into apache#14769. - The API server certificate always lists the control node's own IP as well as the public IP, since nodes join on the former and now verify the certificate. The external etcd kubeadm config advertises the control node's own IP (as kubeadm does in the stacked case); the public IP stays the controlPlaneEndpoint. - Add-node joins on the address kubeadm prints with the join command (the controlPlaneEndpoint, else the advertise address), which the certificate always covers. External etcd clusters created before this change have only the public IP in their certificate. Signed-off-by: Brad House <bhouse@nexthop.ai>
Problem: - The bootstrap token was derived from the cluster UUID (visible in the API) and never expired. - Nodes joined with --discovery-token-unsafe-skip-ca-verification. - The HA certificate key was also derived from the UUID. Change: - Create: CloudStack generates the cluster CA, a random token and a random certificate key. The token expires after the start timeout. - Create: the CA is copied to the first control node over SSH, not put in userdata; kubeadm init waits for it. Every other node pins its hash. - Create: once all nodes are ready, the token and the kubeadm-certs secret are deleted. - Scale and add-node: `kubeadm token create --print-join-command` on the control node gives a new token and the CA hash, so clusters created before this change keep scaling. The token is deleted afterwards, and also when an add-node fails before any node was given it. - Joins use --discovery-token-ca-cert-hash. - The API server certificate always lists the control node's own IP as well as the public IP, since nodes join on the former and now verify the certificate. The external etcd kubeadm config advertises the control node's own IP (as kubeadm does in the stacked case); the public IP stays the controlPlaneEndpoint. - Add-node joins on the control node's own IP, as before, unless the API server certificate served there is not valid for it (external etcd clusters created before this change). Then it joins on the address kubeadm prints with the join command, which the certificate covers. If the certificate can't be checked, the control node's IP is used. Not done here: deleting the old UUID token on existing clusters. Signed-off-by: Brad House <bhouse@nexthop.ai>
435e47c to
6fef2a0
Compare
…vers it 24.0 counterpart of the add-node part of the amended apache#14769. - Add-node joins on the control node's own IP, as before apache#14769, unless the API server certificate served there is not valid for it (openssl -checkip on the control node): external etcd clusters created before the certificate fix. Then it joins on the address kubeadm token create --print-join-command prints, which the certificate covers. - If the check can't tell, the control node's IP is used. Signed-off-by: Brad House <bhouse@nexthop.ai>
…vers it Follow-up to "Put the control node's IP in the CKS API server certificate", matching the amended apache#14769. - Add-node joins on the control node's own IP, as before apache#14769, unless the API server certificate served there is not valid for it (openssl -checkip on the control node): external etcd clusters created before the certificate fix. Then it joins on the address kubeadm token create --print-join-command prints, which the certificate covers. - If the check can't tell, the control node's IP is used. Signed-off-by: Brad House <bhouse@nexthop.ai>
|
Lab test of the join-address change: KVM, isolated network, a 4.22-based build (46372ad) and a main-based build (d385b9d). "Private" is the control node's own IP and "public" is the cluster's public IP. 4.22-based build, addNodesToKubernetesCluster:
Run by hand on the control nodes, the check prints Main-based build, recreate rollouts (worker template change,
This also covers the external-etcd results from my earlier run that I hadn't posted. On both build lines, clusters created with this change get the control node's private IP in the API server certificate and in |
Description
Fixes #14768
Nodes join a CKS cluster with a never-expiring bootstrap token derived from the cluster UUID, and with
--discovery-token-unsafe-skip-ca-verification. This gives every join a fresh, short-lived token and pins the cluster CA.kubeadm initwaits for it. Every other node joins with--discovery-token-ca-cert-hash sha256:<hash>kubeadm-certssecret are deletedkubeadm token create --ttl <timeout> --print-join-commandon the control node gives a new token and the CA hash, so clusters created before this change keep scaling. The output is parsed strictly (token and hash formats) before it goes into userdata. The token is deleted afterwards, and also when an add-node fails before any node was given itcontrolPlaneEndpointand kubeconfig is unchangedopenssl x509 -checkipon the control node). That is the case for external etcd clusters created before this change, which then join on the address--print-join-commandprints, which the certificate covers. If the check can't tell, the control node's IP is usedNot done here: deleting the old
<forever>UUID token on existing clusters. That is a one-off migration step.Related: conflicts with #14819 (fail add-node when a node isn't added) in
KubernetesClusterAddWorker: failure block, outer catch and helpers. Whichever lands second takes #14819's failure path, keeps this PR's token create/delete, and deletes the join token after the Ready wait on a partial add. A reference resolution is available.Types of changes
Feature/Enhancement Scale or Bug Severity
Bug Severity
How Has This Been Tested?
Unit tests:
KubernetesCluster*Testin the plugin pass, including the new token, certificate-key, CA-hash, join-command-parsing and token-delete tests.Lab: a nested KVM lab (3 hosts, Ceph RBD). It runs a main (24.0.0-SNAPSHOT) build with this commit picked on top, so it has not been run on a 4.22 build. Kubernetes v1.33.13, plus v1.32.5 for the old cluster.
kubeadm token listafterwards--discovery-token-ca-cert-hash sha256:…, which matches the hash of/etc/kubernetes/pki/ca.crt; no unsafe flag in any node's userdatakubeadm-certsdeletedkubeadm init --token-ttl 3600s … --certificate-key <random>; both control-plane joins and the worker join pin the same CA hashkubeadm-certsdeleted--discovery-token-ca-cert-hash<forever>token remains, as beforeThe only entry that remains is kubeadm's own "Proxy for managing TTL for the kubeadm-certs secret". It has no usages, so it cannot be used to join, and it expires after 2h.
How did you try to break this feature and the system with this change?
kubeadm token list.