fix: 4.6.3 default-namespace check false positive with resource/name kubectl output - #2146
Open
brantsrasmus wants to merge 1 commit into
Open
Conversation
…kubectl output The audit for 4.6.3 "The default namespace should not be used" runs `kubectl get all -n default --no-headers` and tries to drop the built-in API service with `grep -v '^service\s\+kubernetes\s'`. With multiple resource types requested, kubectl prints rows in resource/name form, so the line is `service/kubernetes ClusterIP ...` and the exclusion never matches. The built-in service itself then counts as usage and the check FAILs on every cluster, including ones with an otherwise empty default namespace. Match both the resource/name form and the legacy column form, using POSIX classes so the expression behaves the same under busybox grep in the kube-bench image. Applied to the four profiles that share this audit: aks-1.7, aks-1.8, gke-1.8.0, gke-1.9.0. Signed-off-by: brantsrasmus <rasmus.brants@fore.dev>
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.
Fixes #2145
Check 4.6.3 "The default namespace should not be used" runs
kubectl get all -n default --no-headersand tries to drop the built-in API Service withgrep -v '^service\s\+kubernetes\s'. With multiple resource types requested, kubectl prints rows inresource/nameform, so the line isservice/kubernetes ClusterIP ..., the exclusion never matches, and the Service itself counts as usage. The check then FAILs on every cluster, including ones with an otherwise emptydefaultnamespace.This changes the filter to accept both the
resource/nameform and the legacy column form, using POSIX character classes so it behaves the same under the busyboxgrepin the kube-bench image. Same one-line change in the four profiles that share this audit:aks-1.7,aks-1.8,gke-1.8.0,gke-1.9.0.Before (AKS 1.34, kube-bench v0.16.0,
defaultnamespace holding onlyservice/kubernetes):After, the new filter run inside the kube-bench image against the same input plus the two other cases: