Skip to content

Add CEL validation for NodeAddressAutodetection mutual exclusivity#4593

Open
caseydavenport wants to merge 5 commits intotigera:masterfrom
caseydavenport:casey-cel-autodetect
Open

Add CEL validation for NodeAddressAutodetection mutual exclusivity#4593
caseydavenport wants to merge 5 commits intotigera:masterfrom
caseydavenport:casey-cel-autodetect

Conversation

@caseydavenport
Copy link
Member

The operator's Go webhook validates that at most one autodetection method is set per address family, but a merge patch can bypass the webhook and set multiple fields (e.g. firstFound: true alongside interface: eth0). When this happens, the operator silently picks one and ignores the other, which is confusing.

Add a CEL XValidation rule directly on the NodeAddressAutodetection struct so the API server rejects invalid combinations at admission time, before the operator ever sees them.

Found this while working on https://github.com/tigera/calico-private/pull/11214 — a merge patch to set interface: eth0 didn't clear the existing firstFound: true, and the operator kept using first-found.

None

The operator's Go webhook already validates that at most one
autodetection method is set, but a merge patch can bypass the webhook
and set multiple fields simultaneously. Add a CEL XValidation rule
directly on the CRD so the API server rejects invalid combinations
before the operator ever sees them.
Use size(field) > 0 instead of field != '' to avoid goimports
corrupting single quotes in the CEL expression comment.

Add a fast unit test that compiles and evaluates the CEL expression
against a table of inputs covering all autodetection fields, conflict
combinations, and edge cases (false booleans, empty strings/lists).
@marvin-tigera marvin-tigera added this to the v1.43.0 milestone Mar 25, 2026
String fields with omitempty aren't present in the object when unset,
so size(self.field) fails with "no such key". Guard each field access
with has() to handle absent fields correctly.

Replace the cel-go unit test with an envtest-based test that creates
real Installation resources against the generated CRD. This validates
the full CRD schema including the CEL rules without duplicating the
rule expression. Also tests the merge patch scenario that originally
motivated the rule.
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.

2 participants