Skip to content

Join CKS nodes with a fresh token and a pinned CA - #14769

Open
bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:cks-secure-join
Open

bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:cks-secure-join

Conversation

@bhouse-nexthop

Copy link
Copy Markdown
Collaborator

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.

step how
create CloudStack generates the cluster CA, a random bootstrap token and a random HA certificate key. The token TTL is the start timeout
create, CA copied to the first control node over SSH, not put in userdata. kubeadm init waits for it. Every other node joins with --discovery-token-ca-cert-hash sha256:<hash>
create, cleanup once all nodes are Ready, the token and the kubeadm-certs secret are deleted
scale-up, add-node kubeadm token create --ttl <timeout> --print-join-command on 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 it

Not done here: deleting the old <forever> UUID token on existing clusters. That is a one-off migration step.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • Major

How Has This Been Tested?

Unit tests: KubernetesCluster*Test in 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.

case joins kubeadm token list afterwards
create, 1 control + 2 workers workers: --discovery-token-ca-cert-hash sha256:…, which matches the hash of /etc/kubernetes/pki/ca.crt; no unsafe flag in any node's userdata no bootstrap token; kubeadm-certs deleted
create, 3 control + 1 worker (HA) kubeadm init --token-ttl 3600s … --certificate-key <random>; both control-plane joins and the worker join pin the same CA hash no bootstrap token; kubeadm-certs deleted
scale-up +1 worker (single control and HA) new node pins the CA hash the scale token was deleted
add-node, Ubuntu 24.04 VM pins the CA hash the add-node token was deleted
add-node that fails validation – no token left (an earlier revision of this change left a 59m token here)
cluster created by the old packages, scaled after the upgrade old node: unsafe flag (as created); new node: --discovery-token-ca-cert-hash only the old <forever> token remains, as before

The 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?

  • Scaled a cluster that was created by the old packages.
  • Ran add-node with a VM that fails validation, then checked kubeadm token list.

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.

Not done here: deleting the old UUID token on existing clusters.

Signed-off-by: Brad House <bhouse@nexthop.ai>
@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.36879% with 101 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.32%. Comparing base (b56bbc2) to head (8d5faa0).

Files with missing lines Patch % Lines
...er/actionworkers/KubernetesClusterStartWorker.java 0.00% 64 Missing ⚠️
...r/actionworkers/KubernetesClusterActionWorker.java 37.83% 22 Missing and 1 partial ⚠️
...ster/actionworkers/KubernetesClusterAddWorker.java 0.00% 8 Missing ⚠️
...er/actionworkers/KubernetesClusterScaleWorker.java 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               4.22   #14769    +/-   ##
==========================================
  Coverage     18.32%   18.32%            
- Complexity    16644    16654    +10     
==========================================
  Files          5939     5939            
  Lines        537787   537910   +123     
  Branches      65932    65939     +7     
==========================================
+ Hits          98544    98571    +27     
- Misses       428033   428136   +103     
+ Partials      11210    11203     -7     
Flag Coverage Δ
uitests 4.08% <ø> (ø)
unittests 19.41% <28.36%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

bhouse-nexthop added a commit to bhouse-nexthop/cloudstack that referenced this pull request Nov 22, 2026
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>
bhouse-nexthop added a commit to bhouse-nexthop/cloudstack that referenced this pull request Nov 22, 2026
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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant