apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: dockerhub-source-webhook
  labels:
    contrib.eventing.knative.dev/release: devel
rules:
  # Sources admin
  - apiGroups:
      - sources.knative.dev
    resources:
      - dockerhubsources
    verbs: &everything
      - get
      - list
      - watch
      - create
      - update
      - patch
      - delete

  # Sources finalizer
  - apiGroups:
      - sources.knative.dev
    resources:
      - dockerhubsources/finalizers
    verbs: *everything

  # Source statuses update
  - apiGroups:
      - sources.knative.dev
    resources:
      - dockerhubsources/status
    verbs:
      - get
      - update
      - patch

  # Deployments admin
  - apiGroups:
      - apps
    resources:
      - deployments
    verbs: *everything

  # Secrets read
  - apiGroups:
      - ""
    resources:
      - secrets
      - services
    verbs:
      - get
      - list
      - watch

  # Namespace labelling for webhook
  - apiGroups:
      - ""
    resources:
      - namespaces
    verbs:
      - get
      - create
      - update
      - list
      - watch
      - patch

  # Events admin
  - apiGroups:
      - ""
    resources:
      - events
      - configmaps
    verbs: *everything

  # EventTypes admin
  - apiGroups:
      - eventing.knative.dev
    resources:
      - eventtypes
    verbs: *everything

  # For manipulating certs into secrets.
  - apiGroups:
      - ""
    resources:
      - "secrets"
    verbs:
      - "get"
      - "create"
      - "update"
      - "list"
      - "watch"

  # For actually registering our webhook.
  - apiGroups:
      - "admissionregistration.k8s.io"
    resources:
      - "mutatingwebhookconfigurations"
      - "validatingwebhookconfigurations"
    verbs: *everything

  - apiGroups:
      - coordination.k8s.io
    resources:
      - leases
    verbs: *everything

  # finalizers are needed for the owner reference of the webhook
  - apiGroups:
      - ""
    resources:
      - "namespaces/finalizers"
    verbs:
      - "update"
