# flux_source_controller.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: crd-controller
rules:
- apiGroups: ['source.toolkit.fluxcd.io']
  resources: ['*']
  verbs: ['*']
- apiGroups: ['kustomize.toolkit.fluxcd.io']
  resources: ['*']
  verbs: ['*']
- apiGroups: ['helm.toolkit.fluxcd.io']
  resources: ['*']
  verbs: ['*']
- apiGroups: ['notification.toolkit.fluxcd.io']
  resources: ['*']
  verbs: ['*']
- apiGroups: ['image.toolkit.fluxcd.io']
  resources: ['*']
  verbs: ['*']
- apiGroups: ['source.extensions.fluxcd.io']
  resources: ['*']
  verbs: ['*']
- apiGroups:
  - ""
  resources:
  - namespaces
  - secrets
  - configmaps
  - serviceaccounts
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - events
  verbs:
  - create
  - patch
# required by leader election
- apiGroups:
    - ""
  resources:
    - configmaps
  verbs:
    - get
    - list
    - watch
    - create
    - update
    - patch
    - delete
- apiGroups:
    - ""
  resources:
    - configmaps/status
  verbs:
    - get
    - update
    - patch
- apiGroups:
  - "coordination.k8s.io"
  resources:
  - leases
  verbs:
  - get
  - list
  - watch
  - create
  - update
  - patch
  - delete
# required for object-level workload identity
- apiGroups:
  - ""
  resources:
  - serviceaccounts/token
  verbs:
  - create
# required for flow control
- nonResourceURLs:
  - /livez/ping
  verbs:
  - head
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: crd-controller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: crd-controller
subjects:
  - kind: ServiceAccount
    name: kustomize-controller
    namespace: flux-system
  - kind: ServiceAccount
    name: helm-controller
    namespace: flux-system
  - kind: ServiceAccount
    name: source-controller
    namespace: flux-system
  - kind: ServiceAccount
    name: notification-controller
    namespace: flux-system
  - kind: ServiceAccount
    name: image-reflector-controller
    namespace: flux-system
  - kind: ServiceAccount
    name: image-automation-controller
    namespace: flux-system
  - kind: ServiceAccount
    name: source-watcher
    namespace: flux-system