{{- if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: {{ template "appmesh-spire-server.fullname" . }}-configmap-role
  namespace: {{ .Release.Namespace }}
  labels:
{{ include "appmesh-spire-server.labels" . | indent 4 }}
rules:
- apiGroups: [""]
  resources: ["configmaps"]
  verbs: ["patch", "get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ template "appmesh-spire-server.fullname" . }}-configmap-rolebinding
  namespace: {{ .Release.Namespace }}
  labels:
{{ include "appmesh-spire-server.labels" . | indent 4 }}
subjects:
- kind: ServiceAccount
  name: {{ template "appmesh-spire-server.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ template "appmesh-spire-server.fullname" . }}-configmap-role
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ template "appmesh-spire-server.fullname" . }}-role
  labels:
{{ include "appmesh-spire-server.labels" . | indent 4 }}
rules:
  - apiGroups: ["authentication.k8s.io"]
    resources: ["tokenreviews"]
    verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: {{ template "appmesh-spire-server.fullname" . }}-rolebinding
  labels:
{{ include "appmesh-spire-server.labels" . | indent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "appmesh-spire-server.fullname" . }}-role
subjects:
- name: {{ template "appmesh-spire-server.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
  kind: ServiceAccount
{{- end }}
