-
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.
Merge pull request #39 from kcl-lang/psp-host-namespaces
feat: add psp-host-namespaces modules
- Loading branch information
Showing
4 changed files
with
31 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-host-namespaces` is a kcl PSP validation package. | ||
|
||
## Resource | ||
|
||
Code source and document is [here](https://github.com/kcl-lang/artifacthub/tree/main/psp-host-namespaces) |
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-host-namespaces" | ||
version = "0.1.0" | ||
description = "`psp-host-namespaces` 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,19 @@ | ||
"""Disallows sharing of host PID and IPC namespaces by pod containers. | ||
Corresponds to the `hostPID` and `hostIPC` fields in a PodSecurityPolicy. | ||
For more information, see | ||
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces | ||
""" | ||
|
||
# Define the validation function | ||
validate = lambda item: {str:} { | ||
n = "" | ||
if item.kind == "Pod": | ||
n = item.spec.hostPID or item.spec.hostIPC | ||
elif item.kind == "Deployment": | ||
n = item.spec.template.spec.hostPID or item.spec.template.spec.hostIPC | ||
assert not n, "Sharing the host namespace is not allowed: {}".format(item.metadata.name) | ||
# Return the resource | ||
item | ||
} | ||
# Validate All resource | ||
items = [validate(i) for i in option("items")] |