Skip to content

interface: [FEP-0001] prevent unsetting ClusterClaim selector terms - #812

Open
Yetkin Timocin (ytimocin) with Copilot wants to merge 1 commit into
mainfrom
copilot/fep-0001-fix-clusterrequest-immutability-bypass
Open

interface: [FEP-0001] prevent unsetting ClusterClaim selector terms#812
Yetkin Timocin (ytimocin) with Copilot wants to merge 1 commit into
mainfrom
copilot/fep-0001-fix-clusterrequest-immutability-bypass

Conversation

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

ClusterClaim.spec.clusterSelectorTerms could be removed after creation because Kubernetes skips field-level transition rules when an optional field becomes absent. This silently widened the request to match any member cluster.

  • API validation

    • Add a spec-level CEL presence guard while retaining the existing field-level immutability rule:

      // +kubebuilder:validation:XValidation:rule="has(self.clusterSelectorTerms) == has(oldSelf.clusterSelectorTerms)",message="the clusterSelectorTerms field cannot be added or removed after creation"
  • CRD

    • Regenerate the ClusterClaim CRD with the new validation rule.
  • Regression coverage

    • Add an envtest case verifying that unsetting populated clusterSelectorTerms is rejected.

Rebased onto main after #803 renamed ClusterRequest to ClusterClaim; the rule now lives on ClusterClaimSpec.

Copilot AI changed the title [WIP] Fix immutability bypass for clusterSelectorTerms in ClusterRequest interface: prevent unsetting ClusterRequest selector terms Aug 12, 2026
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ytimocin

Copy link
Copy Markdown
Collaborator

The single failing spec (resource_placement_rollout_test.go:684, image-rollover/resourcesnapshot) is unrelated to this diff — the PR only touches ClusterRequest API types, the CRD, and envtest validation. Same test family is tracked as flaky in #530, and it also flaked on an unrelated PR run today. Re-running the failed job.

@ytimocin
Yetkin Timocin (ytimocin) force-pushed the copilot/fep-0001-fix-clusterrequest-immutability-bypass branch from a669914 to 3626de2 Compare August 27, 2026 00:40
@ytimocin Yetkin Timocin (ytimocin) changed the title interface: prevent unsetting ClusterRequest selector terms interface: [FEP-0001] prevent unsetting ClusterClaim selector terms Aug 27, 2026
ClusterClaim.spec.clusterSelectorTerms could be removed after creation
because Kubernetes skips field-level transition rules when an optional
field becomes absent. Unsetting the field silently widened the claim to
match any member cluster, bypassing the field's immutability contract.

Add a spec-level CEL transition rule that requires the field's presence
to match between the old and new object, so the selector terms can be
neither added nor removed after creation, and cover it with an envtest
in the placement API validation suite.

Signed-off-by: Yetkin Timocin <ytimocin@microsoft.com>
@ytimocin
Yetkin Timocin (ytimocin) force-pushed the copilot/fep-0001-fix-clusterrequest-immutability-bypass branch from 3626de2 to 965415c Compare August 27, 2026 21:26
@ytimocin
Yetkin Timocin (ytimocin) marked this pull request as ready for review August 27, 2026 21:40
@ytimocin
Yetkin Timocin (ytimocin) requested a review from a team as a code owner August 27, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [FEP-0001] ClusterRequest clusterSelectorTerms immutability can be bypassed by unsetting the field

2 participants