{{ if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
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 }}
rules:
  - apiGroups:
      - ""
    resourceNames:
      - {{ .Values.secretName }}
    resources:
      - secrets
    verbs:
      - get
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - create
      - list
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
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 }}
rules:
  - apiGroups:
      - ""
    resourceNames:
      - {{ include "sealed-secrets.fullname" . }}
    resources:
      - services
    verbs:
      - get
  - apiGroups:
      - ""
    resourceNames:
      - 'http:{{ include "sealed-secrets.fullname" . }}:'
      - 'http:{{ include "sealed-secrets.fullname" . }}:http'
      - {{ include "sealed-secrets.fullname" . }}
    resources:
      - services/proxy
    verbs:
      - create
      - get
{{ end }}
