fix: require ignore label for VAP exempt namespace matching#4501
fix: require ignore label for VAP exempt namespace matching#4501sozercan wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Tightens Gatekeeper’s VAP “global exempted namespaces” matching to prevent policy bypass when --sync-vap-enforcement-scope is enabled by requiring the admission.gatekeeper.sh/ignore label on the namespace before namespaced resources are treated as exempt.
Changes:
- Update
matchGlobalExemptedNamespacesGlobto requirenamespaceObject.metadata.labelsto containadmission.gatekeeper.sh/ignorefor namespaced resources (cluster-scoped behavior unchanged). - Add a regression test asserting the generated match expression includes the namespace label checks.
Show a summary per file
| File | Description |
|---|---|
| pkg/drivers/k8scel/transform/cel_snippets.go | Tightens global exemption CEL logic for namespaced resources to require the namespace “ignore” label. |
| pkg/drivers/k8scel/transform/cel_snippets_test.go | Adds a regression test checking the generated CEL includes namespace label-gating logic. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 1
| func TestMatchGlobalExemptedNamespacesGlobRequiresIgnoreLabel(t *testing.T) { | ||
| mc := MatchGlobalExemptedNamespacesGlobV1Beta1(`"team-*"`) | ||
|
|
||
| expectedChecks := []string{ | ||
| "has(namespaceObject.metadata.labels)", | ||
| `("admission.gatekeeper.sh/ignore" in namespaceObject.metadata.labels)`, | ||
| } | ||
|
|
||
| for _, check := range expectedChecks { | ||
| if !strings.Contains(mc.Expression, check) { | ||
| t.Fatalf("expected expression to contain %q, got: %s", check, mc.Expression) | ||
| } | ||
| } |
There was a problem hiding this comment.
This regression test only asserts that the generated CEL expression contains certain substrings; it won’t catch CEL syntax/type errors (e.g., if namespaceObject isn’t available in the match-condition environment) or behavioral regressions (namespace match should not exempt unless the namespace has the ignore label). Consider compiling and evaluating the match condition against representative requests (namespaced vs cluster-scoped; namespace labeled vs unlabeled) like the other matcher tests in this file do.
JaydipGabani
left a comment
There was a problem hiding this comment.
replace substring test with an evaluation-based test using the existing TestMatchExcludedNamespacesGlob harness; verify namespaceObject null safety; add release-note callout for upgrade-time behavior migration (operators who listed a namespace in --exempt-namespace without labeling it will suddenly see enforcement)
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
efc639d to
0151bbc
Compare
Motivation
--sync-vap-enforcement-scopeis enabled by aligning VAP exemption logic with the label webhook semantics that require theadmission.gatekeeper.sh/ignorelabel on a namespace before its resources are exempted.Description
matchGlobalExemptedNamespacesGlobinpkg/drivers/k8scel/transform/cel_snippets.goso namespaced resources are exempted only when the namespace both matches the exempt pattern andnamespaceObject.metadata.labelscontainsadmission.gatekeeper.sh/ignorewhile preserving existing behavior for cluster-scoped objects.TestMatchGlobalExemptedNamespacesGlobRequiresIgnoreLabelinpkg/drivers/k8scel/transform/cel_snippets_test.gothat asserts the generated match condition includes the namespace label checks.buildMatchConditionsand keep all other behavior unchanged.Testing
go test ./pkg/drivers/k8scel/transform -run 'TestMatchGlobalExemptedNamespacesGlobRequiresIgnoreLabel|TestBuildMatchConditions' -count=1and the tests passed (ok).Codex Task