[BUG] No validation of `provisioning.cattle.io/management-cluster-name` annotation (format and uniqueness)
Rancher Server Setup
- Rancher version: v2.8 and later (all versions that honor the
provisioning.cattle.io/management-cluster-nameannotation, introduced in #42955); observed on currentmain - Installation option (Docker install/Helm Chart): Helm Chart
- If Helm Chart, Kubernetes Cluster and version (RKE1, RKE2, k3s, EKS, etc): N/A (not specific to the local cluster distro)
- Proxy/Cert Details: N/A
Information about the Cluster
- Kubernetes version: N/A
- Cluster Type (Local/Downstream): Downstream
- If downstream, what type of cluster? (Custom/Imported or specify provider for Hosted/Infrastructure Provider): Any provisioning v2 (
provisioning.cattle.io/v1) cluster
- If downstream, what type of cluster? (Custom/Imported or specify provider for Hosted/Infrastructure Provider): Any provisioning v2 (
User Information
- What is the role of the user logged in? (Admin/Cluster Owner/Cluster Member/Project Owner/Project Member/Custom): Admin
Describe the bug
When the provisioning.cattle.io/management-cluster-name annotation is set on a provisioning.cattle.io/v1 Cluster at creation time, the provisioning controller uses its value verbatim as the name of the generated management.cattle.io/v3 Cluster (pkg/controllers/provisioningv2/cluster/controller.go, createNewCluster). There is no server-side validation of this value:
- Uniqueness: nothing checks that the requested name is not already used by an existing management cluster, or requested by another provisioning cluster. Management clusters are cluster-scoped, so their names must be globally unique.
- Format: nothing checks that the value follows established format for v2prov-related management cluster names -
c-m-aaaaaaaa(whereais any lowercase alphanumeric character).
The webhook doesn't validate it either. The provisioning cluster validator only checks the provisioning cluster's own metadata.name, and the mutator ignores this annotation. The management cluster validator puts no constraints on metadata.name.
The UI now exposes this annotation (rancher/dashboard#18147), and users are starting to set it from automation (GitOps) to get predictable management cluster names, so this gap is likely to be hit.
Management cluster names were made random in v2.6.0 (#34178) to fix #33897, where a deterministic name caused identity/cache collisions when a cluster was deleted and recreated with the same name. Accepting a user-supplied name without validation brings back the same class of problem.
To Reproduce
- Create a provisioning v2 cluster (e.g.
fleet-default/cluster-a) and wait for it to become Active. Note its management cluster name (status.clusterName, e.g.c-m-aaaaaaaa). - Create a second provisioning v2 cluster (e.g.
fleet-default/cluster-b) with the annotationprovisioning.cattle.io/management-cluster-name: <management cluster name of cluster-a>.
Result
- The create request for
cluster-bsucceeds (HTTP 201). cluster-bnever gets a management cluster of its own and stays in an error state. In the UI, cluster creation hangs waiting for the corresponding management cluster.cluster-a(the existing cluster) starts flapping between Active and Updating, because both provisioning clusters' generating handlers now reconcile the same management cluster object.- No error is surfaced to the user saying the requested name collides with an existing one.
Expected Result Admission rejects the second provisioning cluster with a clear error because the requested management cluster name is already in use. The existing cluster is not affected.
More generally, the webhook should validate provisioning.cattle.io/management-cluster-name on create:
- reject values that collide with an existing management cluster, or with a name already requested by another provisioning cluster
- Important caveat: Simple uniqueness check may not be enough - issue #57522 seems to be caused by creating cluster with the same value of
provisioning.cattle.io/management-cluster-nameannotation as recently deleted cluster. Additional research is needed to confirm when it's safe to reuse previously used cluster name and how to track these.
- Important caveat: Simple uniqueness check may not be enough - issue #57522 seems to be caused by creating cluster with the same value of
- reject values that aren't in
c-m-aaaaaaaaformat
Screenshots N/A
Additional context
- Related: #56815. The same annotation can be changed after creation (via YAML/kubectl/API), even though the UI treats it as read-only. Since the controller only reads the annotation on first reconcile, an edit leaves it out of sync with
status.clusterName. Immutability is tracked there. This issue covers format and uniqueness validation on create. - Related: #57522. Excessive updates to CRTBs filling up etcd where observed when a cluster is created with the same value of
provisioning.cattle.io/management-cluster-nameannotation as recently deleted cluster.
SURE-11552
Source: rancher/rancher