apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: tigera-operator
rules:
  - apiGroups:
      - ""
    resources:
      - namespaces
      - pods
      - podtemplates
      - services
      - endpoints
      - events
      - configmaps
      - secrets
      - serviceaccounts
    verbs:
      - create
      - get
      - list
      - update
      - delete
      - watch
  - apiGroups:
      - ""
    resources:
      - nodes
    verbs:
      # Need to update node labels when migrating nodes.
      - 'get'
      - 'patch'
      - 'list'
      # We need this for Typha autoscaling
      - 'watch'
  - apiGroups:
      - rbac.authorization.k8s.io
    resources:
      - clusterroles
      - clusterrolebindings
      - rolebindings
      - roles
    verbs:
      - create
      - get
      - list
      - update
      - delete
      - watch
      - bind
      - escalate
  - apiGroups:
      - apps
    resources:
      - deployments
      - daemonsets
      - statefulsets
    verbs:
      - create
      - get
      - list
      - patch
      - update
      - delete
      - watch
  - apiGroups:
      - apps
    resourceNames:
      - tigera-operator
    resources:
      - deployments/finalizers
    verbs:
      - update
  - apiGroups:
      - operator.tigera.io
    resources:
      - '*'
    verbs:
      - create
      - get
      - list
      - update
      - patch
      - delete
      - watch
  - apiGroups:
    - networking.k8s.io
    resources:
    - networkpolicies
    verbs:
      - create
      - update
      - delete
      - get
      - list
      - watch
  - apiGroups:
    - crd.projectcalico.org
    resources:
    - felixconfigurations
    verbs:
    - patch
  - apiGroups:
    - crd.projectcalico.org
    resources:
    - ippools
    - kubecontrollersconfigurations
    verbs:
    - get
    - list
    - watch
  - apiGroups:
      - scheduling.k8s.io
    resources:
      - priorityclasses
    verbs:
      - create
      - get
      - list
      - update
      - delete
      - watch
  - apiGroups:
      - monitoring.coreos.com
    resources:
      - servicemonitors
    verbs:
      - get
      - create
  - apiGroups:
      - policy
    resources:
      - poddisruptionbudgets
    verbs:
      - create
      - get
      - list
      - update
      - delete
      - watch
  - apiGroups:
      - apiregistration.k8s.io
    resources:
      - apiservices
    verbs:
      - list
      - watch
      - create 
      - update
  # Needed for operator lock
  - apiGroups:
      - coordination.k8s.io
    resources:
      - leases
    verbs:
      - create
      - get
      - list
      - update
      - delete
      - watch
{{- if eq .Values.installation.kubernetesProvider "openshift" }}
  # When running in OpenShift, we need to update networking config.
  - apiGroups:
      - config.openshift.io
    resources:
      - networks/status
    verbs:
      - get
      - list
      - update
  - apiGroups:
      - config.openshift.io
    resources:
      - networks
      - infrastructures
    verbs:
      - get
      - list
      - patch
      - watch
  # On OpenShift, we need to modify SCCs.
  - apiGroups:
      - security.openshift.io
    resources:
      - securitycontextconstraints
    verbs:
      - create
      - get
      - list
      - update
      - delete
      - watch
  # The following rule is only for operator certification purposes.
  # The operator normally runs in a namespace with openshift.io/run-level=0 which bypasses SCC.
  # However in certification tests, the operator is run in a normal namespace so this
  # rule is needed for host networking and hostPath volume access.
  - apiGroups:
      - security.openshift.io
    resources:
      - securitycontextconstraints
    resourceNames:
      - hostaccess
    verbs:
      - use
  # Need these permissions for the calicoctl init container.
  - apiGroups:
      - crd.projectcalico.org
    resources:
      - bgpconfigurations
      - bgppeers
      - felixconfigurations
      - kubecontrollersconfigurations
      - globalnetworkpolicies
      - globalnetworksets
      - hostendpoints
      - ippools
      - networkpolicies
      - networksets
    verbs:
      - create
  - apiGroups:
     - crd.projectcalico.org
    resources:
      - ipamblocks
    verbs:
      - list
  # Need this permission for the calicoctl version mismatch checking
  - apiGroups:
      - crd.projectcalico.org
    resources:
      - clusterinformations
    verbs:
      - get
  # For AWS security group setup.
  - apiGroups:
      - batch
    resources:
      - jobs
      - cronjobs
    verbs:
      - create
      - update
      - list
      - watch
{{- else }}
  # Add the appropriate pod security policy permissions
  - apiGroups:
      - policy
    resources:
      - podsecuritypolicies
    resourceNames:
      - tigera-operator
    verbs:
      - use
  - apiGroups:
      - policy
    resources:
      - podsecuritypolicies
    verbs:
      - get
      - list
      - watch
      - create
      - update
      - delete
# Add the permissions to monitor the status of certificatesigningrequests when certificate management is enabled.
  - apiGroups:
      - certificates.k8s.io
    resources:
      - certificatesigningrequests
    verbs:
      - list
{{- end }}
