1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 01:16:55 +00:00
kyverno/samples/RestrictNodePort.md

33 lines
804 B
Markdown
Raw Normal View History

2019-11-11 14:09:07 -08:00
# Restrict use of `NodePort` services
2019-10-23 14:06:03 -07:00
2020-11-11 15:55:02 -05:00
A Kubernetes service of type `NodePort` uses a host port (on every node in the cluster) to receive traffic from any source.
2019-10-23 14:06:03 -07:00
2020-11-11 15:55:02 -05:00
Kubernetes Network Policies cannot be used to control traffic to host ports.
2019-10-23 14:06:03 -07:00
Although NodePort services can be useful, their use should be limited to services with additional upstream security checks.
## Policy YAML
2019-11-11 18:21:16 -08:00
[restrict_node_port.yaml](more/restrict_node_port.yaml)
2019-10-23 14:06:03 -07:00
````yaml
2019-11-13 13:56:20 -08:00
apiVersion: kyverno.io/v1
2019-10-23 14:06:03 -07:00
kind: ClusterPolicy
metadata:
2019-12-10 09:51:15 -08:00
name: restrict-nodeport
2019-10-23 14:06:03 -07:00
spec:
validationFailureAction: audit
2019-10-23 14:06:03 -07:00
rules:
2019-12-10 09:51:15 -08:00
- name: validate-nodeport
2019-10-23 14:06:03 -07:00
match:
resources:
kinds:
- Service
validate:
2019-12-10 09:51:15 -08:00
message: "Services of type NodePort are not allowed"
2020-11-11 15:55:02 -05:00
pattern:
2019-10-23 14:06:03 -07:00
spec:
type: "!NodePort"
2020-11-11 15:55:02 -05:00
````