fix: add missing adjudicateMisboundNamespace check to admission webhook filter#2978
Conversation
…hook filter `shouldSkipRequest` omitted the `adjudicateMisboundNamespace` adjudicator that `filterNoMatchReason` (the watch path) already included. This meant bindings targeting `kind: Namespace` with a namespace filter (a configuration error since namespaces don't live inside namespaces) were not rejected on the admission side. Instead, the request fell through to `adjudicateMismatchedNamespace`, which produced a misleading error: ``` "Binding defines namespaces ... but Object carries ''" ``` rather than the correct "Cannot use namespace filter on a namespace object" rejection. Additionally, `misboundNamespace` only checked `definesNamespaces` (literal namespace list) but not `definesNamespaceRegexes`. A `kind: Namespace` binding with `regexNamespaces` would slip through in both the admission and watch paths with the same misleading mismatch message. Two fixes: 1. Add `adjudicateMisboundNamespace(binding)` to the `shouldSkipRequest` adjudicator list in `filter.ts`, placed before the namespace mismatch checks so the configuration error is caught early. 2. Broaden `misboundNamespace` in `postCollection.ts` from `allPass([bindsToNamespace, definesNamespaces])` to `allPass([bindsToNamespace, anyPass([definesNamespaces, definesNamespaceRegexes])])`, covering both filter variants. Tests added for both admission and watch paths with literal and regex namespace filters, plus unit tests for the broadened predicate (166 tests pass across the two test files). Signed-off-by: Joonas Bergius <joonas@defenseunicorns.com>
Greptile SummaryThis PR fixes two related bugs in the namespace filter adjudication logic. First, Confidence Score: 5/5Safe to merge — targeted bug fix with no regressions expected. Both changes are minimal and correct: the missing adjudicator is inserted at the right position in the chain, and the broadened predicate covers the previously-unhandled regex case. All new code paths are covered by new tests. No existing behaviour is altered for non-Namespace bindings. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Incoming Admission Request] --> B[adjudicateMismatchedKind]
B -->|kind mismatch| SKIP[Skip / Ignore]
B -->|kind matches| C[adjudicateMisboundNamespace ✨ NEW]
C -->|binding is Namespace kind\nwith namespace/regexNamespace filter| SKIP
C -->|no misbound namespace| D[adjudicateUnbindableNamespaces]
D --> E[adjudicateUncarryableNamespace]
E --> F[adjudicateMismatchedNamespace]
F --> G[adjudicateMismatchedLabels / Annotations]
G --> H[adjudicateMismatchedNamespaceRegex]
H --> PASS[Allow Request]
subgraph misboundNamespace predicate
P1[bindsToNamespace] --> P3[allPass]
P2[anyPass\ndefinesNamespaces\ndefinesNamespaceRegexes ✨ NEW] --> P3
end
Reviews (1): Last reviewed commit: "Merge branch 'main' into fix/missing-adj..." | Re-trigger Greptile |
Description
shouldSkipRequestomitted theadjudicateMisboundNamespaceadjudicator thatfilterNoMatchReason(the watch path) already included. This meant bindings targetingkind: Namespacewith a namespace filter (a configuration error since namespaces don't live inside namespaces) were not rejected on the admission side. Instead, the request fell through toadjudicateMismatchedNamespace, which produced a misleading error:rather than the correct "Cannot use namespace filter on a namespace object" rejection.
Additionally,
misboundNamespaceonly checkeddefinesNamespaces(literal namespace list) but notdefinesNamespaceRegexes. Akind: Namespacebinding withregexNamespaceswould slip through in both the admission and watch paths with the same misleading mismatch message.Two fixes:
Add
adjudicateMisboundNamespace(binding)to theshouldSkipRequestadjudicator list infilter.ts, placed before the namespace mismatch checks so the configuration error is caught early.Broaden
misboundNamespaceinpostCollection.tsfromallPass([bindsToNamespace, definesNamespaces])toallPass([bindsToNamespace, anyPass([definesNamespaces, definesNamespaceRegexes])]), covering both filter variants.Tests added for both admission and watch paths with literal and regex namespace filters, plus unit tests for the broadened predicate.
End to End Test:
(See Pepr Excellent Examples)
Type of change
Checklist before merging