Datasets:
Add pinned source: gatekeeper-library (part 5)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/samples/psp-host-network-ports/constraint_block_host_network.yaml +11 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/samples/psp-host-network-ports/disallowed_ephemeral.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/samples/psp-host-network-ports/example_allowed.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/samples/psp-host-network-ports/example_disallowed.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/samples/psp-host-network-ports/update.yaml +19 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/suite.yaml +45 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/template.yaml +156 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/artifacthub-pkg.yml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/constraint.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/constraint_block_host_network.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/disallowed_ephemeral.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/example_allowed.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/example_disallowed.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/update.yaml +19 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/suite.yaml +45 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/template.yaml +159 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/artifacthub-pkg.yml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/constraint.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/constraint_block_host_network.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/disallowed_ephemeral.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/example_allowed.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/example_allowed_no_ports.yaml +11 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/example_disallowed.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/update.yaml +19 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/suite.yaml +50 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/template.yaml +159 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/artifacthub-pkg.yml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/block_host_network/constraint.yaml +11 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/port_range_block_host_network/constraint.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/port_range_block_host_network/example_disallowed_out_of_range_host_network_true.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/constraint.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/disallowed_ephemeral.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/example_allowed_in_range.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/example_allowed_no_ports.yaml +11 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/example_allowed_no_ports_host_network_false.yaml +9 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/example_allowed_no_ports_host_network_true.yaml +9 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/update.yaml +19 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/suite.yaml +62 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/template.yaml +165 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/artifacthub-pkg.yml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/block_host_network/constraint.yaml +11 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/port_range_block_host_network/constraint.yaml +15 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/port_range_block_host_network/example_disallowed_exempted_container_host_network_enabled.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/port_range_block_host_network/example_disallowed_out_of_range_host_network_true.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/psp-host-network-ports/constraint.yaml +15 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/psp-host-network-ports/disallowed_ephemeral.yaml +14 -0
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/samples/psp-host-network-ports/constraint_block_host_network.yaml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostNetworkingPorts
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-network
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
hostNetwork: false
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/samples/psp-host-network-ports/disallowed_ephemeral.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
ephemeralContainers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9001
|
| 14 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/samples/psp-host-network-ports/example_allowed.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-allowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: false
|
| 9 |
+
containers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9000
|
| 14 |
+
hostPort: 80
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/samples/psp-host-network-ports/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
containers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9001
|
| 14 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/samples/psp-host-network-ports/update.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-networking-ports-disallowed
|
| 10 |
+
labels:
|
| 11 |
+
app: nginx-host-networking-ports
|
| 12 |
+
spec:
|
| 13 |
+
hostNetwork: true
|
| 14 |
+
containers:
|
| 15 |
+
- name: nginx
|
| 16 |
+
image: nginx
|
| 17 |
+
ports:
|
| 18 |
+
- containerPort: 9001
|
| 19 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/suite.yaml
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: host-network-ports
|
| 5 |
+
tests:
|
| 6 |
+
- name: use-of-host-networking-ports-blocked
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/psp-host-network-ports/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-disallowed
|
| 11 |
+
object: samples/psp-host-network-ports/example_disallowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: yes
|
| 14 |
+
- name: example-allowed
|
| 15 |
+
object: samples/psp-host-network-ports/example_allowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: no
|
| 18 |
+
- name: disallowed-ephemeral
|
| 19 |
+
object: samples/psp-host-network-ports/disallowed_ephemeral.yaml
|
| 20 |
+
assertions:
|
| 21 |
+
- violations: yes
|
| 22 |
+
- name: update
|
| 23 |
+
object: samples/psp-host-network-ports/update.yaml
|
| 24 |
+
assertions:
|
| 25 |
+
- violations: no
|
| 26 |
+
- name: use-of-host-network-blocked
|
| 27 |
+
template: template.yaml
|
| 28 |
+
constraint: samples/psp-host-network-ports/constraint_block_host_network.yaml
|
| 29 |
+
cases:
|
| 30 |
+
- name: example-disallowed
|
| 31 |
+
object: samples/psp-host-network-ports/example_disallowed.yaml
|
| 32 |
+
assertions:
|
| 33 |
+
- violations: yes
|
| 34 |
+
- name: example-allowed
|
| 35 |
+
object: samples/psp-host-network-ports/example_allowed.yaml
|
| 36 |
+
assertions:
|
| 37 |
+
- violations: no
|
| 38 |
+
- name: disallowed-ephemeral
|
| 39 |
+
object: samples/psp-host-network-ports/disallowed_ephemeral.yaml
|
| 40 |
+
assertions:
|
| 41 |
+
- violations: yes
|
| 42 |
+
- name: update
|
| 43 |
+
object: samples/psp-host-network-ports/update.yaml
|
| 44 |
+
assertions:
|
| 45 |
+
- violations: no
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.0/template.yaml
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8spsphostnetworkingports
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Host Networking Ports"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.1.0
|
| 8 |
+
description: >-
|
| 9 |
+
Controls usage of host network namespace by pod containers. Specific
|
| 10 |
+
ports must be specified. Corresponds to the `hostNetwork` and
|
| 11 |
+
`hostPorts` fields in a PodSecurityPolicy. For more information, see
|
| 12 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 13 |
+
spec:
|
| 14 |
+
crd:
|
| 15 |
+
spec:
|
| 16 |
+
names:
|
| 17 |
+
kind: K8sPSPHostNetworkingPorts
|
| 18 |
+
validation:
|
| 19 |
+
# Schema for the `parameters` field
|
| 20 |
+
openAPIV3Schema:
|
| 21 |
+
type: object
|
| 22 |
+
description: >-
|
| 23 |
+
Controls usage of host network namespace by pod containers. Specific
|
| 24 |
+
ports must be specified. Corresponds to the `hostNetwork` and
|
| 25 |
+
`hostPorts` fields in a PodSecurityPolicy. For more information, see
|
| 26 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 27 |
+
properties:
|
| 28 |
+
exemptImages:
|
| 29 |
+
description: >-
|
| 30 |
+
Any container that uses an image that matches an entry in this list will be excluded
|
| 31 |
+
from enforcement. Prefix-matching can be signified with `*`. For example: `my-image-*`.
|
| 32 |
+
|
| 33 |
+
It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name)
|
| 34 |
+
in order to avoid unexpectedly exempting images from an untrusted repository.
|
| 35 |
+
type: array
|
| 36 |
+
items:
|
| 37 |
+
type: string
|
| 38 |
+
hostNetwork:
|
| 39 |
+
description: "Determines if the policy allows the use of HostNetwork in the pod spec."
|
| 40 |
+
type: boolean
|
| 41 |
+
min:
|
| 42 |
+
description: "The start of the allowed port range, inclusive."
|
| 43 |
+
type: integer
|
| 44 |
+
max:
|
| 45 |
+
description: "The end of the allowed port range, inclusive."
|
| 46 |
+
type: integer
|
| 47 |
+
targets:
|
| 48 |
+
- target: admission.k8s.gatekeeper.sh
|
| 49 |
+
code:
|
| 50 |
+
- engine: K8sNativeValidation
|
| 51 |
+
source:
|
| 52 |
+
variables:
|
| 53 |
+
- name: containers
|
| 54 |
+
expression: 'has(variables.anyObject.spec.containers) ? variables.anyObject.spec.containers : []'
|
| 55 |
+
- name: initContainers
|
| 56 |
+
expression: 'has(variables.anyObject.spec.initContainers) ? variables.anyObject.spec.initContainers : []'
|
| 57 |
+
- name: ephemeralContainers
|
| 58 |
+
expression: 'has(variables.anyObject.spec.ephemeralContainers) ? variables.anyObject.spec.ephemeralContainers : []'
|
| 59 |
+
- name: exemptImagePrefixes
|
| 60 |
+
expression: |
|
| 61 |
+
!has(variables.params.exemptImages) ? [] :
|
| 62 |
+
variables.params.exemptImages.filter(image, image.endsWith("*")).map(image, string(image).replace("*", ""))
|
| 63 |
+
- name: exemptImageExplicit
|
| 64 |
+
expression: |
|
| 65 |
+
!has(variables.params.exemptImages) ? [] :
|
| 66 |
+
variables.params.exemptImages.filter(image, !image.endsWith("*"))
|
| 67 |
+
- name: exemptImages
|
| 68 |
+
expression: |
|
| 69 |
+
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
|
| 70 |
+
container.image in variables.exemptImageExplicit ||
|
| 71 |
+
variables.exemptImagePrefixes.exists(exemption, string(container.image).startsWith(exemption)))
|
| 72 |
+
- name: badContainers
|
| 73 |
+
expression: |
|
| 74 |
+
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
|
| 75 |
+
!(container.image in variables.exemptImages) &&
|
| 76 |
+
(
|
| 77 |
+
(!has(variables.params.hostNetwork) || !variables.params.hostNetwork ? (has(variables.anyObject.spec.hostNetwork) && variables.anyObject.spec.hostNetwork) : false) ||
|
| 78 |
+
(container.ports.all(port, has(port.hostPort) && has(variables.params.min) && port.hostPort < variables.params.min)) ||
|
| 79 |
+
(container.ports.all(port, has(port.hostPort) && has(variables.params.max) && port.hostPort > variables.params.max))
|
| 80 |
+
)
|
| 81 |
+
)
|
| 82 |
+
validations:
|
| 83 |
+
- expression: '(has(request.operation) && request.operation == "UPDATE") || size(variables.badContainers) == 0'
|
| 84 |
+
messageExpression: '"The specified hostNetwork and hostPort are not allowed, pod: " + variables.anyObject.metadata.name + ". Allowed values: " + variables.params'
|
| 85 |
+
- engine: Rego
|
| 86 |
+
source:
|
| 87 |
+
rego: |
|
| 88 |
+
package k8spsphostnetworkingports
|
| 89 |
+
|
| 90 |
+
import data.lib.exclude_update.is_update
|
| 91 |
+
import data.lib.exempt_container.is_exempt
|
| 92 |
+
|
| 93 |
+
violation[{"msg": msg, "details": {}}] {
|
| 94 |
+
# spec.hostNetwork field is immutable.
|
| 95 |
+
not is_update(input.review)
|
| 96 |
+
|
| 97 |
+
input_share_hostnetwork(input.review.object)
|
| 98 |
+
msg := sprintf("The specified hostNetwork and hostPort are not allowed, pod: %v. Allowed values: %v", [input.review.object.metadata.name, input.parameters])
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
input_share_hostnetwork(o) {
|
| 102 |
+
not input.parameters.hostNetwork
|
| 103 |
+
o.spec.hostNetwork
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
input_share_hostnetwork(_) {
|
| 107 |
+
hostPort := input_containers[_].ports[_].hostPort
|
| 108 |
+
hostPort < input.parameters.min
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
input_share_hostnetwork(_) {
|
| 112 |
+
hostPort := input_containers[_].ports[_].hostPort
|
| 113 |
+
hostPort > input.parameters.max
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
input_containers[c] {
|
| 117 |
+
c := input.review.object.spec.containers[_]
|
| 118 |
+
not is_exempt(c)
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
input_containers[c] {
|
| 122 |
+
c := input.review.object.spec.initContainers[_]
|
| 123 |
+
not is_exempt(c)
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
input_containers[c] {
|
| 127 |
+
c := input.review.object.spec.ephemeralContainers[_]
|
| 128 |
+
not is_exempt(c)
|
| 129 |
+
}
|
| 130 |
+
libs:
|
| 131 |
+
- |
|
| 132 |
+
package lib.exclude_update
|
| 133 |
+
|
| 134 |
+
is_update(review) {
|
| 135 |
+
review.operation == "UPDATE"
|
| 136 |
+
}
|
| 137 |
+
- |
|
| 138 |
+
package lib.exempt_container
|
| 139 |
+
|
| 140 |
+
is_exempt(container) {
|
| 141 |
+
exempt_images := object.get(object.get(input, "parameters", {}), "exemptImages", [])
|
| 142 |
+
img := container.image
|
| 143 |
+
exemption := exempt_images[_]
|
| 144 |
+
_matches_exemption(img, exemption)
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
_matches_exemption(img, exemption) {
|
| 148 |
+
not endswith(exemption, "*")
|
| 149 |
+
exemption == img
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
_matches_exemption(img, exemption) {
|
| 153 |
+
endswith(exemption, "*")
|
| 154 |
+
prefix := trim_suffix(exemption, "*")
|
| 155 |
+
startswith(img, prefix)
|
| 156 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/artifacthub-pkg.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 1.1.1
|
| 2 |
+
name: k8spsphostnetworkingports
|
| 3 |
+
displayName: Host Networking Ports
|
| 4 |
+
createdAt: "2024-06-25T22:51:27Z"
|
| 5 |
+
description: Controls usage of host network namespace by pod containers. Specific ports must be specified. Corresponds to the `hostNetwork` and `hostPorts` fields in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 6 |
+
digest: e97c59805103b9bcdeec7d92aace619039df7262feb78a91d5657240c3d2700a
|
| 7 |
+
license: Apache-2.0
|
| 8 |
+
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/host-network-ports
|
| 9 |
+
keywords:
|
| 10 |
+
- gatekeeper
|
| 11 |
+
- open-policy-agent
|
| 12 |
+
- policies
|
| 13 |
+
readme: |-
|
| 14 |
+
# Host Networking Ports
|
| 15 |
+
Controls usage of host network namespace by pod containers. Specific ports must be specified. Corresponds to the `hostNetwork` and `hostPorts` fields in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 16 |
+
install: |-
|
| 17 |
+
### Usage
|
| 18 |
+
```shell
|
| 19 |
+
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/template.yaml
|
| 20 |
+
```
|
| 21 |
+
provider:
|
| 22 |
+
name: Gatekeeper Library
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/constraint.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostNetworkingPorts
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-network-ports
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
hostNetwork: true
|
| 12 |
+
min: 80
|
| 13 |
+
max: 9000
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/constraint_block_host_network.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostNetworkingPorts
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-network
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
hostNetwork: false
|
| 12 |
+
exemptImages:
|
| 13 |
+
- "nginx"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/disallowed_ephemeral.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
ephemeralContainers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9001
|
| 14 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/example_allowed.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-allowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: false
|
| 9 |
+
containers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9000
|
| 14 |
+
hostPort: 80
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
containers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9001
|
| 14 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/samples/psp-host-network-ports/update.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-networking-ports-disallowed
|
| 10 |
+
labels:
|
| 11 |
+
app: nginx-host-networking-ports
|
| 12 |
+
spec:
|
| 13 |
+
hostNetwork: true
|
| 14 |
+
containers:
|
| 15 |
+
- name: nginx
|
| 16 |
+
image: nginx
|
| 17 |
+
ports:
|
| 18 |
+
- containerPort: 9001
|
| 19 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/suite.yaml
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: host-network-ports
|
| 5 |
+
tests:
|
| 6 |
+
- name: use-of-host-networking-ports-blocked
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/psp-host-network-ports/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-disallowed
|
| 11 |
+
object: samples/psp-host-network-ports/example_disallowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: yes
|
| 14 |
+
- name: example-allowed
|
| 15 |
+
object: samples/psp-host-network-ports/example_allowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: no
|
| 18 |
+
- name: disallowed-ephemeral
|
| 19 |
+
object: samples/psp-host-network-ports/disallowed_ephemeral.yaml
|
| 20 |
+
assertions:
|
| 21 |
+
- violations: yes
|
| 22 |
+
- name: update
|
| 23 |
+
object: samples/psp-host-network-ports/update.yaml
|
| 24 |
+
assertions:
|
| 25 |
+
- violations: no
|
| 26 |
+
- name: use-of-host-network-blocked
|
| 27 |
+
template: template.yaml
|
| 28 |
+
constraint: samples/psp-host-network-ports/constraint_block_host_network.yaml
|
| 29 |
+
cases:
|
| 30 |
+
- name: example-disallowed
|
| 31 |
+
object: samples/psp-host-network-ports/example_disallowed.yaml
|
| 32 |
+
assertions:
|
| 33 |
+
- violations: yes
|
| 34 |
+
- name: example-allowed
|
| 35 |
+
object: samples/psp-host-network-ports/example_allowed.yaml
|
| 36 |
+
assertions:
|
| 37 |
+
- violations: no
|
| 38 |
+
- name: disallowed-ephemeral
|
| 39 |
+
object: samples/psp-host-network-ports/disallowed_ephemeral.yaml
|
| 40 |
+
assertions:
|
| 41 |
+
- violations: yes
|
| 42 |
+
- name: update
|
| 43 |
+
object: samples/psp-host-network-ports/update.yaml
|
| 44 |
+
assertions:
|
| 45 |
+
- violations: no
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.1/template.yaml
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8spsphostnetworkingports
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Host Networking Ports"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.1.1
|
| 8 |
+
description: >-
|
| 9 |
+
Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific
|
| 10 |
+
ports must be specified. Corresponds to the `hostNetwork` and
|
| 11 |
+
`hostPorts` fields in a PodSecurityPolicy. For more information, see
|
| 12 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 13 |
+
spec:
|
| 14 |
+
crd:
|
| 15 |
+
spec:
|
| 16 |
+
names:
|
| 17 |
+
kind: K8sPSPHostNetworkingPorts
|
| 18 |
+
validation:
|
| 19 |
+
# Schema for the `parameters` field
|
| 20 |
+
openAPIV3Schema:
|
| 21 |
+
type: object
|
| 22 |
+
description: >-
|
| 23 |
+
Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific
|
| 24 |
+
ports must be specified. Corresponds to the `hostNetwork` and
|
| 25 |
+
`hostPorts` fields in a PodSecurityPolicy. For more information, see
|
| 26 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 27 |
+
properties:
|
| 28 |
+
exemptImages:
|
| 29 |
+
description: >-
|
| 30 |
+
Any container that uses an image that matches an entry in this list will be excluded
|
| 31 |
+
from enforcement. Prefix-matching can be signified with `*`. For example: `my-image-*`.
|
| 32 |
+
|
| 33 |
+
It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name)
|
| 34 |
+
in order to avoid unexpectedly exempting images from an untrusted repository.
|
| 35 |
+
type: array
|
| 36 |
+
items:
|
| 37 |
+
type: string
|
| 38 |
+
hostNetwork:
|
| 39 |
+
description: "Determines if the policy allows the use of HostNetwork in the pod spec."
|
| 40 |
+
type: boolean
|
| 41 |
+
min:
|
| 42 |
+
description: "The start of the allowed port range, inclusive."
|
| 43 |
+
type: integer
|
| 44 |
+
max:
|
| 45 |
+
description: "The end of the allowed port range, inclusive."
|
| 46 |
+
type: integer
|
| 47 |
+
targets:
|
| 48 |
+
- target: admission.k8s.gatekeeper.sh
|
| 49 |
+
code:
|
| 50 |
+
- engine: K8sNativeValidation
|
| 51 |
+
source:
|
| 52 |
+
variables:
|
| 53 |
+
- name: containers
|
| 54 |
+
expression: 'has(variables.anyObject.spec.containers) ? variables.anyObject.spec.containers : []'
|
| 55 |
+
- name: initContainers
|
| 56 |
+
expression: 'has(variables.anyObject.spec.initContainers) ? variables.anyObject.spec.initContainers : []'
|
| 57 |
+
- name: ephemeralContainers
|
| 58 |
+
expression: 'has(variables.anyObject.spec.ephemeralContainers) ? variables.anyObject.spec.ephemeralContainers : []'
|
| 59 |
+
- name: exemptImagePrefixes
|
| 60 |
+
expression: |
|
| 61 |
+
!has(variables.params.exemptImages) ? [] :
|
| 62 |
+
variables.params.exemptImages.filter(image, image.endsWith("*")).map(image, string(image).replace("*", ""))
|
| 63 |
+
- name: exemptImageExplicit
|
| 64 |
+
expression: |
|
| 65 |
+
!has(variables.params.exemptImages) ? [] :
|
| 66 |
+
variables.params.exemptImages.filter(image, !image.endsWith("*"))
|
| 67 |
+
- name: exemptImages
|
| 68 |
+
expression: |
|
| 69 |
+
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
|
| 70 |
+
container.image in variables.exemptImageExplicit ||
|
| 71 |
+
variables.exemptImagePrefixes.exists(exemption, string(container.image).startsWith(exemption)))
|
| 72 |
+
- name: badContainers
|
| 73 |
+
expression: |
|
| 74 |
+
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
|
| 75 |
+
!(container.image in variables.exemptImages) &&
|
| 76 |
+
(
|
| 77 |
+
(container.ports.all(port, has(port.hostPort) && has(variables.params.min) && port.hostPort < variables.params.min)) ||
|
| 78 |
+
(container.ports.all(port, has(port.hostPort) && has(variables.params.max) && port.hostPort > variables.params.max))
|
| 79 |
+
)
|
| 80 |
+
)
|
| 81 |
+
validations:
|
| 82 |
+
- expression: '(has(request.operation) && request.operation == "UPDATE") || size(variables.badContainers) == 0'
|
| 83 |
+
messageExpression: '"The specified hostNetwork and hostPort are not allowed, pod: " + variables.anyObject.metadata.name + ". Allowed values: " + variables.params'
|
| 84 |
+
- expression: |
|
| 85 |
+
(has(request.operation) && request.operation == "UPDATE") ||
|
| 86 |
+
(!has(variables.params.hostNetwork) || !variables.params.hostNetwork ? (has(variables.anyObject.spec.hostNetwork) && !variables.anyObject.spec.hostNetwork) : true)
|
| 87 |
+
messageExpression: '"The specified hostNetwork and hostPort are not allowed, pod: " + variables.anyObject.metadata.name + ". Allowed values: " + variables.params'
|
| 88 |
+
- engine: Rego
|
| 89 |
+
source:
|
| 90 |
+
rego: |
|
| 91 |
+
package k8spsphostnetworkingports
|
| 92 |
+
|
| 93 |
+
import data.lib.exclude_update.is_update
|
| 94 |
+
import data.lib.exempt_container.is_exempt
|
| 95 |
+
|
| 96 |
+
violation[{"msg": msg, "details": {}}] {
|
| 97 |
+
# spec.hostNetwork field is immutable.
|
| 98 |
+
not is_update(input.review)
|
| 99 |
+
|
| 100 |
+
input_share_hostnetwork(input.review.object)
|
| 101 |
+
msg := sprintf("The specified hostNetwork and hostPort are not allowed, pod: %v. Allowed values: %v", [input.review.object.metadata.name, input.parameters])
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
input_share_hostnetwork(o) {
|
| 105 |
+
not input.parameters.hostNetwork
|
| 106 |
+
o.spec.hostNetwork
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
input_share_hostnetwork(_) {
|
| 110 |
+
hostPort := input_containers[_].ports[_].hostPort
|
| 111 |
+
hostPort < input.parameters.min
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
input_share_hostnetwork(_) {
|
| 115 |
+
hostPort := input_containers[_].ports[_].hostPort
|
| 116 |
+
hostPort > input.parameters.max
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
input_containers[c] {
|
| 120 |
+
c := input.review.object.spec.containers[_]
|
| 121 |
+
not is_exempt(c)
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
input_containers[c] {
|
| 125 |
+
c := input.review.object.spec.initContainers[_]
|
| 126 |
+
not is_exempt(c)
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
input_containers[c] {
|
| 130 |
+
c := input.review.object.spec.ephemeralContainers[_]
|
| 131 |
+
not is_exempt(c)
|
| 132 |
+
}
|
| 133 |
+
libs:
|
| 134 |
+
- |
|
| 135 |
+
package lib.exclude_update
|
| 136 |
+
|
| 137 |
+
is_update(review) {
|
| 138 |
+
review.operation == "UPDATE"
|
| 139 |
+
}
|
| 140 |
+
- |
|
| 141 |
+
package lib.exempt_container
|
| 142 |
+
|
| 143 |
+
is_exempt(container) {
|
| 144 |
+
exempt_images := object.get(object.get(input, "parameters", {}), "exemptImages", [])
|
| 145 |
+
img := container.image
|
| 146 |
+
exemption := exempt_images[_]
|
| 147 |
+
_matches_exemption(img, exemption)
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
_matches_exemption(img, exemption) {
|
| 151 |
+
not endswith(exemption, "*")
|
| 152 |
+
exemption == img
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
_matches_exemption(img, exemption) {
|
| 156 |
+
endswith(exemption, "*")
|
| 157 |
+
prefix := trim_suffix(exemption, "*")
|
| 158 |
+
startswith(img, prefix)
|
| 159 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/artifacthub-pkg.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 1.1.2
|
| 2 |
+
name: k8spsphostnetworkingports
|
| 3 |
+
displayName: Host Networking Ports
|
| 4 |
+
createdAt: "2024-08-26T20:25:17Z"
|
| 5 |
+
description: Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific ports must be specified. Corresponds to the `hostNetwork` and `hostPorts` fields in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 6 |
+
digest: 29aa57aacfb5f7fa92cd7cdc241250ed0ae1619d1706228f03f058e4efe7cabe
|
| 7 |
+
license: Apache-2.0
|
| 8 |
+
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/host-network-ports
|
| 9 |
+
keywords:
|
| 10 |
+
- gatekeeper
|
| 11 |
+
- open-policy-agent
|
| 12 |
+
- policies
|
| 13 |
+
readme: |-
|
| 14 |
+
# Host Networking Ports
|
| 15 |
+
Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific ports must be specified. Corresponds to the `hostNetwork` and `hostPorts` fields in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 16 |
+
install: |-
|
| 17 |
+
### Usage
|
| 18 |
+
```shell
|
| 19 |
+
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/template.yaml
|
| 20 |
+
```
|
| 21 |
+
provider:
|
| 22 |
+
name: Gatekeeper Library
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/constraint.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostNetworkingPorts
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-network-ports
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
hostNetwork: true
|
| 12 |
+
min: 80
|
| 13 |
+
max: 9000
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/constraint_block_host_network.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostNetworkingPorts
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-network
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
hostNetwork: false
|
| 12 |
+
exemptImages:
|
| 13 |
+
- "nginx"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/disallowed_ephemeral.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
ephemeralContainers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9001
|
| 14 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/example_allowed.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-allowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: false
|
| 9 |
+
containers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9000
|
| 14 |
+
hostPort: 80
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/example_allowed_no_ports.yaml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
containers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
containers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9001
|
| 14 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/samples/psp-host-network-ports/update.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-networking-ports-disallowed
|
| 10 |
+
labels:
|
| 11 |
+
app: nginx-host-networking-ports
|
| 12 |
+
spec:
|
| 13 |
+
hostNetwork: true
|
| 14 |
+
containers:
|
| 15 |
+
- name: nginx
|
| 16 |
+
image: nginx
|
| 17 |
+
ports:
|
| 18 |
+
- containerPort: 9001
|
| 19 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/suite.yaml
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: host-network-ports
|
| 5 |
+
tests:
|
| 6 |
+
- name: use-of-host-networking-ports-blocked
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/psp-host-network-ports/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-disallowed
|
| 11 |
+
object: samples/psp-host-network-ports/example_disallowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: yes
|
| 14 |
+
- name: example-allowed
|
| 15 |
+
object: samples/psp-host-network-ports/example_allowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: no
|
| 18 |
+
- name: disallowed-ephemeral
|
| 19 |
+
object: samples/psp-host-network-ports/disallowed_ephemeral.yaml
|
| 20 |
+
assertions:
|
| 21 |
+
- violations: yes
|
| 22 |
+
- name: update
|
| 23 |
+
object: samples/psp-host-network-ports/update.yaml
|
| 24 |
+
assertions:
|
| 25 |
+
- violations: no
|
| 26 |
+
- name: no-ports-specified
|
| 27 |
+
object: samples/psp-host-network-ports/example_allowed_no_ports.yaml
|
| 28 |
+
assertions:
|
| 29 |
+
- violations: no
|
| 30 |
+
- name: use-of-host-network-blocked
|
| 31 |
+
template: template.yaml
|
| 32 |
+
constraint: samples/psp-host-network-ports/constraint_block_host_network.yaml
|
| 33 |
+
cases:
|
| 34 |
+
- name: example-disallowed
|
| 35 |
+
object: samples/psp-host-network-ports/example_disallowed.yaml
|
| 36 |
+
assertions:
|
| 37 |
+
- violations: yes
|
| 38 |
+
- name: example-allowed
|
| 39 |
+
object: samples/psp-host-network-ports/example_allowed.yaml
|
| 40 |
+
assertions:
|
| 41 |
+
- violations: no
|
| 42 |
+
- name: disallowed-ephemeral
|
| 43 |
+
object: samples/psp-host-network-ports/disallowed_ephemeral.yaml
|
| 44 |
+
assertions:
|
| 45 |
+
- violations: yes
|
| 46 |
+
- name: update
|
| 47 |
+
object: samples/psp-host-network-ports/update.yaml
|
| 48 |
+
assertions:
|
| 49 |
+
- violations: no
|
| 50 |
+
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.2/template.yaml
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8spsphostnetworkingports
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Host Networking Ports"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.1.2
|
| 8 |
+
description: >-
|
| 9 |
+
Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific
|
| 10 |
+
ports must be specified. Corresponds to the `hostNetwork` and
|
| 11 |
+
`hostPorts` fields in a PodSecurityPolicy. For more information, see
|
| 12 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 13 |
+
spec:
|
| 14 |
+
crd:
|
| 15 |
+
spec:
|
| 16 |
+
names:
|
| 17 |
+
kind: K8sPSPHostNetworkingPorts
|
| 18 |
+
validation:
|
| 19 |
+
# Schema for the `parameters` field
|
| 20 |
+
openAPIV3Schema:
|
| 21 |
+
type: object
|
| 22 |
+
description: >-
|
| 23 |
+
Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific
|
| 24 |
+
ports must be specified. Corresponds to the `hostNetwork` and
|
| 25 |
+
`hostPorts` fields in a PodSecurityPolicy. For more information, see
|
| 26 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 27 |
+
properties:
|
| 28 |
+
exemptImages:
|
| 29 |
+
description: >-
|
| 30 |
+
Any container that uses an image that matches an entry in this list will be excluded
|
| 31 |
+
from enforcement. Prefix-matching can be signified with `*`. For example: `my-image-*`.
|
| 32 |
+
|
| 33 |
+
It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name)
|
| 34 |
+
in order to avoid unexpectedly exempting images from an untrusted repository.
|
| 35 |
+
type: array
|
| 36 |
+
items:
|
| 37 |
+
type: string
|
| 38 |
+
hostNetwork:
|
| 39 |
+
description: "Determines if the policy allows the use of HostNetwork in the pod spec."
|
| 40 |
+
type: boolean
|
| 41 |
+
min:
|
| 42 |
+
description: "The start of the allowed port range, inclusive."
|
| 43 |
+
type: integer
|
| 44 |
+
max:
|
| 45 |
+
description: "The end of the allowed port range, inclusive."
|
| 46 |
+
type: integer
|
| 47 |
+
targets:
|
| 48 |
+
- target: admission.k8s.gatekeeper.sh
|
| 49 |
+
code:
|
| 50 |
+
- engine: K8sNativeValidation
|
| 51 |
+
source:
|
| 52 |
+
variables:
|
| 53 |
+
- name: containers
|
| 54 |
+
expression: 'has(variables.anyObject.spec.containers) ? variables.anyObject.spec.containers : []'
|
| 55 |
+
- name: initContainers
|
| 56 |
+
expression: 'has(variables.anyObject.spec.initContainers) ? variables.anyObject.spec.initContainers : []'
|
| 57 |
+
- name: ephemeralContainers
|
| 58 |
+
expression: 'has(variables.anyObject.spec.ephemeralContainers) ? variables.anyObject.spec.ephemeralContainers : []'
|
| 59 |
+
- name: exemptImagePrefixes
|
| 60 |
+
expression: |
|
| 61 |
+
!has(variables.params.exemptImages) ? [] :
|
| 62 |
+
variables.params.exemptImages.filter(image, image.endsWith("*")).map(image, string(image).replace("*", ""))
|
| 63 |
+
- name: exemptImageExplicit
|
| 64 |
+
expression: |
|
| 65 |
+
!has(variables.params.exemptImages) ? [] :
|
| 66 |
+
variables.params.exemptImages.filter(image, !image.endsWith("*"))
|
| 67 |
+
- name: exemptImages
|
| 68 |
+
expression: |
|
| 69 |
+
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
|
| 70 |
+
container.image in variables.exemptImageExplicit ||
|
| 71 |
+
variables.exemptImagePrefixes.exists(exemption, string(container.image).startsWith(exemption)))
|
| 72 |
+
- name: badContainers
|
| 73 |
+
expression: |
|
| 74 |
+
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
|
| 75 |
+
!(container.image in variables.exemptImages) && has(container.ports) &&
|
| 76 |
+
(
|
| 77 |
+
(container.ports.all(port, has(port.hostPort) && has(variables.params.min) && port.hostPort < variables.params.min)) ||
|
| 78 |
+
(container.ports.all(port, has(port.hostPort) && has(variables.params.max) && port.hostPort > variables.params.max))
|
| 79 |
+
)
|
| 80 |
+
)
|
| 81 |
+
validations:
|
| 82 |
+
- expression: '(has(request.operation) && request.operation == "UPDATE") || size(variables.badContainers) == 0'
|
| 83 |
+
messageExpression: '"The specified hostNetwork and hostPort are not allowed, pod: " + variables.anyObject.metadata.name + ". Allowed values: " + variables.params'
|
| 84 |
+
- expression: |
|
| 85 |
+
(has(request.operation) && request.operation == "UPDATE") ||
|
| 86 |
+
(!has(variables.params.hostNetwork) || !variables.params.hostNetwork ? (has(variables.anyObject.spec.hostNetwork) && !variables.anyObject.spec.hostNetwork) : true)
|
| 87 |
+
messageExpression: '"The specified hostNetwork and hostPort are not allowed, pod: " + variables.anyObject.metadata.name + ". Allowed values: " + variables.params'
|
| 88 |
+
- engine: Rego
|
| 89 |
+
source:
|
| 90 |
+
rego: |
|
| 91 |
+
package k8spsphostnetworkingports
|
| 92 |
+
|
| 93 |
+
import data.lib.exclude_update.is_update
|
| 94 |
+
import data.lib.exempt_container.is_exempt
|
| 95 |
+
|
| 96 |
+
violation[{"msg": msg, "details": {}}] {
|
| 97 |
+
# spec.hostNetwork field is immutable.
|
| 98 |
+
not is_update(input.review)
|
| 99 |
+
|
| 100 |
+
input_share_hostnetwork(input.review.object)
|
| 101 |
+
msg := sprintf("The specified hostNetwork and hostPort are not allowed, pod: %v. Allowed values: %v", [input.review.object.metadata.name, input.parameters])
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
input_share_hostnetwork(o) {
|
| 105 |
+
not input.parameters.hostNetwork
|
| 106 |
+
o.spec.hostNetwork
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
input_share_hostnetwork(_) {
|
| 110 |
+
hostPort := input_containers[_].ports[_].hostPort
|
| 111 |
+
hostPort < input.parameters.min
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
input_share_hostnetwork(_) {
|
| 115 |
+
hostPort := input_containers[_].ports[_].hostPort
|
| 116 |
+
hostPort > input.parameters.max
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
input_containers[c] {
|
| 120 |
+
c := input.review.object.spec.containers[_]
|
| 121 |
+
not is_exempt(c)
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
input_containers[c] {
|
| 125 |
+
c := input.review.object.spec.initContainers[_]
|
| 126 |
+
not is_exempt(c)
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
input_containers[c] {
|
| 130 |
+
c := input.review.object.spec.ephemeralContainers[_]
|
| 131 |
+
not is_exempt(c)
|
| 132 |
+
}
|
| 133 |
+
libs:
|
| 134 |
+
- |
|
| 135 |
+
package lib.exclude_update
|
| 136 |
+
|
| 137 |
+
is_update(review) {
|
| 138 |
+
review.operation == "UPDATE"
|
| 139 |
+
}
|
| 140 |
+
- |
|
| 141 |
+
package lib.exempt_container
|
| 142 |
+
|
| 143 |
+
is_exempt(container) {
|
| 144 |
+
exempt_images := object.get(object.get(input, "parameters", {}), "exemptImages", [])
|
| 145 |
+
img := container.image
|
| 146 |
+
exemption := exempt_images[_]
|
| 147 |
+
_matches_exemption(img, exemption)
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
_matches_exemption(img, exemption) {
|
| 151 |
+
not endswith(exemption, "*")
|
| 152 |
+
exemption == img
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
_matches_exemption(img, exemption) {
|
| 156 |
+
endswith(exemption, "*")
|
| 157 |
+
prefix := trim_suffix(exemption, "*")
|
| 158 |
+
startswith(img, prefix)
|
| 159 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/artifacthub-pkg.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 1.1.3
|
| 2 |
+
name: k8spsphostnetworkingports
|
| 3 |
+
displayName: Host Networking Ports
|
| 4 |
+
createdAt: "2024-08-29T21:28:18Z"
|
| 5 |
+
description: Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific ports must be specified. Corresponds to the `hostNetwork` and `hostPorts` fields in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 6 |
+
digest: 751752950daeb4002a10cad6cbeba6a4afe03b98605f32885ae3fe0179eaff67
|
| 7 |
+
license: Apache-2.0
|
| 8 |
+
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/host-network-ports
|
| 9 |
+
keywords:
|
| 10 |
+
- gatekeeper
|
| 11 |
+
- open-policy-agent
|
| 12 |
+
- policies
|
| 13 |
+
readme: |-
|
| 14 |
+
# Host Networking Ports
|
| 15 |
+
Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific ports must be specified. Corresponds to the `hostNetwork` and `hostPorts` fields in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 16 |
+
install: |-
|
| 17 |
+
### Usage
|
| 18 |
+
```shell
|
| 19 |
+
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/template.yaml
|
| 20 |
+
```
|
| 21 |
+
provider:
|
| 22 |
+
name: Gatekeeper Library
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/block_host_network/constraint.yaml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostNetworkingPorts
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-network
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
hostNetwork: false
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/port_range_block_host_network/constraint.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostNetworkingPorts
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-network-ports
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
hostNetwork: false
|
| 12 |
+
min: 80
|
| 13 |
+
max: 9000
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/port_range_block_host_network/example_disallowed_out_of_range_host_network_true.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
containers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9001
|
| 14 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/constraint.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostNetworkingPorts
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-network-ports
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
hostNetwork: true
|
| 12 |
+
min: 80
|
| 13 |
+
max: 9000
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/disallowed_ephemeral.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
ephemeralContainers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9001
|
| 14 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/example_allowed_in_range.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-allowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
containers:
|
| 9 |
+
- name: nginx
|
| 10 |
+
image: nginx
|
| 11 |
+
ports:
|
| 12 |
+
- containerPort: 9000
|
| 13 |
+
hostPort: 80
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/example_allowed_no_ports.yaml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
containers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/example_allowed_no_ports_host_network_false.yaml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-network-false
|
| 5 |
+
spec:
|
| 6 |
+
hostNetwork: false
|
| 7 |
+
containers:
|
| 8 |
+
- name: nginx
|
| 9 |
+
image: nginx
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/example_allowed_no_ports_host_network_true.yaml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-network-true
|
| 5 |
+
spec:
|
| 6 |
+
hostNetwork: true
|
| 7 |
+
containers:
|
| 8 |
+
- name: nginx
|
| 9 |
+
image: nginx
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/samples/psp-host-network-ports/update.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-networking-ports-disallowed
|
| 10 |
+
labels:
|
| 11 |
+
app: nginx-host-networking-ports
|
| 12 |
+
spec:
|
| 13 |
+
hostNetwork: true
|
| 14 |
+
containers:
|
| 15 |
+
- name: nginx
|
| 16 |
+
image: nginx
|
| 17 |
+
ports:
|
| 18 |
+
- containerPort: 9001
|
| 19 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/suite.yaml
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: host-network-ports
|
| 5 |
+
tests:
|
| 6 |
+
- name: port-range-with-host-network-allowed
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/psp-host-network-ports/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: out-of-range
|
| 11 |
+
object: samples/port_range_block_host_network/example_disallowed_out_of_range_host_network_true.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: yes
|
| 14 |
+
- name: example-allowed
|
| 15 |
+
object: samples/psp-host-network-ports/example_allowed_in_range.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: no
|
| 18 |
+
- name: out-of-range-ephemeral
|
| 19 |
+
object: samples/psp-host-network-ports/disallowed_ephemeral.yaml
|
| 20 |
+
assertions:
|
| 21 |
+
- violations: yes
|
| 22 |
+
- name: update
|
| 23 |
+
object: samples/psp-host-network-ports/update.yaml
|
| 24 |
+
assertions:
|
| 25 |
+
- violations: no
|
| 26 |
+
- name: no-ports-specified
|
| 27 |
+
object: samples/psp-host-network-ports/example_allowed_no_ports.yaml
|
| 28 |
+
assertions:
|
| 29 |
+
- violations: no
|
| 30 |
+
- name: host-network-forbidden
|
| 31 |
+
template: template.yaml
|
| 32 |
+
constraint: samples/block_host_network/constraint.yaml
|
| 33 |
+
cases:
|
| 34 |
+
- name: hostnetwork-true
|
| 35 |
+
object: samples/psp-host-network-ports/example_allowed_no_ports_host_network_true.yaml
|
| 36 |
+
assertions:
|
| 37 |
+
- violations: yes
|
| 38 |
+
- name: hostnetwork-false
|
| 39 |
+
object: samples/psp-host-network-ports/example_allowed_no_ports_host_network_false.yaml
|
| 40 |
+
assertions:
|
| 41 |
+
- violations: no
|
| 42 |
+
- name: port-range-with-host-network-forbidden
|
| 43 |
+
template: template.yaml
|
| 44 |
+
constraint: samples/port_range_block_host_network/constraint.yaml
|
| 45 |
+
cases:
|
| 46 |
+
- name: out-of-range-and-host-network-true
|
| 47 |
+
object: samples/port_range_block_host_network/example_disallowed_out_of_range_host_network_true.yaml
|
| 48 |
+
assertions:
|
| 49 |
+
- violations: yes
|
| 50 |
+
- name: in-range-host-network-false
|
| 51 |
+
object: samples/psp-host-network-ports/example_allowed_in_range.yaml
|
| 52 |
+
assertions:
|
| 53 |
+
- violations: no
|
| 54 |
+
- name: disallowed-ephemeral
|
| 55 |
+
object: samples/psp-host-network-ports/disallowed_ephemeral.yaml
|
| 56 |
+
assertions:
|
| 57 |
+
- violations: yes
|
| 58 |
+
- name: update
|
| 59 |
+
object: samples/psp-host-network-ports/update.yaml
|
| 60 |
+
assertions:
|
| 61 |
+
- violations: no
|
| 62 |
+
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.3/template.yaml
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8spsphostnetworkingports
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Host Networking Ports"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.1.3
|
| 8 |
+
description: >-
|
| 9 |
+
Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific
|
| 10 |
+
ports must be specified. Corresponds to the `hostNetwork` and
|
| 11 |
+
`hostPorts` fields in a PodSecurityPolicy. For more information, see
|
| 12 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 13 |
+
spec:
|
| 14 |
+
crd:
|
| 15 |
+
spec:
|
| 16 |
+
names:
|
| 17 |
+
kind: K8sPSPHostNetworkingPorts
|
| 18 |
+
validation:
|
| 19 |
+
# Schema for the `parameters` field
|
| 20 |
+
openAPIV3Schema:
|
| 21 |
+
type: object
|
| 22 |
+
description: >-
|
| 23 |
+
Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific
|
| 24 |
+
ports must be specified. Corresponds to the `hostNetwork` and
|
| 25 |
+
`hostPorts` fields in a PodSecurityPolicy. For more information, see
|
| 26 |
+
https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 27 |
+
properties:
|
| 28 |
+
exemptImages:
|
| 29 |
+
description: >-
|
| 30 |
+
Any container that uses an image that matches an entry in this list will be excluded
|
| 31 |
+
from enforcement. Prefix-matching can be signified with `*`. For example: `my-image-*`.
|
| 32 |
+
|
| 33 |
+
It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name)
|
| 34 |
+
in order to avoid unexpectedly exempting images from an untrusted repository.
|
| 35 |
+
type: array
|
| 36 |
+
items:
|
| 37 |
+
type: string
|
| 38 |
+
hostNetwork:
|
| 39 |
+
description: "Determines if the policy allows the use of HostNetwork in the pod spec."
|
| 40 |
+
type: boolean
|
| 41 |
+
min:
|
| 42 |
+
description: "The start of the allowed port range, inclusive."
|
| 43 |
+
type: integer
|
| 44 |
+
max:
|
| 45 |
+
description: "The end of the allowed port range, inclusive."
|
| 46 |
+
type: integer
|
| 47 |
+
targets:
|
| 48 |
+
- target: admission.k8s.gatekeeper.sh
|
| 49 |
+
code:
|
| 50 |
+
- engine: K8sNativeValidation
|
| 51 |
+
source:
|
| 52 |
+
variables:
|
| 53 |
+
- name: containers
|
| 54 |
+
expression: 'has(variables.anyObject.spec.containers) ? variables.anyObject.spec.containers : []'
|
| 55 |
+
- name: initContainers
|
| 56 |
+
expression: 'has(variables.anyObject.spec.initContainers) ? variables.anyObject.spec.initContainers : []'
|
| 57 |
+
- name: ephemeralContainers
|
| 58 |
+
expression: 'has(variables.anyObject.spec.ephemeralContainers) ? variables.anyObject.spec.ephemeralContainers : []'
|
| 59 |
+
- name: exemptImagePrefixes
|
| 60 |
+
expression: |
|
| 61 |
+
!has(variables.params.exemptImages) ? [] :
|
| 62 |
+
variables.params.exemptImages.filter(image, image.endsWith("*")).map(image, string(image).replace("*", ""))
|
| 63 |
+
- name: exemptImageExplicit
|
| 64 |
+
expression: |
|
| 65 |
+
!has(variables.params.exemptImages) ? [] :
|
| 66 |
+
variables.params.exemptImages.filter(image, !image.endsWith("*"))
|
| 67 |
+
- name: exemptImages
|
| 68 |
+
expression: |
|
| 69 |
+
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
|
| 70 |
+
container.image in variables.exemptImageExplicit ||
|
| 71 |
+
variables.exemptImagePrefixes.exists(exemption, string(container.image).startsWith(exemption)))
|
| 72 |
+
- name: badContainers
|
| 73 |
+
expression: |
|
| 74 |
+
(variables.containers + variables.initContainers + variables.ephemeralContainers).filter(container,
|
| 75 |
+
!(container.image in variables.exemptImages) && has(container.ports) &&
|
| 76 |
+
(
|
| 77 |
+
(container.ports.all(port, has(port.hostPort) && has(variables.params.min) && port.hostPort < variables.params.min)) ||
|
| 78 |
+
(container.ports.all(port, has(port.hostPort) && has(variables.params.max) && port.hostPort > variables.params.max))
|
| 79 |
+
)
|
| 80 |
+
)
|
| 81 |
+
- name: isUpdate
|
| 82 |
+
expression: has(request.operation) && request.operation == "UPDATE"
|
| 83 |
+
- name: hostNetworkAllowed
|
| 84 |
+
expression: has(variables.params.hostNetwork) && variables.params.hostNetwork
|
| 85 |
+
- name: hostNetworkEnabled
|
| 86 |
+
expression: has(variables.anyObject.spec.hostNetwork) && variables.anyObject.spec.hostNetwork
|
| 87 |
+
- name: hostNetworkViolation
|
| 88 |
+
expression: variables.hostNetworkEnabled && !variables.hostNetworkAllowed
|
| 89 |
+
validations:
|
| 90 |
+
- expression: 'variables.isUpdate || size(variables.badContainers) == 0'
|
| 91 |
+
messageExpression: '"The specified hostNetwork and hostPort are not allowed, pod: " + variables.anyObject.metadata.name'
|
| 92 |
+
- expression: variables.isUpdate || !variables.hostNetworkViolation
|
| 93 |
+
messageExpression: '"The specified hostNetwork and hostPort are not allowed, pod: " + variables.anyObject.metadata.name'
|
| 94 |
+
- engine: Rego
|
| 95 |
+
source:
|
| 96 |
+
rego: |
|
| 97 |
+
package k8spsphostnetworkingports
|
| 98 |
+
|
| 99 |
+
import data.lib.exclude_update.is_update
|
| 100 |
+
import data.lib.exempt_container.is_exempt
|
| 101 |
+
|
| 102 |
+
violation[{"msg": msg, "details": {}}] {
|
| 103 |
+
# spec.hostNetwork field is immutable.
|
| 104 |
+
not is_update(input.review)
|
| 105 |
+
|
| 106 |
+
input_share_hostnetwork(input.review.object)
|
| 107 |
+
msg := sprintf("The specified hostNetwork and hostPort are not allowed, pod: %v. Allowed values: %v", [input.review.object.metadata.name, input.parameters])
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
input_share_hostnetwork(o) {
|
| 111 |
+
not input.parameters.hostNetwork
|
| 112 |
+
o.spec.hostNetwork
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
input_share_hostnetwork(_) {
|
| 116 |
+
hostPort := input_containers[_].ports[_].hostPort
|
| 117 |
+
hostPort < input.parameters.min
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
input_share_hostnetwork(_) {
|
| 121 |
+
hostPort := input_containers[_].ports[_].hostPort
|
| 122 |
+
hostPort > input.parameters.max
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
input_containers[c] {
|
| 126 |
+
c := input.review.object.spec.containers[_]
|
| 127 |
+
not is_exempt(c)
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
input_containers[c] {
|
| 131 |
+
c := input.review.object.spec.initContainers[_]
|
| 132 |
+
not is_exempt(c)
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
input_containers[c] {
|
| 136 |
+
c := input.review.object.spec.ephemeralContainers[_]
|
| 137 |
+
not is_exempt(c)
|
| 138 |
+
}
|
| 139 |
+
libs:
|
| 140 |
+
- |
|
| 141 |
+
package lib.exclude_update
|
| 142 |
+
|
| 143 |
+
is_update(review) {
|
| 144 |
+
review.operation == "UPDATE"
|
| 145 |
+
}
|
| 146 |
+
- |
|
| 147 |
+
package lib.exempt_container
|
| 148 |
+
|
| 149 |
+
is_exempt(container) {
|
| 150 |
+
exempt_images := object.get(object.get(input, "parameters", {}), "exemptImages", [])
|
| 151 |
+
img := container.image
|
| 152 |
+
exemption := exempt_images[_]
|
| 153 |
+
_matches_exemption(img, exemption)
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
_matches_exemption(img, exemption) {
|
| 157 |
+
not endswith(exemption, "*")
|
| 158 |
+
exemption == img
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
_matches_exemption(img, exemption) {
|
| 162 |
+
endswith(exemption, "*")
|
| 163 |
+
prefix := trim_suffix(exemption, "*")
|
| 164 |
+
startswith(img, prefix)
|
| 165 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/artifacthub-pkg.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 1.1.4
|
| 2 |
+
name: k8spsphostnetworkingports
|
| 3 |
+
displayName: Host Networking Ports
|
| 4 |
+
createdAt: "2024-08-30T22:03:40Z"
|
| 5 |
+
description: Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific ports must be specified. Corresponds to the `hostNetwork` and `hostPorts` fields in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 6 |
+
digest: 5e295f3ee2762996e89f926faae128ca3ae86166aac8fb9e518433ba1300deec
|
| 7 |
+
license: Apache-2.0
|
| 8 |
+
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/host-network-ports
|
| 9 |
+
keywords:
|
| 10 |
+
- gatekeeper
|
| 11 |
+
- open-policy-agent
|
| 12 |
+
- policies
|
| 13 |
+
readme: |-
|
| 14 |
+
# Host Networking Ports
|
| 15 |
+
Controls usage of host network namespace by pod containers. HostNetwork verification happens without exception for exemptImages. Specific ports must be specified. Corresponds to the `hostNetwork` and `hostPorts` fields in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces
|
| 16 |
+
install: |-
|
| 17 |
+
### Usage
|
| 18 |
+
```shell
|
| 19 |
+
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/template.yaml
|
| 20 |
+
```
|
| 21 |
+
provider:
|
| 22 |
+
name: Gatekeeper Library
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/block_host_network/constraint.yaml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostNetworkingPorts
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-network
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
hostNetwork: false
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/port_range_block_host_network/constraint.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostNetworkingPorts
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-network-ports
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
hostNetwork: false
|
| 12 |
+
min: 80
|
| 13 |
+
max: 9000
|
| 14 |
+
exemptImages:
|
| 15 |
+
- "safeimages.com/*"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/port_range_block_host_network/example_disallowed_exempted_container_host_network_enabled.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-hn-ok-bad-port
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
containers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: safeimages.com/nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9001
|
| 14 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/port_range_block_host_network/example_disallowed_out_of_range_host_network_true.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
containers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9001
|
| 14 |
+
hostPort: 9001
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/psp-host-network-ports/constraint.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sPSPHostNetworkingPorts
|
| 3 |
+
metadata:
|
| 4 |
+
name: psp-host-network-ports
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Pod"]
|
| 10 |
+
parameters:
|
| 11 |
+
hostNetwork: true
|
| 12 |
+
min: 80
|
| 13 |
+
max: 9000
|
| 14 |
+
exemptImages:
|
| 15 |
+
- "safeimages.com/*"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/pod-security-policy/host-network-ports/1.1.4/samples/psp-host-network-ports/disallowed_ephemeral.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Pod
|
| 3 |
+
metadata:
|
| 4 |
+
name: nginx-host-networking-ports-disallowed
|
| 5 |
+
labels:
|
| 6 |
+
app: nginx-host-networking-ports
|
| 7 |
+
spec:
|
| 8 |
+
hostNetwork: true
|
| 9 |
+
ephemeralContainers:
|
| 10 |
+
- name: nginx
|
| 11 |
+
image: nginx
|
| 12 |
+
ports:
|
| 13 |
+
- containerPort: 9001
|
| 14 |
+
hostPort: 9001
|