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

feat: add psp-host-namespaces modules #39

Merged
merged 1 commit into from
Oct 31, 2023
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
7 changes: 7 additions & 0 deletions psp-host-namespaces/README.md
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)
5 changes: 5 additions & 0 deletions psp-host-namespaces/kcl.mod
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.
19 changes: 19 additions & 0 deletions psp-host-namespaces/main.k
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")]
Loading