### Webhook ###
---
# apiserver gets the auth-delegator role to delegate auth decisions to
# the core apiserver
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: {{ include "webhook.fullname" . }}:auth-delegator
  labels:
    app: {{ include "webhook.name" . }}
    chart: {{ include "webhook.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:auth-delegator
subjects:
- apiGroup: ""
  kind: ServiceAccount
  name: {{ include "webhook.fullname" . }}
  namespace: {{ .Release.Namespace }}

---

# apiserver gets the ability to read authentication. This allows it to
# read the specific configmap that has the requestheader-* entries to
# api agg
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
  name: {{ include "webhook.fullname" . }}:webhook-authentication-reader
  namespace: kube-system
  labels:
    app: {{ include "webhook.name" . }}
    chart: {{ include "webhook.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: extension-apiserver-authentication-reader
subjects:
- apiGroup: ""
  kind: ServiceAccount
  name: {{ include "webhook.fullname" . }}
  namespace: {{ .Release.Namespace }}

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ include "webhook.fullname" . }}:webhook-requester
  labels:
    app: {{ include "webhook.name" . }}
    chart: {{ include "webhook.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
rules:
- apiGroups:
  - admission.certmanager.k8s.io
  resources:
  - certificates
  - issuers
  - clusterissuers
  verbs:
  - create
