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