{{- if and .Values.agent.enabled .Values.psp.create -}}
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: {{ template "kiam.fullname" . }}-agent
spec:
  # Prevents running in privileged mode
  privileged: false
  # Required to prevent escalations to root.
  allowPrivilegeEscalation: false
{{- if .Values.agent.host.iptables }}
  allowedCapabilities:
    - "NET_ADMIN"
{{ end }}
  volumes:
    - 'secret'
    - 'hostPath'
  allowedHostPaths:
    - pathPrefix: "/run/xtables.lock"
{{- range .Values.agent.extraHostPathMounts }}
    - pathPrefix: {{ .hostPath }}
      readOnly: {{ .readOnly }}
{{- end }}
  hostNetwork: true
  hostIPC: false
  hostPID: false
  runAsUser:
    rule: 'RunAsAny'
  seLinux:
    rule: 'RunAsAny'
  supplementalGroups:
    rule: 'MustRunAs'
    ranges:
      # Forbid adding the root group.
      - min: 1
        max: 65535
  fsGroup:
    rule: 'MustRunAs'
    ranges:
      # Forbid adding the root group.
      - min: 1
        max: 65535
  readOnlyRootFilesystem: false
{{- end }}
