{{- if and (.Values.rbac.pspEnabled) (semverCompare "<1.25-0" .Capabilities.KubeVersion.GitVersion) }}
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: {{ template "squid.fullname" . }}
  labels:
{{ include "squid.labels" . | indent 4 }}
  annotations:
    seccomp.security.alpha.kubernetes.io/allowedProfileNames: '*'
spec:
  privileged: false
  hostIPC: false
  hostNetwork: true
  hostPorts:
    - min: 1024
      max: 65535
  hostPID: false
  readOnlyRootFilesystem: false
  allowPrivilegeEscalation: false
  allowedCapabilities:
    - '*'
  fsGroup:
    rule: RunAsAny
  runAsUser:
    rule: RunAsAny
  seLinux:
    rule: RunAsAny
  supplementalGroups:
    rule: RunAsAny
  volumes:
    - '*'
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "squid.fullname" . }}-psp
  labels:
{{ include "squid.labels" . | indent 4 }}
rules:
  - apiGroups: ['policy']
    resources: ['podsecuritypolicies']
    verbs:     ['use']
    resourceNames:
      - {{ template "squid.fullname" . }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ template "squid.fullname" . }}-psp
  labels:
{{ include "squid.labels" . | indent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "squid.fullname" . }}-psp
subjects:
  - kind: ServiceAccount
    name: {{ template "squid.serviceAccountName" . }}
    namespace: {{ .Release.Namespace }}
{{- end }}
