-
Notifications
You must be signed in to change notification settings - Fork 119
Fix: correct search for control plane containers #1269
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.
could you give an example of how this would fail today (false positive)?
adding @chen-keinan to take a second look |
@simar7 Hi! apiVersion: v1
kind: Pod
metadata:
name: kube-apiserver
namespace: kube-system
spec:
containers:
- command:
- kube-apiserver
- "..."
name: kube-apiserver
- command:
- /usr/local/bin/kube-apiserver-healthcheck
name: healthcheck With old regex it will check both containers in If we use regex from this PR - all works as expected (only As you can see, examples differ only by regex in |
I see - thanks that makes sense now. In that case, could you also update the unit tests for this check to make sure that we can capture this? The test file lives here https://github.com/aquasecurity/defsec/blob/master/rules/kubernetes/policies/cisbenchmarks/apiserver/audit_log_path_test.rego You could add the input you provided in the rego playground and modify accordingly to have multiple containers as input, but only one of them triggers the check. |
@simar7 And hi here:) |
Signed-off-by: alexey.makhonin <[email protected]>
Signed-off-by: Simar <[email protected]>
awesome, thanks! |
* fix Signed-off-by: alexey.makhonin <[email protected]> * Fix regex and add tests for lib * opa fmt Signed-off-by: Simar <[email protected]> --------- Signed-off-by: alexey.makhonin <[email protected]> Signed-off-by: Simar <[email protected]> Co-authored-by: Simar <[email protected]>
* fix Signed-off-by: alexey.makhonin <[email protected]> * Fix regex and add tests for lib * opa fmt Signed-off-by: Simar <[email protected]> --------- Signed-off-by: alexey.makhonin <[email protected]> Signed-off-by: Simar <[email protected]> Co-authored-by: Simar <[email protected]>
Now in functions
is_apiserver
,is_etcd
,is_controllermananager
andis_scheduler
regexes for first command entry are not "strict", so when there is more than one container in control plane pod with first command entries, for example,kube-apiserver
andkube-apiserver-healthcheck
- checks for control plane containers would be applied also for another (non control plane) container. This produces false negative check results.In this PR I proposed solution for fixing this behavior.