-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User and group PodSecurityPolicy added.
Adds the logic to enforce the same behaviour from the Kubernetes PodSecurityPolicy user to control user and groups used in the containers.
- Loading branch information
Showing
34 changed files
with
4,007 additions
and
109 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/usr/bin/env bats | ||
|
||
@test "RunAsAny should accept empty runAsUser, runAsGroup and supplementalGroups" { | ||
run kwctl run --request-path test_data/e2e/empty_security_context_pod.json --settings-path test_data/e2e/settings_run_as_any.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ] | ||
} | ||
|
||
@test "MustRunAs should reject invalid user ID" { | ||
run kwctl run --request-path test_data/e2e/invalid_user_id.json --settings-path test_data/e2e/settings_must_run_as.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ] | ||
[ $(expr "$output" : '.*"message":"User ID outside defined ranges".*') -ne 0 ] | ||
} | ||
|
||
@test "MustRunAs should reject invalid group ID" { | ||
run kwctl run --request-path test_data/e2e/invalid_group_id.json --settings-path test_data/e2e/settings_must_run_as.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ] | ||
[ $(expr "$output" : '.*"message":"Group ID is outside defined ranges".*') -ne 0 ] | ||
} | ||
|
||
@test "MustRunAs should reject invalid supplemental group ID" { | ||
run kwctl run --request-path test_data/e2e/invalid_supplemental_group_.json --settings-path test_data/e2e/settings_must_run_as.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ] | ||
[ $(expr "$output" : '.*"message":"Group ID is outside defined ranges".*') -ne 0 ] | ||
} | ||
|
||
@test "MustRunAs should patch empty runAsUser, runAsGroup and supplementalGroups" { | ||
run kwctl run --request-path test_data/e2e/empty_security_context_pod.json --settings-path test_data/e2e/settings_must_run_as.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ] | ||
[ $(expr "$output" : '.*"patchType":"JSONPatch".*') -ne 0 ] | ||
} | ||
|
||
@test "MayRunAs should accept empty runAsGroup and supplementalGroups" { | ||
run kwctl run --request-path test_data/e2e/empty_security_context_pod.json --settings-path test_data/e2e/settings_may_run_as.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ] | ||
} | ||
|
||
@test "MayRunAs should reject invalid group ID" { | ||
run kwctl run --request-path test_data/e2e/invalid_group_id.json --settings-path test_data/e2e/settings_may_run_as.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ] | ||
[ $(expr "$output" : '.*"message":"Group ID is outside defined ranges".*') -ne 0 ] | ||
} | ||
|
||
@test "MayRunAs should reject invalid supplemental group ID" { | ||
run kwctl run --request-path test_data/e2e/invalid_supplemental_group_.json --settings-path test_data/e2e/settings_may_run_as.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ] | ||
[ $(expr "$output" : '.*"message":"Group ID is outside defined ranges".*') -ne 0 ] | ||
} | ||
|
||
@test "MustRunAs should accept valid runAsUser, runAsGroup and supplementalGroups" { | ||
run kwctl run --request-path test_data/e2e/valid_security_context.json --settings-path test_data/e2e/settings_must_run_as.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ] | ||
} | ||
|
||
@test "MustRunAsNonRoot should reject 0 as user ID" { | ||
run kwctl run --request-path test_data/e2e/zero_as_user_id.json --settings-path test_data/e2e/settings_must_run_as_non_root.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ] | ||
[ $(expr "$output" : '.*"message":"Invalid user ID: cannot run container with root ID (0)".*') -ne 0 ] | ||
} | ||
|
||
@test "MustRunAsNonRoot should mutate request when runAsUser is not defined" { | ||
run kwctl run --request-path test_data/e2e/empty_security_context_pod.json --settings-path test_data/e2e/settings_must_run_as_non_root.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ] | ||
[ $(expr "$output" : '.*"patchType":"JSONPatch".*') -ne 0 ] | ||
} | ||
|
||
@test "MustRunAsNonRoot should accept request when user defined is not root" { | ||
run kwctl run --request-path test_data/e2e/valid_security_context.json --settings-path test_data/e2e/settings_must_run_as_non_root.json target/wasm32-unknown-unknown/release/psp_user_group.wasm | ||
[ "$status" -eq 0 ] | ||
echo "$output" | ||
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ] | ||
} |
This file contains 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
Oops, something went wrong.