fix: add missing adjudicateMisboundNamespace check to admission webhook filter#2978
Open
joonas wants to merge 1 commit intodefenseunicorns:mainfrom
Open
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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