{{ if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ printf "%s-key-admin" (include "sealed-secrets.fullname" .) }}
  namespace: {{ include "sealed-secrets.namespace" . }}
  labels: {{- include "sealed-secrets.labels" . | nindent 4 }}
    {{- if .Values.rbac.labels }}
    {{- include "sealed-secrets.render" ( dict "value" .Values.rbac.labels "context" $) | nindent 4 }}
    {{- end }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ printf "%s-key-admin" (include "sealed-secrets.fullname" .) }}
subjects:
  - apiGroup: ""
    kind: ServiceAccount
    name: {{ include "sealed-secrets.serviceAccountName" . }}
    namespace: {{ include "sealed-secrets.namespace" . }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ printf "%s-service-proxier" (include "sealed-secrets.fullname" .) }}
  namespace: {{ include "sealed-secrets.namespace" . }}
  labels: {{- include "sealed-secrets.labels" . | nindent 4 }}
    {{- if .Values.rbac.labels }}
    {{- include "sealed-secrets.render" ( dict "value" .Values.rbac.labels "context" $) | nindent 4 }}
    {{- end }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ printf "%s-service-proxier" (include "sealed-secrets.fullname" .) }}
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: system:authenticated
{{ end }}
