{{ if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ template "sealed-secrets.fullname" . }}-key-admin
  namespace: {{ template "sealed-secrets.namespace" . }}
  labels:
    app.kubernetes.io/name: {{ template "sealed-secrets.name" . }}
    helm.sh/chart: {{ template "sealed-secrets.chart" . }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/version: {{ .Chart.AppVersion }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ template "sealed-secrets.fullname" . }}-key-admin
subjects:
  - apiGroup: ""
    kind: ServiceAccount
    name: {{ template "sealed-secrets.serviceAccountName" . }}
    namespace: {{ template "sealed-secrets.namespace" . }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ template "sealed-secrets.fullname" . }}-service-proxier
  namespace: {{ template "sealed-secrets.namespace" . }}
  labels:
    app.kubernetes.io/name: {{ template "sealed-secrets.name" . }}
    helm.sh/chart: {{ template "sealed-secrets.chart" . }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/version: {{ .Chart.AppVersion }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ template "sealed-secrets.fullname" . }}-service-proxier
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: system:authenticated
{{ end }}
