Skip to content
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

fix(kubernetes): fix the KSV001 check #86

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ getNoPrivilegeEscalationContainers[container] {
# getPrivilegeEscalationContainers returns the names of all containers which have
# securityContext.allowPrivilegeEscalation set to true or not set.
getPrivilegeEscalationContainers[container] {
containerName := kubernetes.containers[_].name
not getNoPrivilegeEscalationContainers[containerName]
container := kubernetes.containers[_]
not getNoPrivilegeEscalationContainers[container.name]
}

deny[res] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,34 @@ test_allow_privilege_escalation_set_to_true_denied {
count(r) == 1
r[_].msg == "Container 'hello' of Pod 'hello-privilege-escalation' should set 'securityContext.allowPrivilegeEscalation' to false"
}

test_allow_privilege_escalation_multiple_containers {
r := deny with input as {
"apiVersion": "v1",
"kind": "Pod",
"metadata": {"name": "hello-privilege-escalation"},
"spec": {"containers": [
{
"command": [
"sh",
"-c",
"echo 'Hello' && sleep 1h",
],
"image": "busybox",
"name": "hello",
"securityContext": {"allowPrivilegeEscalation": true},
},
{
"command": [
"sh",
"-c",
"echo 'Hello' && sleep 1h",
],
"image": "busybox",
"name": "hello2",
"securityContext": {"allowPrivilegeEscalation": false},
},
]},
}
count(r) == 1
}