apiVersion: v1
kind: ServiceAccount
metadata:
  name: dapr-sentry
  namespace: {{ .Release.Namespace }}
  labels:
    {{- range $key, $value := .Values.global.k8sLabels }}
    {{ $key }}: {{ tpl $value $ }}
    {{- end }}
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: dapr-sentry
  labels:
    {{- range $key, $value := .Values.global.k8sLabels }}
    {{ $key }}: {{ tpl $value $ }}
    {{- end }}
rules:
  - apiGroups: ["authentication.k8s.io"]
    resources: ["tokenreviews"]
    verbs: ["create"]
{{- if not .Values.global.rbac.namespaced }}
  - apiGroups: ["dapr.io"]
    resources: ["configurations"]
    verbs: ["list", "get", "watch"]
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["list", "get", "watch"]
{{- end }}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: dapr-sentry
  labels:
    {{- range $key, $value := .Values.global.k8sLabels }}
    {{ $key }}: {{ tpl $value $ }}
    {{- end }}
subjects:
- kind: ServiceAccount
  name: dapr-sentry
  namespace: {{ .Release.Namespace }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: dapr-sentry
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: dapr-sentry
  namespace: {{ .Release.Namespace }}
  labels:
    {{- range $key, $value := .Values.global.k8sLabels }}
    {{ $key }}: {{ tpl $value $ }}
    {{- end }}
rules:
  - apiGroups: [""]
    resources: ["secrets"]
    verbs: ["get", "update","delete"]
    resourceNames: ["dapr-trust-bundle"]
  - apiGroups: [""]
    resources: ["configmaps"]
    verbs: ["get", "update", "watch", "list"]
    resourceNames: ["dapr-trust-bundle"]
  - apiGroups: ["dapr.io"]
    resources: ["configurations"]
    verbs: ["list", "get", "watch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: dapr-sentry
  namespace: {{ .Release.Namespace }}
  labels:
    {{- range $key, $value := .Values.global.k8sLabels }}
    {{ $key }}: {{ tpl $value $ }}
    {{- end }}
subjects:
- kind: ServiceAccount
  name: dapr-sentry
  namespace: {{ .Release.Namespace }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: dapr-sentry
