Skip to content

Check cluster ownership for infra applies and cluster bindings (BUG-319978) - #1980

Merged
yongwen merged 1 commit into
masterfrom
fix/BUG-319978
Nov 19, 2026
Merged

yongwen merged 1 commit into
masterfrom
fix/BUG-319978

Conversation

@yongwen

@yongwen yongwen commented Nov 18, 2026

Copy link
Copy Markdown
Member

Fixes BUG-319978.

Summary

Problem (Why)

POST /v1/envs/{env}/{stage}/infras requires EXECUTE on the env in the path, but the cluster it changes comes from clusterName in the request body. ApplyInfraWorker acted on that name without checking that it belonged to the env:

  • For an existing Rodimus cluster, it overwrote the cluster's config and capacity and replaced its scaling policies, alarms, and scheduled actions.
  • For an unknown name, it bound the name to the caller's env and added it as group capacity without the ownership check that EnvCapacities applies.

Any user can create an env and becomes its admin, so any user could change another env's cluster or take over a group that live hosts report.

PUT /v1/envs/{env}/{stage} and POST /v1/envs had the same gap: they accepted any clusterName. Capacity checks, main-env lookups, and Rodimus resolve a cluster's owner from that field, so binding another env's cluster name undermines them too.

Solution (What + How)

One check in EnvironmentHandler, run in three places:

  • ApplyInfraWorker.applyInfra runs validateInfraCluster before any Rodimus or Teletraan change. Checking in the worker covers every way a job gets queued, including jobs queued before this change deploys.
  • EnvironmentHandler.updateEnvironment runs validateClusterClaim when an env stage's clusterName changes.
  • Environs.create runs validateClusterClaim when a new env stage has a clusterName. It checks a bean without the caller-supplied id.

The check rejects:

  • Cluster names outside [a-zA-Z0-9_-]{1,128} (400). This is Rodimus's own path pattern, and environs.cluster_name is VARCHAR(128). Cluster names are interpolated into Rodimus URLs, so the ownership check only holds if the name checked is the cluster Rodimus acts on.
  • An existing Rodimus cluster that isn't the env's clusterName.
  • A name bound to another env.
  • A name the env isn't bound to yet, if another non-sidecar env has it as group capacity, or if hosts report it and this env doesn't already deploy to it.

EnvInfras is unchanged: a rejected apply still returns 200 and its job then fails. The only automated caller, Spinnaker's TeletraanInfrastructureApplyMonitorTask, treats a failed job as a failed stage.

Behavior changes

  • Infra apply jobs fail for:
    • clusters bound to another env;
    • Rodimus clusters not bound to the env, including envs that use a cluster only as group capacity (set the env's clusterName first);
    • new names already used by another env's group capacity or reported by hosts.
  • PUT /v1/envs/{env}/{stage} and POST /v1/envs:
    • return 403 when clusterName changes to a name bound to another env, used as another env's group capacity, or reported by hosts this env doesn't deploy to;
    • return 400 for invalid names.
  • Deploy-board's create and clone flows bind {env}-{stage} before the cluster exists, so they are unaffected.

Before deploying

The owner lookup returns a single row, so first confirm that no two env stages share a cluster_name, and resolve any that do:

SELECT cluster_name, GROUP_CONCAT(CONCAT(env_name, '/', stage_name))
FROM environs
WHERE cluster_name <> ''
GROUP BY cluster_name
HAVING COUNT(*) > 1;

Test Plan

  • New InfraClusterOwnershipTest (7 tests) uses the real ApplyInfraWorker, EnvironmentHandler, and Environs with mocked DAOs and Rodimus.
    • The worker fails jobs for another env's cluster, a Rodimus cluster with no Teletraan owner, and an unclaimed group with hosts, with no Rodimus or Teletraan writes.
    • The worker still updates the env's own cluster.
    • Env update and create reject binding another env's cluster or an unclaimed group with hosts, including a create request with a spoofed id.
  • EnvironmentHandlerTest (+9) covers each rule. ApplyInfraWorkerTest (+2) checks that a rejected job makes no changes, and an invalid name makes no Rodimus calls.
  • With the three call sites reverted to master, the 6 rejection tests fail.
  • Full teletraanservice suite locally: 377 of 382 pass, 0 fail. The other 5 are TokenRolesTest, which needs a Docker Hub image unavailable on the test host; master behaves the same.
  • Compiled locally with ecj because the host has no javac. Formatted with google-java-format 1.7 (AOSP). Relying on CI for the Maven build and spotless.

🤖 Generated with Claude Code

…19978)

POST /v1/envs/{env}/{stage}/infras authorizes only the env in the path,
but ApplyInfraWorker acted on the clusterName from the request body.
Any env admin could reconfigure or resize another env's Rodimus cluster,
or claim a group that live hosts report. PUT and POST /v1/envs also
accepted any clusterName, which lets an env bind a name another env owns.

Add one ownership check in EnvironmentHandler and run it:
- in ApplyInfraWorker before any Rodimus or Teletraan change, which also
  covers jobs already queued;
- when an env stage's clusterName changes, and when an env stage is
  created with one.

The check rejects cluster names Rodimus cannot address, existing Rodimus
clusters not bound to the env, names bound to another env, and new names
that another non-sidecar env deploys to or that hosts already report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yongwen
yongwen requested a review from a team as a code owner November 18, 2026 18:13
@github-actions github-actions Bot added the deploy-service Includes changes to deploy-service label Nov 18, 2026
@yongwen
yongwen merged commit 48dc3bc into master Nov 19, 2026
6 checks passed
@yongwen
yongwen deleted the fix/BUG-319978 branch November 19, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deploy-service Includes changes to deploy-service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants