Skip to content

Add extra API server certificate names to CKS clusters at creation - #14904

Open
bhouse-nexthop wants to merge 1 commit into
apache:mainfrom
bhouse-nexthop:cks-cert-sans
Open

bhouse-nexthop wants to merge 1 commit into
apache:mainfrom
bhouse-nexthop:cks-cert-sans

Conversation

@bhouse-nexthop

Copy link
Copy Markdown
Collaborator

Description

The API server certificate of a CKS cluster covers only the addresses CloudStack knows: the cluster's public (or external load balancer) IP, plus the control node IP that kubeadm adds. A client that reaches the cluster through a DNS name in front of the load balancer, a VIP or a NAT address fails TLS verification, and the only way out is insecure-skip-tls-verify or re-issuing the certificate by hand on every control node.

createKubernetesCluster takes a new parameter, apiserversans: a comma-separated list of DNS names and IP addresses to add to the certificate.

create kubernetescluster name=prod ... apiserversans=k8s.example.com,198.51.100.7
Before After
kubeadm init (stacked etcd) --apiserver-cert-extra-sans=<public IP> --apiserver-cert-extra-sans=<public IP>,k8s.example.com,198.51.100.7
kubeadm-config.yaml certSANs (external etcd) <public IP> <public IP>, k8s.example.com, 198.51.100.7
listKubernetesClusters "apiserversans": ["k8s.example.com", "198.51.100.7"]
  • Each entry must be an IP address or a DNS name as kubeadm accepts it (lower-case RFC 1123 subdomain). Entries are trimmed and lower-cased; anything else is refused before the cluster is created, with Invalid apiserversans entry '<entry>': give a DNS name or an IP address. A name whose last label is all digits (203.0.113.256) is refused as a mistyped IP address. Wildcards are not accepted.
  • The list is stored as a cluster detail, so there is no schema change.
  • kubeadm stores the SANs in the cluster's kubeadm-config ConfigMap, so control nodes that join later get them. kubeadm certs renew and upgrades keep them, because kubeadm renews from the existing certificate.
  • The UI's create form has a text field for it, and the cluster's details tab shows it.
  • The kubeconfig CloudStack returns still points at the public IP; a client that uses another name sets server: (or --tls-server-name) itself.
  • The list can not be changed after creation. That needs the certificate re-issued on every control node, and is not part of this PR.
  • ExternalManaged clusters refuse the parameter, since CloudStack does not issue their certificates.

This touches the same lines in KubernetesClusterStartWorker as #14769 (4.22) and #14783; whichever is merged second adds the extra SANs to the address list there.

Fixes: #14903

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Unit tests, mvn test -pl plugins/integrations/kubernetes-service -am -Dtest='Kubernetes*Test': 137 passed, 0 failed.

  • KubernetesClusterUtilTest: DNS names and IPv4/IPv6 addresses are accepted, trimmed and lower-cased; empty entries, underscores, leading hyphens, trailing dots, empty labels, wildcards, URLs, names over 253 characters and mistyped IPv4 addresses are refused.
  • KubernetesClusterManagerImplTest: an ExternalManaged create with apiserversans is refused.
  • KubernetesClusterStartWorkerTest: renders the real k8s-control-node.yml and checks the SANs in both the kubeadm init arguments and the kubeadm config, with and without extra SANs.

Not yet tested on a live cluster; a lab report will follow.

How did you try to break this feature and the system with this change?

  • Values YAML or the shell would misread (* starts a YAML alias and is a shell glob) are refused by the validation, and the kubeadm config quotes every entry.
  • Without the parameter the rendered config is the same as before, apart from the quotes around the public IP in certSANs.

The API server certificate of a CKS cluster covers only the control
node IP and the cluster's public or external load balancer IP. Clients
that reach the cluster through a DNS name in front of the load
balancer, a VIP or a NAT address fail TLS verification.

createKubernetesCluster takes apiserversans, a list of DNS names and IP
addresses. CKS validates them, stores them as a cluster detail and adds
them to kubeadm init (--apiserver-cert-extra-sans, or certSANs in the
kubeadm config with external etcd). kubeadm keeps them in the cluster
configuration, so control nodes that join later and kubeadm certs renew
keep them too.

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

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.73913% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.94%. Comparing base (58fda71) to head (7d2cf8c).

Files with missing lines Patch % Lines
...bernetes/cluster/KubernetesClusterManagerImpl.java 22.22% 6 Missing and 1 partial ⚠️
...kubernetes/cluster/CreateKubernetesClusterCmd.java 0.00% 3 Missing ⚠️
...dstack/api/response/KubernetesClusterResponse.java 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              main   #14904       +/-   ##
============================================
+ Coverage     3.86%   20.94%   +17.08%     
- Complexity       0    21170    +21170     
============================================
  Files          494     6057     +5563     
  Lines        42888   549600   +506712     
  Branches      8141    73485    +65344     
============================================
+ Hits          1657   115139   +113482     
- Misses       40999   421003   +380004     
- Partials       232    13458    +13226     
Flag Coverage Δ
uitests 3.86% <ø> (-0.01%) ⬇️
unittests 22.39% <71.73%> (?)

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

Copy link
Copy Markdown
Collaborator Author

Tested on a KVM lab running a main (24.0) build that includes this change. Primary storage is Ceph RBD, CKS clusters on Kubernetes 1.33.1. Each cluster was created with apiserversans=k8s-sans.example.com,api.k8s-sans.example.com,198.51.100.7.

Check 2 control nodes, stacked etcd (12 of 12 passed) 1 control node, 1 external etcd node (11 of 11 passed)
Create with an invalid entry (bad_name.example.com) refused with Invalid apiserversans entry 'bad_name.example.com', no cluster left behind same
listKubernetesClusters apiserversans returned as a list same
apiserver.crt on the control nodes both control nodes (including the one that joined) carry both DNS names, 198.51.100.7 and the cluster's public IP the control node carries them (kubeadm-config.yaml path)
kubectl with --tls-server-name k8s-sans.example.com lists the nodes same
kubectl with a name not in the list fails with an x509 error same
After kubeadm certs renew apiserver names still in the certificate

Both clusters were deleted afterwards.

Not tested: the UI create field and details row.

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.

CKS: allow extra DNS names and IP addresses in the API server certificate

1 participant