Skip to content

CKS add-node can pick an SSH port a live node uses after a node is removed #14797

Open

Description

@bhouse-nexthop

problem

CKS add-node picks the new node's SSH port from the node count, not from the ports in use. After removing an added node that is not the last one, the next add-node picks a port a live node still uses, and the add fails on a rule conflict.

In KubernetesClusterAddWorker.validateAndSetupNode:

int startSshPortNumber = CLUSTER_NODES_DEFAULT_START_SSH_PORT + (int) kubernetesCluster.getTotalNodeCount() - kubernetesCluster.getEtcdNodeCount().intValue();
int sshStartPort = startSshPortNumber + nodeIndex;

Example, 1 control + 2 workers (2222-2224):

step node count port picked result
add A 3 → 4 2225 ok
add B 4 → 5 2226 ok
remove A 5 → 4 (2225 freed) ok
add C 4 2226 clash with B's rules

On an isolated network the firewall rule create fails (The range specified, 2226-2226, conflicts with rule ...). On a VPC tier the PF rule is saved without a conflict check, so two PF rules share the port.

versions

4.22 and main (same code). Any CKS cluster that uses add-node / remove-node with external VMs.

The steps to reproduce the bug

  1. Create a CKS cluster (1 control, 2 workers) on an isolated network.
  2. addNodesToKubernetesCluster with VM A, then with VM B.
  3. removeNodesFromKubernetesCluster with VM A.
  4. addNodesToKubernetesCluster with VM C: it fails on port 2226.

What to do about it?

Pick the lowest port from 2222 up that no rule on the cluster's public IP is using, so a gap left by a removed node is reused and live nodes' ports are never taken. Existing nodes keep their ports.

Activity

  1. github-actions commented on Nov 30, 2026

    @github-actions

    Warning

    threat detection engine error
    The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

    What happened

    The threat detection engine failed to produce results.

    Review the workflow run logs for details.

    🎯 Triage report

    CKS add-node picks the new node's SSH port from the total node count, not from the ports in use. After a node that is not the last one is removed, the next add can pick a port a live node still uses. On an isolated network the firewall rule create then fails on a conflict. On a VPC tier the port-forwarding rule is saved without a conflict check, so two rules can share a port. The proposed fix is to take the lowest free port from 2222 that no rule on the cluster's public IP uses, leaving existing nodes unchanged.

    📊 Assessment

    Dimension Value Reasoning
    Type type:bug Port allocation collides with live nodes, with a worked example
    Component component:cks KubernetesClusterAddWorker.validateAndSetupNode
    Severity Severity:Major Add-node fails on isolated networks; duplicate rules on VPC tiers
    Labels type:bug, component:cks, Severity:Major Based on the issue text
    Coding agent Suitable Specific allocation rule given, with existing nodes unchanged

    🔗 Similar issues

    💡 Notes and suggestions
    • Reproduction: isolated-network cluster with one control and two workers, then add A, add B, remove A, add C.
    • The same port logic appears in the scale and upgrade paths, so a shared helper may be worth considering.

    Generated by Daily Issue Triage · copilot · haiku55 · ~8 AIC · ⊞ 3.8K · ◷

    Add this agentic workflow to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/daily-issue-triage.md@139fa09ef17cde4135e696ff8e7af09bc5ddfa6e
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions