1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

fix disallow_host_network_hostport policy

This commit is contained in:
Jim Bugwadia 2019-11-08 18:26:58 -08:00
parent 687c0c6470
commit a0d3f728da
2 changed files with 21 additions and 10 deletions

View file

@ -1,24 +1,33 @@
apiVersion: kyverno.io/v1alpha1
kind: ClusterPolicy
metadata:
name: validate-host-network-hostport
name: host-network-port
annotations:
policies.kyverno.io/category: Security
policies.kyverno.io/description: Using 'hostPort' and 'hostNetwork' allows pods to share
the host network stack, allowing potential snooping of network traffic from an application pod.
spec:
rules:
- name: validate-host-network-hostport
- name: validate-host-network
match:
resources:
kinds:
- Pod
validate:
message: "Defining hostNetwork and hostPort are not allowed"
message: "Use of hostNetwork is not allowed"
pattern:
spec:
=(hostNetwork): false
- name: validate-host-port
match:
resources:
kinds:
- Pod
validate:
message: "Use of hostPort is not allowed"
pattern:
spec:
(hostNetwork): false
containers:
- name: "*"
ports:
=(ports):
- hostPort: null

View file

@ -5,14 +5,16 @@ input:
expected:
validation:
policyresponse:
policy: validate-host-network-hostport
policy: host-network-port
resource:
kind: Pod
apiVersion: v1
namespace: ''
name: "nginx-host-network"
rules:
- name: validate-host-network-hostport
- name: validate-host-network
type: Validation
success: true
- name: validate-host-port
type: Validation
message: "Validation error: Defining hostNetwork and hostPort are not allowed\nValidation rule 'validate-host-network-hostport' failed at path '/spec/containers/0/ports/0/hostPort/'."
success: false