-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: peefy <[email protected]>
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
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,7 @@ | ||
## Introduction | ||
|
||
`psp-fsgroup` is a kcl PSP validation package. | ||
|
||
## Resource | ||
|
||
Code source and document is [here](https://github.com/kcl-lang/artifacthub/tree/main/psp-fsgroup) |
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,5 @@ | ||
[package] | ||
name = "psp-fsgroup" | ||
version = "0.1.0" | ||
description = "`psp-fsgroup` is a kcl validation package" | ||
|
Empty file.
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,43 @@ | ||
"""Controls the user and group IDs of the container and some volumes. | ||
Corresponds to the `runAsUser`, `runAsGroup`, `supplementalGroups`, and | ||
`fsGroup` fields in a PodSecurityPolicy. For more information, see | ||
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#users-and-groups | ||
""" | ||
|
||
type Rule = "MustRunAs" | "MustRunAsNonRoot" | "RunAsAny" | ||
FIELDS = ["runAsUser", "runAsGroup", "supplementalGroups", "fsGroup"] | ||
|
||
schema Params: | ||
rule: Rule | ||
ranges: [Range] | ||
|
||
schema Range: | ||
min: int | ||
max: int | ||
|
||
check: | ||
min <= max | ||
|
||
params: Params = option("params") | ||
|
||
# Define the validation function | ||
validate = lambda item: {str:} { | ||
if item.kind == "Pod": | ||
fg = item?.spec?.securityContext?.fsGroup | ||
if params.rule == "RunAsAny": | ||
assert True | ||
# MustRunAs - Validates pod spec fsgroup against all ranges | ||
elif params.rule == "MustRunAs": | ||
assert fg and all range in params.ranges { | ||
range.min <= fg <= range.max | ||
} | ||
# Validates pod spec fsgroup against all ranges or allow pod spec fsgroup to be left unset | ||
elif params.rule == "MayRunAs" and fg: | ||
assert all range in params.ranges { | ||
range.min <= fg <= range.max | ||
} | ||
# Return the resource | ||
item | ||
} | ||
# Validate All resource | ||
items = [validate(i) for i in option("items")] |