-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consistently use namespaceMatchLabels across rules #316
Consistently use namespaceMatchLabels across rules #316
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please adapt the example managedk8s
diki config file to use the new namespaceMatchLabels
option:
diki/example/config/managedk8s.yaml
Lines 29 to 33 in 1529d1b
# # Defaults to ["default", "kube-public", "kube-node-lease"] | |
# namespaceNames: | |
# - default | |
# - kube-public | |
# - kube-node-lease |
diki/example/config/managedk8s.yaml
Lines 105 to 108 in 1529d1b
# namespaceNames: | |
# - kube-system | |
# - kube-public | |
# - kube-node-lease |
Also write a comment describing which namespaces can be selected. Example for
242383
:
# Only namespaces in ["default", "kube-public", "kube-node-lease"]
# can be selected with namespaceMatchLabels
I've added 3 new commits that may resolve the issues. The unnecessary newlines are removed, and the structs are renamed accordingly. New configurations are added in the yaml files as well |
example/config/managedk8s.yaml
Outdated
# - default | ||
# - kube-public | ||
# - kube-node-lease | ||
# # only namespaces in ["default", "kube-public", "kube-node-lease" can be selected with namespaceMatchLabels |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# # only namespaces in ["default", "kube-public", "kube-node-lease" can be selected with namespaceMatchLabels | |
# # only namespaces in ["default", "kube-public", "kube-node-lease"] are meaningful to be selected with namespaceMatchLabels | |
# since the rule does not perform checks on objects in namespaces different from the listed above |
example/config/managedk8s.yaml
Outdated
# - kube-system | ||
# - kube-public | ||
# - kube-node-lease | ||
# # only pods in namespaces ["kube-system", "kube-public", "kube-node-lease"] can be selected with namespaceMatchLabels |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
justification: "Pods managed by Gardener are not considered as user pods" | ||
- ruleID: "242449" | ||
- ruleID: "242449" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ruleID: "242449" | |
- ruleID: "242449" |
@@ -352,12 +350,15 @@ func (r *Ruleset) registerV2R1Rules(ruleOptions map[string]config.RuleOptionsCon | |||
Options: &sharedrules.Options242417{ | |||
AcceptedPods: []sharedrules.AcceptedPods242417{ | |||
{ | |||
PodMatchLabels: map[string]string{ | |||
PodSelector: option.PodSelector{PodMatchLabels: map[string]string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PodSelector: option.PodSelector{PodMatchLabels: map[string]string{ | |
PodSelector: option.PodSelector{ | |
PodMatchLabels: map[string]string{ |
@@ -88,19 +107,23 @@ func (r *Rule242383) Name() string { | |||
} | |||
|
|||
func (r *Rule242383) Run(ctx context.Context) (rule.RuleResult, error) { | |||
allNamespaces, err := kubeutils.GetNamespaces(ctx, r.Client) | |||
if err != nil { | |||
return rule.SingleCheckResult(r, rule.ErroredCheckResult(err.Error(), rule.NewTarget("", ""))), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return rule.SingleCheckResult(r, rule.ErroredCheckResult(err.Error(), rule.NewTarget("", ""))), nil | |
return rule.SingleCheckResult(r, rule.ErroredCheckResult(err.Error(), rule.NewTarget())), nil |
selector := labels.NewSelector().Add(*notDikiPodReq) | ||
|
||
allNamespaces, err := kubeutils.GetNamespaces(ctx, r.Client) | ||
if err != nil { | ||
return rule.SingleCheckResult(r, rule.ErroredCheckResult(err.Error(), rule.NewTarget("", ""))), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return rule.SingleCheckResult(r, rule.ErroredCheckResult(err.Error(), rule.NewTarget("", ""))), nil | |
return rule.SingleCheckResult(r, rule.ErroredCheckResult(err.Error(), rule.NewTarget()), nil |
APIVersion: "v1", | ||
Kind: "Service", | ||
MatchLabels: map[string]string{ | ||
"component": "apiserver", | ||
"provider": "kubernetes", | ||
}, | ||
NamespaceNames: []string{"default"}, | ||
NamespaceMatchLabels: allNamespaces["default"].Labels, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's match the default
namespace by the metadata name label similarly to how we match other namespaces. It would be better to keep this consistent since it will be easier for developers to search similar usages through the code.
@@ -106,10 +132,9 @@ var _ Option = (*Options242415)(nil) | |||
|
|||
// AcceptedPods242415 contains option specifications for appected pods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// AcceptedPods242415 contains option specifications for appected pods | |
// AcceptedPods242415 contains option specifications for accepted pods |
@@ -70,10 +98,9 @@ var _ Option = (*Options242414)(nil) | |||
|
|||
// AcceptedPods242414 contains option specifications for appected pods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// AcceptedPods242414 contains option specifications for appected pods | |
// AcceptedPods242414 contains option specifications for accepted pods |
7330903
to
05d3749
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
What this PR does / why we need it:
This PR refactors the accepted pod structs implemented for rules #242414 and #242415 by aggregating the label matching options into a singular shared structure.
The accepted pod struct for #242417 is refactored to utilize the new structure and now can add exemptions from the ruleset checks by matching namespaces by labels.
The accepted pod struct for #242383 is refactored as well to use namespace labels for matching its rule exemptions.
Which issue(s) this PR fixes:
Fixes #286
Special notes for your reviewer:
Release note: