Datasets:
Add pinned source: gatekeeper-library (part 7)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf.files.sha256.json +0 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-baseline/update.yaml +26 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/constraint.yaml +12 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/disallowed_ephemeral.yaml +21 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/example_allowed.yaml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/example_disallowed.yaml +21 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/example_drop_all.yaml +21 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/update.yaml +26 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/suite.yaml +45 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/template.yaml +220 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/samples/psp-flexvolume-drivers/constraint.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/samples/psp-flexvolume-drivers/example_allowed.yaml +18 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/samples/psp-flexvolume-drivers/example_disallowed.yaml +18 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/samples/psp-flexvolume-drivers/update.yaml +23 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/suite.yaml +21 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/template.yaml +72 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/README.md +36 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/constraint.yaml +21 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/constraint2.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/constraint3.yaml +15 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/constraint4.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/constraint5.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/example_allowed.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/example_disallowed.yaml +16 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/update.yaml +21 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/suite.yaml +85 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/template.yaml +151 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/README.md +7 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/constraint.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/constraint2.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/constraint3.yaml +12 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/example_allowed.yaml +17 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/example_disallowed.yaml +17 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/update.yaml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/suite.yaml +53 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/template.yaml +127 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/no-host-paths/constraint.yaml +9 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/no-host-paths/example_allowed_no_volumes.yaml +8 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/psp-host-filesystem/constraint.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/psp-host-filesystem/disallowed_ephemeral.yaml +16 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/psp-host-filesystem/example_allowed.yaml +16 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/psp-host-filesystem/example_disallowed.yaml +16 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/psp-host-filesystem/update.yaml +23 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/suite.yaml +37 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/template.yaml +182 -0
.gitattributes
CHANGED
|
@@ -65,3 +65,4 @@ source_data/indexes/gene-ontology/go-2026-08-05+goa238/terms.jsonl filter=lfs di
|
|
| 65 |
source_data/indexes/gene-ontology/go-2026-08-05+goa238/units.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 66 |
source_data/indexes/reactome/release-98/reactome.db filter=lfs diff=lfs merge=lfs -text
|
| 67 |
source_data/pinned/gatekeeper-library-repin-1946bc28/1946bc28e133/gatekeeper-library-1946bc28e1337b90b7e675e3f0fa94aa2e92fd6e/website/static/img/favicon.ico filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 65 |
source_data/indexes/gene-ontology/go-2026-08-05+goa238/units.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 66 |
source_data/indexes/reactome/release-98/reactome.db filter=lfs diff=lfs merge=lfs -text
|
| 67 |
source_data/pinned/gatekeeper-library-repin-1946bc28/1946bc28e133/gatekeeper-library-1946bc28e1337b90b7e675e3f0fa94aa2e92fd6e/website/static/img/favicon.ico filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/website/static/img/favicon.ico filter=lfs diff=lfs merge=lfs -text
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf.files.sha256.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-baseline/update.yaml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: AdmissionReview
|
| 2 |
+
apiVersion: admission.k8s.io/v1beta1
|
| 3 |
+
request:
|
| 4 |
+
operation: "UPDATE"
|
| 5 |
+
object:
|
| 6 |
+
apiVersion: v1
|
| 7 |
+
kind: Pod
|
| 8 |
+
metadata:
|
| 9 |
+
name: opa-disallowed
|
| 10 |
+
labels:
|
| 11 |
+
owner: me.agilebank.demo
|
| 12 |
+
spec:
|
| 13 |
+
containers:
|
| 14 |
+
- name: opa
|
| 15 |
+
image: openpolicyagent/opa:0.9.2
|
| 16 |
+
args:
|
| 17 |
+
- "run"
|
| 18 |
+
- "--server"
|
| 19 |
+
- "--addr=localhost:8080"
|
| 20 |
+
securityContext:
|
| 21 |
+
capabilities:
|
| 22 |
+
add: ["SYS_ADMIN"]
|
| 23 |
+
resources:
|
| 24 |
+
limits:
|
| 25 |
+
cpu: "100m"
|
| 26 |
+
memory: "30Mi"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/constraint.yaml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPCapabilities
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-capabilities-restricted
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
allowedCapabilities: ["NET_BIND_SERVICE"]
|
| 12 |
+
requiredDropCapabilities: ["ALL"]
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/disallowed_ephemeral.yaml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: opa-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
owner: me.agilebank.demo
|
| 7 |
+
spec:
|
| 8 |
+
ephemeralContainers:
|
| 9 |
+
- name: opa
|
| 10 |
+
image: openpolicyagent/opa:0.9.2
|
| 11 |
+
args:
|
| 12 |
+
- "run"
|
| 13 |
+
- "--server"
|
| 14 |
+
- "--addr=localhost:8080"
|
| 15 |
+
securityContext:
|
| 16 |
+
capabilities:
|
| 17 |
+
add: ["SYS_ADMIN"]
|
| 18 |
+
resources:
|
| 19 |
+
limits:
|
| 20 |
+
cpu: "100m"
|
| 21 |
+
memory: "30Mi"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/example_allowed.yaml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: opa-allowed
|
| 5 |
+
labels:
|
| 6 |
+
owner: me.agilebank.demo
|
| 7 |
+
spec:
|
| 8 |
+
containers:
|
| 9 |
+
- name: opa
|
| 10 |
+
image: openpolicyagent/opa:0.9.2
|
| 11 |
+
args:
|
| 12 |
+
- "run"
|
| 13 |
+
- "--server"
|
| 14 |
+
- "--addr=localhost:8080"
|
| 15 |
+
securityContext:
|
| 16 |
+
capabilities:
|
| 17 |
+
add: ["NET_BIND_SERVICE"]
|
| 18 |
+
drop: ["ALL"]
|
| 19 |
+
resources:
|
| 20 |
+
limits:
|
| 21 |
+
cpu: "100m"
|
| 22 |
+
memory: "30Mi"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: opa-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
owner: me.agilebank.demo
|
| 7 |
+
spec:
|
| 8 |
+
containers:
|
| 9 |
+
- name: opa
|
| 10 |
+
image: openpolicyagent/opa:0.9.2
|
| 11 |
+
args:
|
| 12 |
+
- "run"
|
| 13 |
+
- "--server"
|
| 14 |
+
- "--addr=localhost:8080"
|
| 15 |
+
securityContext:
|
| 16 |
+
capabilities:
|
| 17 |
+
add: ["SYS_ADMIN"]
|
| 18 |
+
resources:
|
| 19 |
+
limits:
|
| 20 |
+
cpu: "100m"
|
| 21 |
+
memory: "30Mi"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/example_drop_all.yaml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: opa-drop-all
|
| 5 |
+
labels:
|
| 6 |
+
owner: me.agilebank.demo
|
| 7 |
+
spec:
|
| 8 |
+
containers:
|
| 9 |
+
- name: opa
|
| 10 |
+
image: openpolicyagent/opa:0.9.2
|
| 11 |
+
args:
|
| 12 |
+
- "run"
|
| 13 |
+
- "--server"
|
| 14 |
+
- "--addr=localhost:8080"
|
| 15 |
+
securityContext:
|
| 16 |
+
capabilities:
|
| 17 |
+
drop: ["ALL", "all"]
|
| 18 |
+
resources:
|
| 19 |
+
limits:
|
| 20 |
+
cpu: "100m"
|
| 21 |
+
memory: "30Mi"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/samples/psp-capabilities-restricted/update.yaml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: AdmissionReview
|
| 2 |
+
apiVersion: admission.k8s.io/v1beta1
|
| 3 |
+
request:
|
| 4 |
+
operation: "UPDATE"
|
| 5 |
+
object:
|
| 6 |
+
apiVersion: v1
|
| 7 |
+
kind: Pod
|
| 8 |
+
metadata:
|
| 9 |
+
name: opa-disallowed
|
| 10 |
+
labels:
|
| 11 |
+
owner: me.agilebank.demo
|
| 12 |
+
spec:
|
| 13 |
+
containers:
|
| 14 |
+
- name: opa
|
| 15 |
+
image: openpolicyagent/opa:0.9.2
|
| 16 |
+
args:
|
| 17 |
+
- "run"
|
| 18 |
+
- "--server"
|
| 19 |
+
- "--addr=localhost:8080"
|
| 20 |
+
securityContext:
|
| 21 |
+
capabilities:
|
| 22 |
+
add: ["SYS_ADMIN"]
|
| 23 |
+
resources:
|
| 24 |
+
limits:
|
| 25 |
+
cpu: "100m"
|
| 26 |
+
memory: "30Mi"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/suite.yaml
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: capabilities
|
| 5 |
+
tests:
|
| 6 |
+
- name: capabilities-baseline
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/psp-capabilities-baseline/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-disallowed
|
| 11 |
+
object: samples/psp-capabilities-baseline/example_disallowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: yes
|
| 14 |
+
- name: example-allowed
|
| 15 |
+
object: samples/psp-capabilities-baseline/example_allowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: no
|
| 18 |
+
- name: disallowed-ephemeral
|
| 19 |
+
object: samples/psp-capabilities-baseline/disallowed_ephemeral.yaml
|
| 20 |
+
assertions:
|
| 21 |
+
- violations: yes
|
| 22 |
+
- name: update
|
| 23 |
+
object: samples/psp-capabilities-baseline/update.yaml
|
| 24 |
+
assertions:
|
| 25 |
+
- violations: no
|
| 26 |
+
- name: capabilities-restricted
|
| 27 |
+
template: template.yaml
|
| 28 |
+
constraint: samples/psp-capabilities-restricted/constraint.yaml
|
| 29 |
+
cases:
|
| 30 |
+
- name: example-disallowed
|
| 31 |
+
object: samples/psp-capabilities-restricted/example_disallowed.yaml
|
| 32 |
+
assertions:
|
| 33 |
+
- violations: yes
|
| 34 |
+
- name: example-allowed
|
| 35 |
+
object: samples/psp-capabilities-restricted/example_allowed.yaml
|
| 36 |
+
assertions:
|
| 37 |
+
- violations: no
|
| 38 |
+
- name: disallowed-ephemeral
|
| 39 |
+
object: samples/psp-capabilities-restricted/disallowed_ephemeral.yaml
|
| 40 |
+
assertions:
|
| 41 |
+
- violations: yes
|
| 42 |
+
- name: update
|
| 43 |
+
object: samples/psp-capabilities-restricted/update.yaml
|
| 44 |
+
assertions:
|
| 45 |
+
- violations: no
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/capabilities/template.yaml
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8spspcapabilities
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Capabilities"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.1.3
|
| 8 |
+
metadata.gatekeeper.sh/bundle: "pod-security-baseline, pod-security-restricted"
|
| 9 |
+
description: >-
|
| 10 |
+
Controls Linux capabilities on containers. Corresponds to the
|
| 11 |
+
`allowedCapabilities` and `requiredDropCapabilities` fields in a
|
| 12 |
+
PodSecurityPolicy. For more information, see
|
| 13 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#capabilities
|
| 14 |
+
spec:
|
| 15 |
+
crd:
|
| 16 |
+
spec:
|
| 17 |
+
names:
|
| 18 |
+
kind: K8sPSPCapabilities
|
| 19 |
+
validation:
|
| 20 |
+
# Schema for the `parameters` field
|
| 21 |
+
openAPIV3Schema:
|
| 22 |
+
type: object
|
| 23 |
+
description: >-
|
| 24 |
+
Controls Linux capabilities on containers. Corresponds to the
|
| 25 |
+
`allowedCapabilities` and `requiredDropCapabilities` fields in a
|
| 26 |
+
PodSecurityPolicy. For more information, see
|
| 27 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#capabilities
|
| 28 |
+
properties:
|
| 29 |
+
exemptImages:
|
| 30 |
+
description: >-
|
| 31 |
+
Any container that uses an image that matches an entry in this list will be excluded
|
| 32 |
+
from enforcement. Prefix-matching can be signified with `*`. For example: `my-image-*`.
|
| 33 |
+
|
| 34 |
+
It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name)
|
| 35 |
+
in order to avoid unexpectedly exempting images from an untrusted repository.
|
| 36 |
+
type: array
|
| 37 |
+
items:
|
| 38 |
+
type: string
|
| 39 |
+
allowedCapabilities:
|
| 40 |
+
type: array
|
| 41 |
+
description: "A list of Linux capabilities that can be added to a container."
|
| 42 |
+
items:
|
| 43 |
+
type: string
|
| 44 |
+
requiredDropCapabilities:
|
| 45 |
+
type: array
|
| 46 |
+
description: "A list of Linux capabilities that are required to be dropped from a container."
|
| 47 |
+
items:
|
| 48 |
+
type: string
|
| 49 |
+
targets:
|
| 50 |
+
- target: admission.k8s.gatekeeper.sh
|
| 51 |
+
code:
|
| 52 |
+
- engine: K8sNativeValidation
|
| 53 |
+
source:
|
| 54 |
+
variables:
|
| 55 |
+
- name: containers
|
| 56 |
+
expression: 'has(variables.anyObject.spec.containers) ? variables.anyObject.spec.containers : []'
|
| 57 |
+
- name: initContainers
|
| 58 |
+
expression: 'has(variables.anyObject.spec.initContainers) ? variables.anyObject.spec.initContainers : []'
|
| 59 |
+
- name: ephemeralContainers
|
| 60 |
+
expression: 'has(variables.anyObject.spec.ephemeralContainers) ? variables.anyObject.spec.ephemeralContainers : []'
|
| 61 |
+
- name: allContainers
|
| 62 |
+
expression: 'variables.containers + variables.initContainers + variables.ephemeralContainers'
|
| 63 |
+
- name: exemptImagePrefixes
|
| 64 |
+
expression: |
|
| 65 |
+
!has(variables.params.exemptImages) ? [] :
|
| 66 |
+
variables.params.exemptImages.filter(image, image.endsWith("*")).map(image, string(image).replace("*", ""))
|
| 67 |
+
- name: exemptImageExplicit
|
| 68 |
+
expression: |
|
| 69 |
+
!has(variables.params.exemptImages) ? [] :
|
| 70 |
+
variables.params.exemptImages.filter(image, !image.endsWith("*"))
|
| 71 |
+
- name: exemptImages
|
| 72 |
+
expression: |
|
| 73 |
+
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
|
| 74 |
+
container.image in variables.exemptImageExplicit ||
|
| 75 |
+
variables.exemptImagePrefixes.exists(exemption, string(container.image).startsWith(exemption))
|
| 76 |
+
).map(container, container.image)
|
| 77 |
+
- name: allowedCapabilities
|
| 78 |
+
expression: 'has(variables.params.allowedCapabilities) ? variables.params.allowedCapabilities : []'
|
| 79 |
+
- name: allCapabilitiesAllowed
|
| 80 |
+
expression: '"*" in variables.allowedCapabilities'
|
| 81 |
+
- name: disallowedCapabilitiesByContainer
|
| 82 |
+
expression: |
|
| 83 |
+
variables.allContainers.map(container, !(container.image in variables.exemptImages) &&
|
| 84 |
+
!variables.allCapabilitiesAllowed && has(container.securityContext) && has(container.securityContext.capabilities) && has(container.securityContext.capabilities.add) &&
|
| 85 |
+
container.securityContext.capabilities.add.exists(capability, !(capability in variables.allowedCapabilities)),
|
| 86 |
+
[container.name, dyn(container.securityContext.capabilities.add.filter(capability, !(capability in variables.allowedCapabilities)).join(", "))]
|
| 87 |
+
)
|
| 88 |
+
- name: requiredDropCapabilities
|
| 89 |
+
expression: 'has(variables.params.requiredDropCapabilities) ? variables.params.requiredDropCapabilities : []'
|
| 90 |
+
- name: missingDropCapabilitiesByContainer
|
| 91 |
+
expression: |
|
| 92 |
+
variables.allContainers.map(container, !(container.image in variables.exemptImages) &&
|
| 93 |
+
size(variables.requiredDropCapabilities) > 0 && (
|
| 94 |
+
!has(container.securityContext) || !has(container.securityContext.capabilities) || !has(container.securityContext.capabilities.drop) || (
|
| 95 |
+
!(container.securityContext.capabilities.drop.exists(capability, capability.lowerAscii() == "all")) &&
|
| 96 |
+
variables.requiredDropCapabilities.exists(capability, !(capability in container.securityContext.capabilities.drop))
|
| 97 |
+
)
|
| 98 |
+
),
|
| 99 |
+
[container.name,
|
| 100 |
+
!has(container.securityContext) ? variables.requiredDropCapabilities :
|
| 101 |
+
!has(container.securityContext.capabilities) ? variables.requiredDropCapabilities :
|
| 102 |
+
!has(container.securityContext.capabilities.drop) ? variables.requiredDropCapabilities :
|
| 103 |
+
variables.requiredDropCapabilities.filter(capability, !(capability in container.securityContext.capabilities.drop))
|
| 104 |
+
]
|
| 105 |
+
)
|
| 106 |
+
validations:
|
| 107 |
+
- expression: '(has(request.operation) && request.operation == "UPDATE") || size(variables.disallowedCapabilitiesByContainer) == 0'
|
| 108 |
+
messageExpression: |
|
| 109 |
+
"containers have disallowed capabilities: " + variables.disallowedCapabilitiesByContainer.map(pair, "{container: " + pair[0] + ", capabilities: [" + pair[1] + "]}").join(", ")
|
| 110 |
+
- expression: '(has(request.operation) && request.operation == "UPDATE") || size(variables.missingDropCapabilitiesByContainer) == 0'
|
| 111 |
+
messageExpression: |
|
| 112 |
+
"containers are not dropping all required capabilities: " + variables.missingDropCapabilitiesByContainer.map(pair, "{container: " + pair[0] + ", capabilities: [" + pair[1].join(", ") + "]}").join(", ")
|
| 113 |
+
- engine: Rego
|
| 114 |
+
source:
|
| 115 |
+
rego: |
|
| 116 |
+
package capabilities
|
| 117 |
+
|
| 118 |
+
import data.lib.exclude_update.is_update
|
| 119 |
+
import data.lib.exempt_container.is_exempt
|
| 120 |
+
|
| 121 |
+
violation[{"msg": msg}] {
|
| 122 |
+
# spec.containers.securityContext.capabilities field is immutable.
|
| 123 |
+
not is_update(input.review)
|
| 124 |
+
|
| 125 |
+
container := input.review.object.spec.containers[_]
|
| 126 |
+
not is_exempt(container)
|
| 127 |
+
has_disallowed_capabilities(container)
|
| 128 |
+
msg := sprintf("container <%v> has a disallowed capability. Allowed capabilities are %v", [container.name, get_default(input.parameters, "allowedCapabilities", "NONE")])
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
violation[{"msg": msg}] {
|
| 132 |
+
not is_update(input.review)
|
| 133 |
+
container := input.review.object.spec.containers[_]
|
| 134 |
+
not is_exempt(container)
|
| 135 |
+
missing_drop_capabilities(container)
|
| 136 |
+
msg := sprintf("container <%v> is not dropping all required capabilities. Container must drop all of %v or \"ALL\"", [container.name, input.parameters.requiredDropCapabilities])
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
violation[{"msg": msg}] {
|
| 140 |
+
not is_update(input.review)
|
| 141 |
+
container := input.review.object.spec.initContainers[_]
|
| 142 |
+
not is_exempt(container)
|
| 143 |
+
has_disallowed_capabilities(container)
|
| 144 |
+
msg := sprintf("init container <%v> has a disallowed capability. Allowed capabilities are %v", [container.name, get_default(input.parameters, "allowedCapabilities", "NONE")])
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
violation[{"msg": msg}] {
|
| 148 |
+
not is_update(input.review)
|
| 149 |
+
container := input.review.object.spec.initContainers[_]
|
| 150 |
+
not is_exempt(container)
|
| 151 |
+
missing_drop_capabilities(container)
|
| 152 |
+
msg := sprintf("init container <%v> is not dropping all required capabilities. Container must drop all of %v or \"ALL\"", [container.name, input.parameters.requiredDropCapabilities])
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
violation[{"msg": msg}] {
|
| 156 |
+
not is_update(input.review)
|
| 157 |
+
container := input.review.object.spec.ephemeralContainers[_]
|
| 158 |
+
not is_exempt(container)
|
| 159 |
+
has_disallowed_capabilities(container)
|
| 160 |
+
msg := sprintf("ephemeral container <%v> has a disallowed capability. Allowed capabilities are %v", [container.name, get_default(input.parameters, "allowedCapabilities", "NONE")])
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
violation[{"msg": msg}] {
|
| 164 |
+
not is_update(input.review)
|
| 165 |
+
container := input.review.object.spec.ephemeralContainers[_]
|
| 166 |
+
not is_exempt(container)
|
| 167 |
+
missing_drop_capabilities(container)
|
| 168 |
+
msg := sprintf("ephemeral container <%v> is not dropping all required capabilities. Container must drop all of %v or \"ALL\"", [container.name, input.parameters.requiredDropCapabilities])
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
has_disallowed_capabilities(container) {
|
| 172 |
+
allowed := {c | c := lower(input.parameters.allowedCapabilities[_])}
|
| 173 |
+
not allowed["*"]
|
| 174 |
+
capabilities := {c | c := lower(container.securityContext.capabilities.add[_])}
|
| 175 |
+
|
| 176 |
+
count(capabilities - allowed) > 0
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
missing_drop_capabilities(container) {
|
| 180 |
+
must_drop := {c | c := lower(input.parameters.requiredDropCapabilities[_])}
|
| 181 |
+
all := {"all"}
|
| 182 |
+
dropped := {c | c := lower(container.securityContext.capabilities.drop[_])}
|
| 183 |
+
|
| 184 |
+
count(must_drop - dropped) > 0
|
| 185 |
+
count(all - dropped) > 0
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
get_default(obj, param, _) := obj[param]
|
| 189 |
+
|
| 190 |
+
get_default(obj, param, _default) := _default {
|
| 191 |
+
not obj[param]
|
| 192 |
+
not obj[param] == false
|
| 193 |
+
}
|
| 194 |
+
libs:
|
| 195 |
+
- |
|
| 196 |
+
package lib.exclude_update
|
| 197 |
+
|
| 198 |
+
is_update(review) {
|
| 199 |
+
review.operation == "UPDATE"
|
| 200 |
+
}
|
| 201 |
+
- |
|
| 202 |
+
package lib.exempt_container
|
| 203 |
+
|
| 204 |
+
is_exempt(container) {
|
| 205 |
+
exempt_images := object.get(object.get(input, "parameters", {}), "exemptImages", [])
|
| 206 |
+
img := container.image
|
| 207 |
+
exemption := exempt_images[_]
|
| 208 |
+
_matches_exemption(img, exemption)
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
_matches_exemption(img, exemption) {
|
| 212 |
+
not endswith(exemption, "*")
|
| 213 |
+
exemption == img
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
_matches_exemption(img, exemption) {
|
| 217 |
+
endswith(exemption, "*")
|
| 218 |
+
prefix := trim_suffix(exemption, "*")
|
| 219 |
+
startswith(img, prefix)
|
| 220 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/samples/psp-flexvolume-drivers/constraint.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPFlexVolumes
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-flexvolume-drivers
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
allowedFlexVolumes: #[]
|
| 12 |
+
- driver: "example/lvm"
|
| 13 |
+
- driver: "example/cifs"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/samples/psp-flexvolume-drivers/example_allowed.yaml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-flexvolume-driver-allowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-flexvolume-driver
|
| 7 |
+
spec:
|
| 8 |
+
containers:
|
| 9 |
+
- name: nginx
|
| 10 |
+
image: nginx
|
| 11 |
+
volumeMounts:
|
| 12 |
+
- mountPath: /test
|
| 13 |
+
name: test-volume
|
| 14 |
+
readOnly: true
|
| 15 |
+
volumes:
|
| 16 |
+
- name: test-volume
|
| 17 |
+
flexVolume:
|
| 18 |
+
driver: "example/lvm"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/samples/psp-flexvolume-drivers/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-flexvolume-driver-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-flexvolume-driver
|
| 7 |
+
spec:
|
| 8 |
+
containers:
|
| 9 |
+
- name: nginx
|
| 10 |
+
image: nginx
|
| 11 |
+
volumeMounts:
|
| 12 |
+
- mountPath: /test
|
| 13 |
+
name: test-volume
|
| 14 |
+
readOnly: true
|
| 15 |
+
volumes:
|
| 16 |
+
- name: test-volume
|
| 17 |
+
flexVolume:
|
| 18 |
+
driver: "example/testdriver" #"example/lvm"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/samples/psp-flexvolume-drivers/update.yaml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: AdmissionReview
|
| 2 |
+
apiVersion: admission.k8s.io/v1beta1
|
| 3 |
+
request:
|
| 4 |
+
operation: "UPDATE"
|
| 5 |
+
object:
|
| 6 |
+
apiVersion: v1
|
| 7 |
+
kind: Pod
|
| 8 |
+
metadata:
|
| 9 |
+
name: nginx-flexvolume-driver-disallowed
|
| 10 |
+
labels:
|
| 11 |
+
app: nginx-flexvolume-driver
|
| 12 |
+
spec:
|
| 13 |
+
containers:
|
| 14 |
+
- name: nginx
|
| 15 |
+
image: nginx
|
| 16 |
+
volumeMounts:
|
| 17 |
+
- mountPath: /test
|
| 18 |
+
name: test-volume
|
| 19 |
+
readOnly: true
|
| 20 |
+
volumes:
|
| 21 |
+
- name: test-volume
|
| 22 |
+
flexVolume:
|
| 23 |
+
driver: "example/testdriver" #"example/lvm"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/suite.yaml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: flexvolume-drivers
|
| 5 |
+
tests:
|
| 6 |
+
- name: flexvolume-drivers
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/psp-flexvolume-drivers/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-allowed
|
| 11 |
+
object: samples/psp-flexvolume-drivers/example_allowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: no
|
| 14 |
+
- name: example-disallowed
|
| 15 |
+
object: samples/psp-flexvolume-drivers/example_disallowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: yes
|
| 18 |
+
- name: update
|
| 19 |
+
object: samples/psp-flexvolume-drivers/update.yaml
|
| 20 |
+
assertions:
|
| 21 |
+
- violations: no
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/flexvolume-drivers/template.yaml
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8spspflexvolumes
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "FlexVolumes"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.0.1
|
| 8 |
+
description: >-
|
| 9 |
+
Controls the allowlist of FlexVolume drivers. Corresponds to the
|
| 10 |
+
`allowedFlexVolumes` field in PodSecurityPolicy. For more information,
|
| 11 |
+
see
|
| 12 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#flexvolume-drivers
|
| 13 |
+
spec:
|
| 14 |
+
crd:
|
| 15 |
+
spec:
|
| 16 |
+
names:
|
| 17 |
+
kind: K8sPSPFlexVolumes
|
| 18 |
+
validation:
|
| 19 |
+
# Schema for the `parameters` field
|
| 20 |
+
openAPIV3Schema:
|
| 21 |
+
type: object
|
| 22 |
+
description: >-
|
| 23 |
+
Controls the allowlist of FlexVolume drivers. Corresponds to the
|
| 24 |
+
`allowedFlexVolumes` field in PodSecurityPolicy. For more information,
|
| 25 |
+
see
|
| 26 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#flexvolume-drivers
|
| 27 |
+
properties:
|
| 28 |
+
allowedFlexVolumes:
|
| 29 |
+
type: array
|
| 30 |
+
description: "An array of AllowedFlexVolume objects."
|
| 31 |
+
items:
|
| 32 |
+
type: object
|
| 33 |
+
properties:
|
| 34 |
+
driver:
|
| 35 |
+
description: "The name of the FlexVolume driver."
|
| 36 |
+
type: string
|
| 37 |
+
targets:
|
| 38 |
+
- target: admission.k8s.gatekeeper.sh
|
| 39 |
+
rego: |
|
| 40 |
+
package k8spspflexvolumes
|
| 41 |
+
|
| 42 |
+
import data.lib.exclude_update.is_update
|
| 43 |
+
|
| 44 |
+
violation[{"msg": msg, "details": {}}] {
|
| 45 |
+
# spec.volumes field is immutable.
|
| 46 |
+
not is_update(input.review)
|
| 47 |
+
|
| 48 |
+
volume := input_flexvolumes[_]
|
| 49 |
+
not input_flexvolumes_allowed(volume)
|
| 50 |
+
msg := sprintf("FlexVolume %v is not allowed, pod: %v. Allowed drivers: %v", [volume, input.review.object.metadata.name, input.parameters.allowedFlexVolumes])
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
input_flexvolumes_allowed(volume) {
|
| 54 |
+
input.parameters.allowedFlexVolumes[_].driver == volume.flexVolume.driver
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
input_flexvolumes[v] {
|
| 58 |
+
v := input.review.object.spec.volumes[_]
|
| 59 |
+
has_field(v, "flexVolume")
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
# has_field returns whether an object has a field
|
| 63 |
+
has_field(object, field) = true {
|
| 64 |
+
object[field]
|
| 65 |
+
}
|
| 66 |
+
libs:
|
| 67 |
+
- |
|
| 68 |
+
package lib.exclude_update
|
| 69 |
+
|
| 70 |
+
is_update(review) {
|
| 71 |
+
review.operation == "UPDATE"
|
| 72 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Forbidden Sysctls security context policy
|
| 2 |
+
|
| 3 |
+
The forbidden sysctls constraint allows one to limit the set of kernel parameters that can be modified by pods. This is accomplished by specifying a combination of allowed and forbidden sysctls using either of two parameters: `allowedSysctls` and `forbiddenSysctls`.
|
| 4 |
+
|
| 5 |
+
## Parameters
|
| 6 |
+
|
| 7 |
+
`allowedSysctls`: A list of explicitly allowed sysctls. Any sysctl not in this list will be considered forbidden. '*' and trailing wildcards are supported. If unspecified, no limitations are made by this parameter.
|
| 8 |
+
|
| 9 |
+
`forbiddenSysctls`: A list of explicitly denied sysctls. Any sysctl in this list will be considered forbidden. '*' and trailing wildcards are supported. If unspecified, no limitations are made by this parameter.
|
| 10 |
+
|
| 11 |
+
## Examples
|
| 12 |
+
|
| 13 |
+
```yaml
|
| 14 |
+
parameters:
|
| 15 |
+
allowedSysctls: ['*']
|
| 16 |
+
forbiddenSysctls:
|
| 17 |
+
- kernel.msg*
|
| 18 |
+
- net.core.somaxconn
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
```yaml
|
| 22 |
+
parameters:
|
| 23 |
+
allowedSysctls:
|
| 24 |
+
- kernel.shm_rmid_forced
|
| 25 |
+
- net.ipv4.ip_local_port_range
|
| 26 |
+
- net.ipv4.tcp_syncookies
|
| 27 |
+
- net.ipv4.ping_group_range
|
| 28 |
+
forbiddenSysctls: []
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
*Note*: `forbiddenSysctls` takes precedence, such that an explicitly forbidden sysctl is still forbidden even if it appears in `allowedSysctls` as well. However in practice, such overlap between the rules should be avoided.
|
| 32 |
+
|
| 33 |
+
## References
|
| 34 |
+
|
| 35 |
+
* [Using sysctls in a Kubernetes Cluster](https://kubernetes.io/docs/tasks/administer-cluster/sysctl-cluster/)
|
| 36 |
+
* [Kubernetes API Reference - Sysctl](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#sysctl-v1-core)
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/constraint.yaml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPForbiddenSysctls
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-forbidden-sysctls
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
allowedSysctls:
|
| 12 |
+
- kernel.shm_rmid_forced
|
| 13 |
+
- net.ipv4.ip_local_port_range
|
| 14 |
+
- net.ipv4.ip_unprivileged_port_start
|
| 15 |
+
- net.ipv4.tcp_syncookies
|
| 16 |
+
- net.ipv4.ping_group_range
|
| 17 |
+
- net.ipv4.ip_local_reserved_ports
|
| 18 |
+
- net.ipv4.tcp_keepalive_time
|
| 19 |
+
- net.ipv4.tcp_fin_timeout
|
| 20 |
+
- net.ipv4.tcp_keepalive_intvl
|
| 21 |
+
- net.ipv4.tcp_keepalive_probes
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/constraint2.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPForbiddenSysctls
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-forbidden-sysctls
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
forbiddenSysctls:
|
| 12 |
+
- "*" # * forbid all sysctls
|
| 13 |
+
allowedSysctls:
|
| 14 |
+
- "*" # allows all sysctls. allowedSysctls is optional.
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/constraint3.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPForbiddenSysctls
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-forbidden-sysctls
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
forbiddenSysctls:
|
| 12 |
+
# - "*" # * may be used to forbid all sysctls
|
| 13 |
+
- kernel.*
|
| 14 |
+
allowedSysctls:
|
| 15 |
+
- "net.*"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/constraint4.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPForbiddenSysctls
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-forbidden-sysctls
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
forbiddenSysctls:
|
| 12 |
+
# - "*" # * may be used to forbid all sysctls
|
| 13 |
+
- kernel.*
|
| 14 |
+
allowedSysctls: [] # empty allowedSysctls means all sysctls are forbidden
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/constraint5.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPForbiddenSysctls
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-forbidden-sysctls
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
forbiddenSysctls:
|
| 12 |
+
# - "*" # * may be used to forbid all sysctls
|
| 13 |
+
- kernel.*
|
| 14 |
+
# unspecified allowedSysctls will not place any restrictions
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/example_allowed.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-forbidden-sysctls-allowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-forbidden-sysctls
|
| 7 |
+
spec:
|
| 8 |
+
containers:
|
| 9 |
+
- name: nginx
|
| 10 |
+
image: nginx
|
| 11 |
+
securityContext:
|
| 12 |
+
sysctls:
|
| 13 |
+
- name: net.ipv4.ip_local_port_range
|
| 14 |
+
value: "1024 65535"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-forbidden-sysctls-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-forbidden-sysctls
|
| 7 |
+
spec:
|
| 8 |
+
containers:
|
| 9 |
+
- name: nginx
|
| 10 |
+
image: nginx
|
| 11 |
+
securityContext:
|
| 12 |
+
sysctls:
|
| 13 |
+
- name: kernel.msgmax
|
| 14 |
+
value: "65536"
|
| 15 |
+
- name: net.core.somaxconn
|
| 16 |
+
value: "1024"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/samples/psp-forbidden-sysctls/update.yaml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: AdmissionReview
|
| 2 |
+
apiVersion: admission.k8s.io/v1beta1
|
| 3 |
+
request:
|
| 4 |
+
operation: "UPDATE"
|
| 5 |
+
object:
|
| 6 |
+
apiVersion: v1
|
| 7 |
+
kind: Pod
|
| 8 |
+
metadata:
|
| 9 |
+
name: nginx-forbidden-sysctls-disallowed
|
| 10 |
+
labels:
|
| 11 |
+
app: nginx-forbidden-sysctls
|
| 12 |
+
spec:
|
| 13 |
+
containers:
|
| 14 |
+
- name: nginx
|
| 15 |
+
image: nginx
|
| 16 |
+
securityContext:
|
| 17 |
+
sysctls:
|
| 18 |
+
- name: kernel.msgmax
|
| 19 |
+
value: "65536"
|
| 20 |
+
- name: net.core.somaxconn
|
| 21 |
+
value: "1024"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/suite.yaml
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: forbidden-sysctls
|
| 5 |
+
tests:
|
| 6 |
+
- name: forbidden-sysctls
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/psp-forbidden-sysctls/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-disallowed
|
| 11 |
+
object: samples/psp-forbidden-sysctls/example_disallowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: yes
|
| 14 |
+
- name: example-allowed
|
| 15 |
+
object: samples/psp-forbidden-sysctls/example_allowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: no
|
| 18 |
+
- name: update
|
| 19 |
+
object: samples/psp-forbidden-sysctls/update.yaml
|
| 20 |
+
assertions:
|
| 21 |
+
- violations: no
|
| 22 |
+
- name: forbidden-sysctls-wildcard
|
| 23 |
+
template: template.yaml
|
| 24 |
+
constraint: samples/psp-forbidden-sysctls/constraint2.yaml
|
| 25 |
+
cases:
|
| 26 |
+
- name: example-disallowed
|
| 27 |
+
object: samples/psp-forbidden-sysctls/example_disallowed.yaml
|
| 28 |
+
assertions:
|
| 29 |
+
- violations: yes
|
| 30 |
+
- name: example-disallowed
|
| 31 |
+
object: samples/psp-forbidden-sysctls/example_allowed.yaml
|
| 32 |
+
assertions:
|
| 33 |
+
- violations: yes
|
| 34 |
+
- name: update
|
| 35 |
+
object: samples/psp-forbidden-sysctls/update.yaml
|
| 36 |
+
assertions:
|
| 37 |
+
- violations: no
|
| 38 |
+
- name: forbidden-sysctls3
|
| 39 |
+
template: template.yaml
|
| 40 |
+
constraint: samples/psp-forbidden-sysctls/constraint3.yaml
|
| 41 |
+
cases:
|
| 42 |
+
- name: example-disallowed
|
| 43 |
+
object: samples/psp-forbidden-sysctls/example_disallowed.yaml
|
| 44 |
+
assertions:
|
| 45 |
+
- violations: yes
|
| 46 |
+
- name: example-allowed
|
| 47 |
+
object: samples/psp-forbidden-sysctls/example_allowed.yaml
|
| 48 |
+
assertions:
|
| 49 |
+
- violations: no
|
| 50 |
+
- name: update
|
| 51 |
+
object: samples/psp-forbidden-sysctls/update.yaml
|
| 52 |
+
assertions:
|
| 53 |
+
- violations: no
|
| 54 |
+
- name: forbidden-sysctls4-empty-allowedSysctls
|
| 55 |
+
template: template.yaml
|
| 56 |
+
constraint: samples/psp-forbidden-sysctls/constraint4.yaml
|
| 57 |
+
cases:
|
| 58 |
+
- name: example-disallowed
|
| 59 |
+
object: samples/psp-forbidden-sysctls/example_disallowed.yaml
|
| 60 |
+
assertions:
|
| 61 |
+
- violations: yes
|
| 62 |
+
- name: example-disallowed
|
| 63 |
+
object: samples/psp-forbidden-sysctls/example_allowed.yaml
|
| 64 |
+
assertions:
|
| 65 |
+
- violations: yes
|
| 66 |
+
- name: update
|
| 67 |
+
object: samples/psp-forbidden-sysctls/update.yaml
|
| 68 |
+
assertions:
|
| 69 |
+
- violations: no
|
| 70 |
+
- name: forbidden-sysctls5-unspecified-allowedSysctls
|
| 71 |
+
template: template.yaml
|
| 72 |
+
constraint: samples/psp-forbidden-sysctls/constraint5.yaml
|
| 73 |
+
cases:
|
| 74 |
+
- name: example-disallowed
|
| 75 |
+
object: samples/psp-forbidden-sysctls/example_disallowed.yaml
|
| 76 |
+
assertions:
|
| 77 |
+
- violations: yes
|
| 78 |
+
- name: example-allowed
|
| 79 |
+
object: samples/psp-forbidden-sysctls/example_allowed.yaml
|
| 80 |
+
assertions:
|
| 81 |
+
- violations: no
|
| 82 |
+
- name: update
|
| 83 |
+
object: samples/psp-forbidden-sysctls/update.yaml
|
| 84 |
+
assertions:
|
| 85 |
+
- violations: no
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/forbidden-sysctls/template.yaml
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8spspforbiddensysctls
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Forbidden Sysctls"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.2.1
|
| 8 |
+
metadata.gatekeeper.sh/bundle: "pod-security-baseline, pod-security-restricted"
|
| 9 |
+
description: >-
|
| 10 |
+
Controls the `sysctl` profile used by containers. Corresponds to the
|
| 11 |
+
`allowedUnsafeSysctls` and `forbiddenSysctls` fields in a PodSecurityPolicy.
|
| 12 |
+
When specified, any sysctl not in the `allowedSysctls` parameter is considered to be forbidden.
|
| 13 |
+
The `forbiddenSysctls` parameter takes precedence over the `allowedSysctls` parameter.
|
| 14 |
+
For more information, see https://kubernetes.io/docs/tasks/administer-cluster/sysctl-cluster/
|
| 15 |
+
spec:
|
| 16 |
+
crd:
|
| 17 |
+
spec:
|
| 18 |
+
names:
|
| 19 |
+
kind: K8sPSPForbiddenSysctls
|
| 20 |
+
validation:
|
| 21 |
+
# Schema for the `parameters` field
|
| 22 |
+
openAPIV3Schema:
|
| 23 |
+
type: object
|
| 24 |
+
description: >-
|
| 25 |
+
Controls the `sysctl` profile used by containers. Corresponds to the
|
| 26 |
+
`allowedUnsafeSysctls` and `forbiddenSysctls` fields in a PodSecurityPolicy.
|
| 27 |
+
When specified, any sysctl not in the `allowedSysctls` parameter is considered to be forbidden.
|
| 28 |
+
The `forbiddenSysctls` parameter takes precedence over the `allowedSysctls` parameter.
|
| 29 |
+
For more information, see https://kubernetes.io/docs/tasks/administer-cluster/sysctl-cluster/
|
| 30 |
+
properties:
|
| 31 |
+
allowedSysctls:
|
| 32 |
+
type: array
|
| 33 |
+
description: "An allow-list of sysctls. `*` allows all sysctls not listed in the `forbiddenSysctls` parameter."
|
| 34 |
+
items:
|
| 35 |
+
type: string
|
| 36 |
+
forbiddenSysctls:
|
| 37 |
+
type: array
|
| 38 |
+
description: "A disallow-list of sysctls. `*` forbids all sysctls."
|
| 39 |
+
items:
|
| 40 |
+
type: string
|
| 41 |
+
targets:
|
| 42 |
+
- target: admission.k8s.gatekeeper.sh
|
| 43 |
+
code:
|
| 44 |
+
- engine: K8sNativeValidation
|
| 45 |
+
source:
|
| 46 |
+
variables:
|
| 47 |
+
- name: isUpdate
|
| 48 |
+
expression: has(request.operation) && request.operation == "UPDATE"
|
| 49 |
+
- name: sysctls
|
| 50 |
+
expression: '!has(variables.anyObject.spec.securityContext) ? [] : !has(variables.anyObject.spec.securityContext.sysctls) ? [] : variables.anyObject.spec.securityContext.sysctls'
|
| 51 |
+
- name: allowedSysctlPrefixes
|
| 52 |
+
expression: |
|
| 53 |
+
!has(variables.params.allowedSysctls) ? [] : variables.params.allowedSysctls.filter(sysctl, sysctl.endsWith("*")).map(sysctl, string(sysctl).replace("*", ""))
|
| 54 |
+
- name: allowedSysctlExplicit
|
| 55 |
+
expression: |
|
| 56 |
+
!has(variables.params.allowedSysctls) ? [] :
|
| 57 |
+
variables.params.allowedSysctls.filter(sysctl, !sysctl.endsWith("*"))
|
| 58 |
+
- name: forbiddenSysctlPrefixes
|
| 59 |
+
expression: |
|
| 60 |
+
!has(variables.params.forbiddenSysctls) ? [] : variables.params.forbiddenSysctls.filter(sysctl, sysctl.endsWith("*")).map(sysctl, string(sysctl).replace("*", ""))
|
| 61 |
+
- name: forbiddenSysctlExplicit
|
| 62 |
+
expression: |
|
| 63 |
+
!has(variables.params.forbiddenSysctls) ? [] :
|
| 64 |
+
variables.params.forbiddenSysctls.filter(sysctl, !sysctl.endsWith("*"))
|
| 65 |
+
- name: allowedSysctlsString
|
| 66 |
+
expression: |
|
| 67 |
+
!has(variables.params.allowedSysctls) ? "unspecified" : size(variables.params.allowedSysctls) == 0 ? "empty" : variables.params.allowedSysctls.join(", ")
|
| 68 |
+
- name: violatingSysctls
|
| 69 |
+
expression: |
|
| 70 |
+
(variables.sysctls.filter(sysctl,
|
| 71 |
+
(sysctl.name in variables.forbiddenSysctlExplicit ||
|
| 72 |
+
variables.forbiddenSysctlPrefixes.exists(fsp, string(sysctl.name).startsWith(fsp))) ||
|
| 73 |
+
(has(variables.params.allowedSysctls) &&
|
| 74 |
+
!(sysctl.name in variables.allowedSysctlExplicit) &&
|
| 75 |
+
!variables.allowedSysctlPrefixes.exists(asp, string(sysctl.name).startsWith(asp)))))
|
| 76 |
+
validations:
|
| 77 |
+
- expression: 'variables.isUpdate || size(variables.violatingSysctls) == 0'
|
| 78 |
+
messageExpression: '"The sysctl is not allowed for pod: " + variables.anyObject.metadata.name + ", forbidden: " + variables.params.forbiddenSysctls.join(", ") + ", allowed: " + variables.allowedSysctlsString'
|
| 79 |
+
- engine: Rego
|
| 80 |
+
source:
|
| 81 |
+
rego: |
|
| 82 |
+
package k8spspforbiddensysctls
|
| 83 |
+
|
| 84 |
+
import data.lib.exclude_update.is_update
|
| 85 |
+
|
| 86 |
+
# Block if forbidden
|
| 87 |
+
violation[{"msg": msg, "details": {}}] {
|
| 88 |
+
# spec.securityContext.sysctls field is immutable.
|
| 89 |
+
not is_update(input.review)
|
| 90 |
+
|
| 91 |
+
sysctl := input.review.object.spec.securityContext.sysctls[_].name
|
| 92 |
+
forbidden_sysctl(sysctl)
|
| 93 |
+
msg := sprintf("The sysctl %v is not allowed, pod: %v. Forbidden sysctls: %v", [sysctl, input.review.object.metadata.name, input.parameters.forbiddenSysctls])
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
# Block if not explicitly allowed
|
| 97 |
+
violation[{"msg": msg, "details": {}}] {
|
| 98 |
+
not is_update(input.review)
|
| 99 |
+
sysctl := input.review.object.spec.securityContext.sysctls[_].name
|
| 100 |
+
not allowed_sysctl(sysctl)
|
| 101 |
+
allowmsg := allowed_sysctl_string()
|
| 102 |
+
msg := sprintf("The sysctl %v is not explicitly allowed, pod: %v. Allowed sysctls: %v", [sysctl, input.review.object.metadata.name, allowmsg])
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
# * may be used to forbid all sysctls
|
| 106 |
+
forbidden_sysctl(_) {
|
| 107 |
+
input.parameters.forbiddenSysctls[_] == "*"
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
forbidden_sysctl(sysctl) {
|
| 111 |
+
input.parameters.forbiddenSysctls[_] == sysctl
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
forbidden_sysctl(sysctl) {
|
| 115 |
+
forbidden := input.parameters.forbiddenSysctls[_]
|
| 116 |
+
endswith(forbidden, "*")
|
| 117 |
+
startswith(sysctl, trim_suffix(forbidden, "*"))
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
# * may be used to allow all sysctls
|
| 121 |
+
allowed_sysctl(_) {
|
| 122 |
+
input.parameters.allowedSysctls[_] == "*"
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
allowed_sysctl(sysctl) {
|
| 126 |
+
input.parameters.allowedSysctls[_] == sysctl
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
allowed_sysctl(sysctl) {
|
| 130 |
+
allowed := input.parameters.allowedSysctls[_]
|
| 131 |
+
endswith(allowed, "*")
|
| 132 |
+
startswith(sysctl, trim_suffix(allowed, "*"))
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
allowed_sysctl(_) {
|
| 136 |
+
not input.parameters.allowedSysctls
|
| 137 |
+
}
|
| 138 |
+
allowed_sysctl_string() = out {
|
| 139 |
+
not input.parameters.allowedSysctls
|
| 140 |
+
out = "unspecified"
|
| 141 |
+
}
|
| 142 |
+
allowed_sysctl_string() = out {
|
| 143 |
+
out = input.parameters.allowedSysctls
|
| 144 |
+
}
|
| 145 |
+
libs:
|
| 146 |
+
- |
|
| 147 |
+
package lib.exclude_update
|
| 148 |
+
|
| 149 |
+
is_update(review) {
|
| 150 |
+
review.operation == "UPDATE"
|
| 151 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Deprecated
|
| 2 |
+
|
| 3 |
+
**This Policy is deprecated**
|
| 4 |
+
|
| 5 |
+
Please use the FSGroup settings on the users policy to enforce FSGroup Settings.
|
| 6 |
+
|
| 7 |
+
[Users Policy](../users)
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/constraint.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPFSGroup
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-fsgroup
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
rule: "MayRunAs" #"MustRunAs" #"MayRunAs", "RunAsAny"
|
| 12 |
+
ranges:
|
| 13 |
+
- min: 1
|
| 14 |
+
max: 1000
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/constraint2.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPFSGroup
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-fsgroup
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
ranges:
|
| 12 |
+
- min: 1
|
| 13 |
+
max: 1000
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/constraint3.yaml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPFSGroup
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-fsgroup
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
rule: "MustRunAs" #"MayRunAs", "RunAsAny"
|
| 12 |
+
ranges: [] # empty ranges should result in violation
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/example_allowed.yaml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: fsgroup-allowed
|
| 5 |
+
spec:
|
| 6 |
+
securityContext:
|
| 7 |
+
fsGroup: 500 # directory will have group ID 500
|
| 8 |
+
volumes:
|
| 9 |
+
- name: fsgroup-demo-vol
|
| 10 |
+
emptyDir: {}
|
| 11 |
+
containers:
|
| 12 |
+
- name: fsgroup-demo
|
| 13 |
+
image: busybox
|
| 14 |
+
command: ["sh", "-c", "sleep 1h"]
|
| 15 |
+
volumeMounts:
|
| 16 |
+
- name: fsgroup-demo-vol
|
| 17 |
+
mountPath: /data/demo
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: fsgroup-disallowed
|
| 5 |
+
spec:
|
| 6 |
+
securityContext:
|
| 7 |
+
fsGroup: 2000 # directory will have group ID 2000
|
| 8 |
+
volumes:
|
| 9 |
+
- name: fsgroup-demo-vol
|
| 10 |
+
emptyDir: {}
|
| 11 |
+
containers:
|
| 12 |
+
- name: fsgroup-demo
|
| 13 |
+
image: busybox
|
| 14 |
+
command: [ "sh", "-c", "sleep 1h" ]
|
| 15 |
+
volumeMounts:
|
| 16 |
+
- name: fsgroup-demo-vol
|
| 17 |
+
mountPath: /data/demo
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/samples/psp-fsgroup/update.yaml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: AdmissionReview
|
| 2 |
+
apiVersion: admission.k8s.io/v1beta1
|
| 3 |
+
request:
|
| 4 |
+
operation: "UPDATE"
|
| 5 |
+
object:
|
| 6 |
+
apiVersion: v1
|
| 7 |
+
kind: Pod
|
| 8 |
+
metadata:
|
| 9 |
+
name: fsgroup-disallowed
|
| 10 |
+
spec:
|
| 11 |
+
securityContext:
|
| 12 |
+
fsGroup: 2000 # directory will have group ID 2000
|
| 13 |
+
volumes:
|
| 14 |
+
- name: fsgroup-demo-vol
|
| 15 |
+
emptyDir: {}
|
| 16 |
+
containers:
|
| 17 |
+
- name: fsgroup-demo
|
| 18 |
+
image: busybox
|
| 19 |
+
command: [ "sh", "-c", "sleep 1h" ]
|
| 20 |
+
volumeMounts:
|
| 21 |
+
- name: fsgroup-demo-vol
|
| 22 |
+
mountPath: /data/demo
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/suite.yaml
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: fsgroup
|
| 5 |
+
tests:
|
| 6 |
+
- name: fsgroup
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/psp-fsgroup/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-disallowed
|
| 11 |
+
object: samples/psp-fsgroup/example_disallowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: yes
|
| 14 |
+
- name: example-allowed
|
| 15 |
+
object: samples/psp-fsgroup/example_allowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: no
|
| 18 |
+
- name: update
|
| 19 |
+
object: samples/psp-fsgroup/update.yaml
|
| 20 |
+
assertions:
|
| 21 |
+
- violations: no
|
| 22 |
+
- name: fsgroup-no-rules
|
| 23 |
+
template: template.yaml
|
| 24 |
+
constraint: samples/psp-fsgroup/constraint2.yaml
|
| 25 |
+
cases:
|
| 26 |
+
- name: example-allowed
|
| 27 |
+
object: samples/psp-fsgroup/example_disallowed.yaml
|
| 28 |
+
assertions:
|
| 29 |
+
- violations: no
|
| 30 |
+
- name: example-allowed
|
| 31 |
+
object: samples/psp-fsgroup/example_allowed.yaml
|
| 32 |
+
assertions:
|
| 33 |
+
- violations: no
|
| 34 |
+
- name: update
|
| 35 |
+
object: samples/psp-fsgroup/update.yaml
|
| 36 |
+
assertions:
|
| 37 |
+
- violations: no
|
| 38 |
+
- name: fsgroup-empty-ranges
|
| 39 |
+
template: template.yaml
|
| 40 |
+
constraint: samples/psp-fsgroup/constraint3.yaml
|
| 41 |
+
cases:
|
| 42 |
+
- name: example-disallowed-2000
|
| 43 |
+
object: samples/psp-fsgroup/example_disallowed.yaml
|
| 44 |
+
assertions:
|
| 45 |
+
- violations: yes
|
| 46 |
+
- name: example-disallowed-500
|
| 47 |
+
object: samples/psp-fsgroup/example_allowed.yaml
|
| 48 |
+
assertions:
|
| 49 |
+
- violations: yes
|
| 50 |
+
- name: update
|
| 51 |
+
object: samples/psp-fsgroup/update.yaml
|
| 52 |
+
assertions:
|
| 53 |
+
- violations: no
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/fsgroup/template.yaml
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8spspfsgroup
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "FS Group"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.1.0
|
| 8 |
+
description: >-
|
| 9 |
+
Controls allocating an FSGroup that owns the Pod's volumes. Corresponds
|
| 10 |
+
to the `fsGroup` field in a PodSecurityPolicy. For more information, see
|
| 11 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#volumes-and-file-systems
|
| 12 |
+
spec:
|
| 13 |
+
crd:
|
| 14 |
+
spec:
|
| 15 |
+
names:
|
| 16 |
+
kind: K8sPSPFSGroup
|
| 17 |
+
validation:
|
| 18 |
+
# Schema for the `parameters` field
|
| 19 |
+
openAPIV3Schema:
|
| 20 |
+
type: object
|
| 21 |
+
description: >-
|
| 22 |
+
Controls allocating an FSGroup that owns the Pod's volumes. Corresponds
|
| 23 |
+
to the `fsGroup` field in a PodSecurityPolicy. For more information, see
|
| 24 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#volumes-and-file-systems
|
| 25 |
+
properties:
|
| 26 |
+
rule:
|
| 27 |
+
description: "An FSGroup rule name."
|
| 28 |
+
enum:
|
| 29 |
+
- MayRunAs
|
| 30 |
+
- MustRunAs
|
| 31 |
+
- RunAsAny
|
| 32 |
+
type: string
|
| 33 |
+
ranges:
|
| 34 |
+
type: array
|
| 35 |
+
description: "GID ranges affected by the rule."
|
| 36 |
+
items:
|
| 37 |
+
type: object
|
| 38 |
+
properties:
|
| 39 |
+
min:
|
| 40 |
+
description: "The minimum GID in the range, inclusive."
|
| 41 |
+
type: integer
|
| 42 |
+
max:
|
| 43 |
+
description: "The maximum GID in the range, inclusive."
|
| 44 |
+
type: integer
|
| 45 |
+
targets:
|
| 46 |
+
- target: admission.k8s.gatekeeper.sh
|
| 47 |
+
code:
|
| 48 |
+
- engine: K8sNativeValidation
|
| 49 |
+
source:
|
| 50 |
+
variables:
|
| 51 |
+
- name: isUpdate
|
| 52 |
+
expression: has(request.operation) && request.operation == "UPDATE"
|
| 53 |
+
- name: fsGroup
|
| 54 |
+
expression: '!has(variables.anyObject.spec.securityContext) ? "" : !has(variables.anyObject.spec.securityContext.fsGroup) ? "" : variables.anyObject.spec.securityContext.fsGroup'
|
| 55 |
+
- name: ruleString
|
| 56 |
+
expression: |
|
| 57 |
+
!has(variables.params.rule) ? "unspecified" : string(variables.params.rule)
|
| 58 |
+
- name: rangesString
|
| 59 |
+
expression: |
|
| 60 |
+
!has(variables.params.ranges) ? "unspecified" : size(variables.params.ranges) == 0 ? "empty" : variables.params.ranges.map(r, string(r)).join(", ")
|
| 61 |
+
- name: input_fsGroup_allowed
|
| 62 |
+
expression: |
|
| 63 |
+
!has(variables.params.rule) ? true : variables.params.rule == "RunAsAny" ? true : variables.params.rule == "MayRunAs" && variables.fsGroup == "" ? true : (variables.params.rule == "MayRunAs" || variables.params.rule == "MustRunAs") && has(variables.params.ranges) && size(variables.params.ranges) > 0 ? variables.params.ranges.exists(range, range.min <= variables.fsGroup && range.max >= variables.fsGroup) : false
|
| 64 |
+
validations:
|
| 65 |
+
- expression: 'variables.isUpdate || variables.input_fsGroup_allowed'
|
| 66 |
+
messageExpression: '"The provided pod spec fsGroup is not allowed, pod: " + variables.anyObject.metadata.name + ". Allowed fsGroup rule: " + variables.ruleString + ", allowed fsGroup ranges: " + variables.rangesString'
|
| 67 |
+
- engine: Rego
|
| 68 |
+
source:
|
| 69 |
+
rego: |
|
| 70 |
+
package k8spspfsgroup
|
| 71 |
+
|
| 72 |
+
import data.lib.exclude_update.is_update
|
| 73 |
+
|
| 74 |
+
violation[{"msg": msg, "details": {}}] {
|
| 75 |
+
# spec.securityContext.fsGroup field is immutable.
|
| 76 |
+
not is_update(input.review)
|
| 77 |
+
has_field(input.parameters, "rule")
|
| 78 |
+
spec := input.review.object.spec
|
| 79 |
+
not input_fsGroup_allowed(spec)
|
| 80 |
+
msg := sprintf("The provided pod spec fsGroup is not allowed, pod: %v. Allowed fsGroup: %v", [input.review.object.metadata.name, input.parameters])
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
input_fsGroup_allowed(_) {
|
| 84 |
+
# RunAsAny - No range is required. Allows any fsGroup ID to be specified.
|
| 85 |
+
input.parameters.rule == "RunAsAny"
|
| 86 |
+
}
|
| 87 |
+
input_fsGroup_allowed(spec) {
|
| 88 |
+
# MustRunAs - Validates pod spec fsgroup against all ranges
|
| 89 |
+
input.parameters.rule == "MustRunAs"
|
| 90 |
+
fg := spec.securityContext.fsGroup
|
| 91 |
+
count(input.parameters.ranges) > 0
|
| 92 |
+
range := input.parameters.ranges[_]
|
| 93 |
+
value_within_range(range, fg)
|
| 94 |
+
}
|
| 95 |
+
input_fsGroup_allowed(spec) {
|
| 96 |
+
# MayRunAs - Validates pod spec fsgroup against all ranges or allow pod spec fsgroup to be left unset
|
| 97 |
+
input.parameters.rule == "MayRunAs"
|
| 98 |
+
not has_field(spec, "securityContext")
|
| 99 |
+
}
|
| 100 |
+
input_fsGroup_allowed(spec) {
|
| 101 |
+
# MayRunAs - Validates pod spec fsgroup against all ranges or allow pod spec fsgroup to be left unset
|
| 102 |
+
input.parameters.rule == "MayRunAs"
|
| 103 |
+
not spec.securityContext.fsGroup
|
| 104 |
+
}
|
| 105 |
+
input_fsGroup_allowed(spec) {
|
| 106 |
+
# MayRunAs - Validates pod spec fsgroup against all ranges or allow pod spec fsgroup to be left unset
|
| 107 |
+
input.parameters.rule == "MayRunAs"
|
| 108 |
+
fg := spec.securityContext.fsGroup
|
| 109 |
+
count(input.parameters.ranges) > 0
|
| 110 |
+
range := input.parameters.ranges[_]
|
| 111 |
+
value_within_range(range, fg)
|
| 112 |
+
}
|
| 113 |
+
value_within_range(range, value) {
|
| 114 |
+
range.min <= value
|
| 115 |
+
range.max >= value
|
| 116 |
+
}
|
| 117 |
+
# has_field returns whether an object has a field
|
| 118 |
+
has_field(object, field) = true {
|
| 119 |
+
object[field]
|
| 120 |
+
}
|
| 121 |
+
libs:
|
| 122 |
+
- |
|
| 123 |
+
package lib.exclude_update
|
| 124 |
+
|
| 125 |
+
is_update(review) {
|
| 126 |
+
review.operation == "UPDATE"
|
| 127 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/no-host-paths/constraint.yaml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostFilesystem
|
| 3 |
+
metadata:
|
| 4 |
+
name: no-host-paths
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/no-host-paths/example_allowed_no_volumes.yaml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-no-volumes
|
| 5 |
+
spec:
|
| 6 |
+
containers:
|
| 7 |
+
- name: nginx
|
| 8 |
+
image: nginx
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/psp-host-filesystem/constraint.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostFilesystem
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-filesystem
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
allowedHostPaths:
|
| 12 |
+
- readOnly: true
|
| 13 |
+
pathPrefix: "/foo"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/psp-host-filesystem/disallowed_ephemeral.yaml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-filesystem
|
| 5 |
+
spec:
|
| 6 |
+
ephemeralContainers:
|
| 7 |
+
- name: nginx
|
| 8 |
+
image: nginx
|
| 9 |
+
volumeMounts:
|
| 10 |
+
- mountPath: /cache
|
| 11 |
+
name: cache-volume
|
| 12 |
+
readOnly: true
|
| 13 |
+
volumes:
|
| 14 |
+
- name: cache-volume
|
| 15 |
+
hostPath:
|
| 16 |
+
path: /tmp # directory location on host
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/psp-host-filesystem/example_allowed.yaml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-filesystem
|
| 5 |
+
spec:
|
| 6 |
+
containers:
|
| 7 |
+
- name: nginx
|
| 8 |
+
image: nginx
|
| 9 |
+
volumeMounts:
|
| 10 |
+
- mountPath: /cache
|
| 11 |
+
name: cache-volume
|
| 12 |
+
readOnly: true
|
| 13 |
+
volumes:
|
| 14 |
+
- name: cache-volume
|
| 15 |
+
hostPath:
|
| 16 |
+
path: /foo/bar
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/psp-host-filesystem/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-filesystem
|
| 5 |
+
spec:
|
| 6 |
+
containers:
|
| 7 |
+
- name: nginx
|
| 8 |
+
image: nginx
|
| 9 |
+
volumeMounts:
|
| 10 |
+
- mountPath: /cache
|
| 11 |
+
name: cache-volume
|
| 12 |
+
readOnly: true
|
| 13 |
+
volumes:
|
| 14 |
+
- name: cache-volume
|
| 15 |
+
hostPath:
|
| 16 |
+
path: /tmp # directory location on host
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/samples/psp-host-filesystem/update.yaml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: AdmissionReview
|
| 2 |
+
apiVersion: admission.k8s.io/v1beta1
|
| 3 |
+
request:
|
| 4 |
+
operation: "UPDATE"
|
| 5 |
+
object:
|
| 6 |
+
apiVersion: v1
|
| 7 |
+
kind: Pod
|
| 8 |
+
metadata:
|
| 9 |
+
name: nginx-host-filesystem
|
| 10 |
+
labels:
|
| 11 |
+
app: nginx-host-filesystem-disallowed
|
| 12 |
+
spec:
|
| 13 |
+
containers:
|
| 14 |
+
- name: nginx
|
| 15 |
+
image: nginx
|
| 16 |
+
volumeMounts:
|
| 17 |
+
- mountPath: /cache
|
| 18 |
+
name: cache-volume
|
| 19 |
+
readOnly: true
|
| 20 |
+
volumes:
|
| 21 |
+
- name: cache-volume
|
| 22 |
+
hostPath:
|
| 23 |
+
path: /tmp # directory location on host
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/suite.yaml
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: host-filesystem
|
| 5 |
+
tests:
|
| 6 |
+
- name: host-filesystem
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/psp-host-filesystem/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-disallowed
|
| 11 |
+
object: samples/psp-host-filesystem/example_disallowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: yes
|
| 14 |
+
- name: example-allowed
|
| 15 |
+
object: samples/psp-host-filesystem/example_allowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: no
|
| 18 |
+
- name: disallowed-ephemeral
|
| 19 |
+
object: samples/psp-host-filesystem/disallowed_ephemeral.yaml
|
| 20 |
+
assertions:
|
| 21 |
+
- violations: yes
|
| 22 |
+
- name: update
|
| 23 |
+
object: samples/psp-host-filesystem/update.yaml
|
| 24 |
+
assertions:
|
| 25 |
+
- violations: no
|
| 26 |
+
- name: no-host-paths
|
| 27 |
+
template: template.yaml
|
| 28 |
+
constraint: samples/no-host-paths/constraint.yaml
|
| 29 |
+
cases:
|
| 30 |
+
- name: previously-allowed-path-disallowed
|
| 31 |
+
object: samples/psp-host-filesystem/example_allowed.yaml
|
| 32 |
+
assertions:
|
| 33 |
+
- violations: yes
|
| 34 |
+
- name: no-volumes-is-allowed
|
| 35 |
+
object: samples/no-host-paths/example_allowed_no_volumes.yaml
|
| 36 |
+
assertions:
|
| 37 |
+
- violations: no
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/library/pod-security-policy/host-filesystem/template.yaml
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8spsphostfilesystem
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Host Filesystem"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.1.2
|
| 8 |
+
metadata.gatekeeper.sh/bundle: "pod-security-baseline, pod-security-restricted"
|
| 9 |
+
description: >-
|
| 10 |
+
Controls usage of the host filesystem. Corresponds to the
|
| 11 |
+
`allowedHostPaths` field in a PodSecurityPolicy. For more information,
|
| 12 |
+
see
|
| 13 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#volumes-and-file-systems
|
| 14 |
+
spec:
|
| 15 |
+
crd:
|
| 16 |
+
spec:
|
| 17 |
+
names:
|
| 18 |
+
kind: K8sPSPHostFilesystem
|
| 19 |
+
validation:
|
| 20 |
+
# Schema for the `parameters` field
|
| 21 |
+
openAPIV3Schema:
|
| 22 |
+
type: object
|
| 23 |
+
description: >-
|
| 24 |
+
Controls usage of the host filesystem. Corresponds to the
|
| 25 |
+
`allowedHostPaths` field in a PodSecurityPolicy. For more information,
|
| 26 |
+
see
|
| 27 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#volumes-and-file-systems
|
| 28 |
+
properties:
|
| 29 |
+
allowedHostPaths:
|
| 30 |
+
type: array
|
| 31 |
+
description: "An array of hostpath objects, representing paths and read/write configuration."
|
| 32 |
+
items:
|
| 33 |
+
type: object
|
| 34 |
+
properties:
|
| 35 |
+
pathPrefix:
|
| 36 |
+
type: string
|
| 37 |
+
description: "The path prefix that the host volume must match."
|
| 38 |
+
readOnly:
|
| 39 |
+
type: boolean
|
| 40 |
+
description: "when set to true, any container volumeMounts matching the pathPrefix must include `readOnly: true`."
|
| 41 |
+
targets:
|
| 42 |
+
- target: admission.k8s.gatekeeper.sh
|
| 43 |
+
code:
|
| 44 |
+
- engine: K8sNativeValidation
|
| 45 |
+
source:
|
| 46 |
+
variables:
|
| 47 |
+
- name: containers
|
| 48 |
+
expression: 'has(variables.anyObject.spec.containers) ? variables.anyObject.spec.containers : []'
|
| 49 |
+
- name: initContainers
|
| 50 |
+
expression: 'has(variables.anyObject.spec.initContainers) ? variables.anyObject.spec.initContainers : []'
|
| 51 |
+
- name: ephemeralContainers
|
| 52 |
+
expression: 'has(variables.anyObject.spec.ephemeralContainers) ? variables.anyObject.spec.ephemeralContainers : []'
|
| 53 |
+
- name: allContainers
|
| 54 |
+
expression: 'variables.containers + variables.initContainers + variables.ephemeralContainers'
|
| 55 |
+
- name: allowedPaths
|
| 56 |
+
expression: |
|
| 57 |
+
!has(variables.params.allowedHostPaths) ? [] : variables.params.allowedHostPaths
|
| 58 |
+
- name: volumes
|
| 59 |
+
expression: |
|
| 60 |
+
!has(variables.anyObject.spec.volumes) ? [] : variables.anyObject.spec.volumes.filter(volume, has(volume.hostPath))
|
| 61 |
+
- name: badHostPaths
|
| 62 |
+
expression: |
|
| 63 |
+
variables.volumes.filter(volume,
|
| 64 |
+
(size(variables.allowedPaths) == 0) ||
|
| 65 |
+
!(variables.allowedPaths.exists(allowedPath,
|
| 66 |
+
volume.hostPath.path.startsWith(allowedPath.pathPrefix) && (
|
| 67 |
+
(!has(allowedPath.readOnly) || !(allowedPath.readOnly)) ||
|
| 68 |
+
(has(allowedPath.readOnly) && allowedPath.readOnly && !variables.allContainers.exists(c,
|
| 69 |
+
c.volumeMounts.exists(m, m.name == volume.name && (!has(m.readOnly) || !m.readOnly)))))))
|
| 70 |
+
).map(volume, "{ hostPath: { path : " + volume.hostPath.path + " }, name: " + volume.name + "}").map(volume, "HostPath volume " + volume + " is not allowed, pod: " + object.metadata.name + ". Allowed path: " + variables.allowedPaths.map(path, path.pathPrefix + ", readOnly: " + (path.readOnly ? "true" : "false") + "}").join(", "))
|
| 71 |
+
validations:
|
| 72 |
+
- expression: '(has(request.operation) && request.operation == "UPDATE") || size(variables.badHostPaths) == 0'
|
| 73 |
+
messageExpression: 'variables.badHostPaths.join("\n")'
|
| 74 |
+
- engine: Rego
|
| 75 |
+
source:
|
| 76 |
+
rego: |
|
| 77 |
+
package k8spsphostfilesystem
|
| 78 |
+
|
| 79 |
+
import data.lib.exclude_update.is_update
|
| 80 |
+
|
| 81 |
+
violation[{"msg": msg, "details": {}}] {
|
| 82 |
+
# spec.volumes field is immutable.
|
| 83 |
+
not is_update(input.review)
|
| 84 |
+
|
| 85 |
+
volume := input_hostpath_volumes[_]
|
| 86 |
+
allowedPaths := get_allowed_paths(input)
|
| 87 |
+
input_hostpath_violation(allowedPaths, volume)
|
| 88 |
+
msg := sprintf("HostPath volume %v is not allowed, pod: %v. Allowed path: %v", [volume, input.review.object.metadata.name, allowedPaths])
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
input_hostpath_violation(allowedPaths, _) {
|
| 92 |
+
# An empty list means all host paths are blocked
|
| 93 |
+
allowedPaths == []
|
| 94 |
+
}
|
| 95 |
+
input_hostpath_violation(allowedPaths, volume) {
|
| 96 |
+
not input_hostpath_allowed(allowedPaths, volume)
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
get_allowed_paths(arg) = out {
|
| 100 |
+
not arg.parameters
|
| 101 |
+
out = []
|
| 102 |
+
}
|
| 103 |
+
get_allowed_paths(arg) = out {
|
| 104 |
+
not arg.parameters.allowedHostPaths
|
| 105 |
+
out = []
|
| 106 |
+
}
|
| 107 |
+
get_allowed_paths(arg) = out {
|
| 108 |
+
out = arg.parameters.allowedHostPaths
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
input_hostpath_allowed(allowedPaths, volume) {
|
| 112 |
+
allowedHostPath := allowedPaths[_]
|
| 113 |
+
path_matches(allowedHostPath.pathPrefix, volume.hostPath.path)
|
| 114 |
+
not allowedHostPath.readOnly == true
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
input_hostpath_allowed(allowedPaths, volume) {
|
| 118 |
+
allowedHostPath := allowedPaths[_]
|
| 119 |
+
path_matches(allowedHostPath.pathPrefix, volume.hostPath.path)
|
| 120 |
+
allowedHostPath.readOnly
|
| 121 |
+
not writeable_input_volume_mounts(volume.name)
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
writeable_input_volume_mounts(volume_name) {
|
| 125 |
+
container := input_containers[_]
|
| 126 |
+
mount := container.volumeMounts[_]
|
| 127 |
+
mount.name == volume_name
|
| 128 |
+
not mount.readOnly
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
# This allows "/foo", "/foo/", "/foo/bar" etc., but
|
| 132 |
+
# disallows "/fool", "/etc/foo" etc.
|
| 133 |
+
path_matches(prefix, path) {
|
| 134 |
+
a := path_array(prefix)
|
| 135 |
+
b := path_array(path)
|
| 136 |
+
prefix_matches(a, b)
|
| 137 |
+
}
|
| 138 |
+
path_array(p) = out {
|
| 139 |
+
p != "/"
|
| 140 |
+
out := split(trim(p, "/"), "/")
|
| 141 |
+
}
|
| 142 |
+
# This handles the special case for "/", since
|
| 143 |
+
# split(trim("/", "/"), "/") == [""]
|
| 144 |
+
path_array("/") = []
|
| 145 |
+
|
| 146 |
+
prefix_matches(a, b) {
|
| 147 |
+
count(a) <= count(b)
|
| 148 |
+
not any_not_equal_upto(a, b, count(a))
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
any_not_equal_upto(a, b, n) {
|
| 152 |
+
a[i] != b[i]
|
| 153 |
+
i < n
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
input_hostpath_volumes[v] {
|
| 157 |
+
v := input.review.object.spec.volumes[_]
|
| 158 |
+
has_field(v, "hostPath")
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
# has_field returns whether an object has a field
|
| 162 |
+
has_field(object, field) = true {
|
| 163 |
+
object[field]
|
| 164 |
+
}
|
| 165 |
+
input_containers[c] {
|
| 166 |
+
c := input.review.object.spec.containers[_]
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
input_containers[c] {
|
| 170 |
+
c := input.review.object.spec.initContainers[_]
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
input_containers[c] {
|
| 174 |
+
c := input.review.object.spec.ephemeralContainers[_]
|
| 175 |
+
}
|
| 176 |
+
libs:
|
| 177 |
+
- |
|
| 178 |
+
package lib.exclude_update
|
| 179 |
+
|
| 180 |
+
is_update(review) {
|
| 181 |
+
review.operation == "UPDATE"
|
| 182 |
+
}
|