kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: "{{ include "aws-calico.fullname" . }}-node"
  labels:
    app.kubernetes.io/name: "{{ include "aws-calico.fullname" . }}-node"
{{ include "aws-calico.labels" . | indent 4 }}
rules:
  # The CNI plugin needs to get pods, nodes, namespaces, and configmaps.
  - apiGroups: [""]
    resources:
      - pods
      - nodes
      - namespaces
      - configmaps
    verbs:
      - get
  # EndpointSlices are used for Service-based network policy rule
  # enforcement.
  - apiGroups: ["discovery.k8s.io"]
    resources:
      - endpointslices
    verbs:
      - watch 
      - list
  - apiGroups: [""]
    resources:
      - endpoints
      - services
    verbs:
      # Used to discover service IPs for advertisement.
      - watch
      - list
      # Used to discover Typhas.
      - get
  - apiGroups: [""]
    resources:
      - nodes/status
    verbs:
      # Needed for clearing NodeNetworkUnavailable flag.
      - patch
      # Calico stores some configuration information in node annotations.
      - update
  # Watch for changes to Kubernetes NetworkPolicies.
  - apiGroups: ["networking.k8s.io"]
    resources:
      - networkpolicies
    verbs:
      - watch
      - list
  # Used by Calico for policy information.
  - apiGroups: [""]
    resources:
      - pods
      - namespaces
      - serviceaccounts
    verbs:
      - list
      - watch
  # The CNI plugin patches pods/status.
  - apiGroups: [""]
    resources:
      - pods/status
    verbs:
      - patch
  # Calico monitors various CRDs for config.
  - apiGroups: ["crd.projectcalico.org"]
    resources:
      - globalfelixconfigs
      - felixconfigurations
      - bgppeers
      - globalbgpconfigs
      - bgpconfigurations
      - ippools
      - ipamblocks
      - globalnetworkpolicies
      - globalnetworksets
      - networkpolicies
      - networksets
      - clusterinformations
      - hostendpoints
      - blockaffinities
    verbs:
      - get
      - list
      - watch
  # Calico must create and update some CRDs on startup.
  - apiGroups: ["crd.projectcalico.org"]
    resources:
      - ippools
      - felixconfigurations
      - clusterinformations
    verbs:
      - create
      - update
  # Calico stores some configuration information on the node.
  - apiGroups: [""]
    resources:
      - nodes
    verbs:
      - get
      - list
      - watch
  # These permissions are only requried for upgrade from v2.6, and can
  # be removed after upgrade or on fresh installations.
  - apiGroups: ["crd.projectcalico.org"]
    resources:
      - bgpconfigurations
      - bgppeers
    verbs:
      - create
      - update
  # These permissions are required for Calico CNI to perform IPAM allocations.
  - apiGroups: ["crd.projectcalico.org"]
    resources:
      - blockaffinities
      - ipamblocks
      - ipamhandles
    verbs:
      - get
      - list
      - create
      - update
      - delete
  - apiGroups: ["crd.projectcalico.org"]
    resources:
      - ipamconfigs
    verbs:
      - get
  # Block affinities must also be watchable by confd for route aggregation.
  - apiGroups: ["crd.projectcalico.org"]
    resources:
      - blockaffinities
    verbs:
      - watch
  # The Calico IPAM migration needs to get daemonsets. These permissions can be
  # removed if not upgrading from an installation using host-local IPAM.
  - apiGroups: ["apps"]
    resources:
      - daemonsets
    verbs:
      - get

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: "{{ include "aws-calico.fullname" . }}-node"
  labels:
{{ include "aws-calico.labels" . | indent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: "{{ include "aws-calico.fullname" . }}-node"
subjects:
  - kind: ServiceAccount
    name: "{{ include "aws-calico.serviceAccountName" . }}-node"
    namespace: {{ .Release.Namespace }}

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: "{{ include "aws-calico.fullname" . }}-typha-cpha"
  labels:
{{ include "aws-calico.labels" . | indent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name:  "{{ include "aws-calico.fullname" . }}-typha-cpha"
subjects:
  - kind: ServiceAccount
    name: "{{ include "aws-calico.serviceAccountName" . }}-typha-cpha"
    namespace: {{ .Release.Namespace }}

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: "{{ include "aws-calico.fullname" . }}-typha-cpha"
  labels:
{{ include "aws-calico.labels" . | indent 4 }}
rules:
  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["watch", "list"]

---

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: "{{ include "aws-calico.fullname" . }}-typha-cpha"
  labels:
{{ include "aws-calico.labels" . | indent 4 }}
rules:
  - apiGroups: [""]
    resources: ["configmaps"]
    verbs: ["get"]
  - apiGroups: ["extensions", "apps"]
    resources: ["deployments/scale"]
    verbs: ["get", "update"]

---

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: "{{ include "aws-calico.fullname" . }}-typha-cpha"
  labels:
{{ include "aws-calico.labels" . | indent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: "{{ include "aws-calico.fullname" . }}-typha-cpha"
subjects:
  - kind: ServiceAccount
    name: "{{ include "aws-calico.serviceAccountName" . }}-typha-cpha"
    namespace: "{{ .Release.Namespace }}"
