{{- if and (.Values.rbac.pspEnabled) (semverCompare "<1.25-0" .Capabilities.KubeVersion.GitVersion) }}
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: {{ template "localstack.fullname" . }}
  labels:
{{ include "localstack.labels" . | indent 4 }}
  annotations:
    seccomp.security.alpha.kubernetes.io/allowedProfileNames: '*'
spec:
  privileged: false
  hostIPC: false
  hostNetwork: false
  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 "localstack.fullname" . }}-psp
  labels:
{{ include "localstack.labels" . | indent 4 }}
rules:
  - apiGroups: ['policy']
    resources: ['podsecuritypolicies']
    verbs:     ['use']
    resourceNames:
      - {{ template "localstack.fullname" . }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ template "localstack.fullname" . }}-psp
  labels:
{{ include "localstack.labels" . | indent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "localstack.fullname" . }}-psp
subjects:
  - kind: ServiceAccount
    name: {{ template "localstack.serviceAccountName" . }}
    namespace: {{ .Release.Namespace }}
{{- end }}
