2022-02-04 01:47:36 -05:00
|
|
|
{{- $name := "disallow-host-ports" }}
|
|
|
|
{{- if eq (include "kyverno-policies.podSecurityBaseline" (merge (dict "name" $name) .)) "true" }}
|
|
|
|
apiVersion: kyverno.io/v1
|
2023-11-16 04:32:38 -05:00
|
|
|
kind: {{ .Values.policyKind }}
|
2022-02-04 01:47:36 -05:00
|
|
|
metadata:
|
|
|
|
name: {{ $name }}
|
|
|
|
annotations:
|
2022-12-01 11:05:56 +01:00
|
|
|
{{- with .Values.autogenControllers }}
|
|
|
|
pod-policies.kyverno.io/autogen-controllers: {{ . }}
|
|
|
|
{{- end }}
|
2022-02-04 01:47:36 -05:00
|
|
|
policies.kyverno.io/title: Disallow hostPorts
|
|
|
|
policies.kyverno.io/category: Pod Security Standards (Baseline)
|
|
|
|
{{- if .Values.podSecuritySeverity }}
|
|
|
|
policies.kyverno.io/severity: {{ .Values.podSecuritySeverity }}
|
|
|
|
{{- end }}
|
|
|
|
policies.kyverno.io/subject: Pod
|
|
|
|
kyverno.io/kyverno-version: 1.6.0
|
|
|
|
kyverno.io/kubernetes-version: "1.22-1.23"
|
|
|
|
policies.kyverno.io/description: >-
|
|
|
|
Access to host ports allows potential snooping of network traffic and should not be
|
|
|
|
allowed, or at minimum restricted to a known list. This policy ensures the `hostPort`
|
2022-08-09 17:12:27 -04:00
|
|
|
field is unset or set to `0`.
|
2022-12-01 11:05:56 +01:00
|
|
|
labels: {{ include "kyverno-policies.labels" . | nindent 4 }}
|
2022-02-04 01:47:36 -05:00
|
|
|
spec:
|
2022-08-25 17:29:20 +02:00
|
|
|
{{- with index .Values "validationFailureActionByPolicy" $name }}
|
|
|
|
validationFailureAction: {{ toYaml . }}
|
|
|
|
{{- else }}
|
2022-02-04 01:47:36 -05:00
|
|
|
validationFailureAction: {{ .Values.validationFailureAction }}
|
2022-08-25 17:29:20 +02:00
|
|
|
{{- end }}
|
2022-02-09 03:24:35 -05:00
|
|
|
{{- with concat (index .Values "validationFailureActionOverrides" "all") (default list (index .Values "validationFailureActionOverrides" $name)) }}
|
|
|
|
validationFailureActionOverrides: {{ toYaml . | nindent 4 }}
|
|
|
|
{{- end }}
|
2022-02-24 17:31:51 +01:00
|
|
|
background: {{ .Values.background }}
|
2022-08-09 17:12:27 -04:00
|
|
|
failurePolicy: {{ .Values.failurePolicy }}
|
2022-02-04 01:47:36 -05:00
|
|
|
rules:
|
|
|
|
- name: host-ports-none
|
|
|
|
match:
|
|
|
|
any:
|
|
|
|
- resources:
|
|
|
|
kinds:
|
|
|
|
- Pod
|
|
|
|
{{- with index .Values "policyExclude" $name }}
|
|
|
|
exclude:
|
|
|
|
{{- toYaml . | nindent 8 }}
|
|
|
|
{{- end }}
|
2022-04-18 13:59:47 -04:00
|
|
|
{{- with index .Values "policyPreconditions" $name }}
|
|
|
|
preconditions:
|
|
|
|
{{- toYaml . | nindent 8 }}
|
|
|
|
{{- end }}
|
2022-02-04 01:47:36 -05:00
|
|
|
validate:
|
|
|
|
message: >-
|
|
|
|
Use of host ports is disallowed. The fields spec.containers[*].ports[*].hostPort
|
|
|
|
, spec.initContainers[*].ports[*].hostPort, and spec.ephemeralContainers[*].ports[*].hostPort
|
|
|
|
must either be unset or set to `0`.
|
|
|
|
pattern:
|
|
|
|
spec:
|
|
|
|
=(ephemeralContainers):
|
|
|
|
- =(ports):
|
|
|
|
- =(hostPort): 0
|
|
|
|
=(initContainers):
|
|
|
|
- =(ports):
|
|
|
|
- =(hostPort): 0
|
|
|
|
containers:
|
|
|
|
- =(ports):
|
|
|
|
- =(hostPort): 0
|
2022-08-09 17:12:27 -04:00
|
|
|
{{- end }}
|