2019-10-23 21:06:03 +00:00
# Disallow `hostNetwork` and `hostPort`
2019-10-23 22:36:37 +00:00
Using `hostPort` and `hostNetwork` allows pods to share the host networking stack allowing potential snooping of network traffic across application pods.
2019-10-23 21:06:03 +00:00
## Policy YAML
2019-11-10 20:53:48 +00:00
[disallow_host_network_port.yaml ](best_practices/disallow_host_network_port.yaml )
2019-10-23 21:06:03 +00:00
````yaml
2019-11-13 21:56:20 +00:00
apiVersion: kyverno.io/v1
2019-10-23 21:06:03 +00:00
kind: ClusterPolicy
metadata:
2019-11-10 20:53:48 +00:00
name: disallow-host-network-port
2019-10-23 21:06:03 +00:00
spec:
2020-08-19 21:04:58 +00:00
validationFailureAction: audit
2019-10-23 21:06:03 +00:00
rules:
2019-12-10 17:51:15 +00:00
- name: validate-host-network
2019-10-23 21:06:03 +00:00
match:
resources:
kinds:
- Pod
validate:
2019-12-10 17:51:15 +00:00
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"
2019-10-23 21:06:03 +00:00
pattern:
spec:
containers:
- name: "*"
2019-12-10 17:51:15 +00:00
=(ports):
- X(hostPort): null
2019-10-23 21:06:03 +00:00
````