@@ -867,15 +867,52 @@ section.
867867
868868When both `.spec.kubeConfig` and
869869[`.spec.serviceAccountName`](#service-account-reference) are specified,
870- the controller will impersonate the ServiceAccount on the target cluster,
871- i.e. a ServiceAccount with name `.spec.serviceAccountName` must exist in
872- the target cluster inside a namespace with the same name as the namespace
873- of the Kustomization. For example, if the Kustomization is in the namespace
874- ` apps` of the cluster where Flux is running, then the ServiceAccount
875- must be in the `apps` namespace of the target remote cluster, and have the
876- name `.spec.serviceAccountName`. In other words, the namespace of the
877- Kustomization must exist both in the cluster where Flux is running
878- and in the target remote cluster where Flux will apply resources.
870+ the controller will impersonate the ServiceAccount username on the target
871+ cluster, i.e. the username `system:serviceaccount:<namespace>:<name>`, where
872+ ` <namespace>` is the namespace of the Kustomization and `<name>` is the value
873+ of `.spec.serviceAccountName`. This means that Kubernetes RBAC RoleBindings
874+ and ClusterRoleBindings must exist on the target cluster granting the required
875+ permissions to the username `system:serviceaccount:<namespace>:<name>`, or
876+ directly to the ServiceAccount kind.
877+
878+ Example of RoleBinding on the target cluster granting permissions to the
879+ ServiceAccount username (through the User kind) :
880+
881+ ` ` ` yaml
882+ apiVersion: rbac.authorization.k8s.io/v1
883+ kind: RoleBinding
884+ metadata:
885+ name: apps-sa-binding
886+ namespace: apps # This namespace DOES NOT have to match the Kustomization namespace.
887+ roleRef:
888+ apiGroup: rbac.authorization.k8s.io
889+ kind: Role
890+ name: apps-role
891+ subjects:
892+ - apiGroup: rbac.authorization.k8s.io
893+ kind: User
894+ name: system:serviceaccount:apps:apps-sa # The namespace here HAS to match the Kustomization namespace.
895+ ` ` `
896+
897+ Example of RoleBinding on the target cluster granting permissions through
898+ the ServiceAccount kind :
899+
900+ ` ` ` yaml
901+ apiVersion: rbac.authorization.k8s.io/v1
902+ kind: RoleBinding
903+ metadata:
904+ name: apps-sa-binding
905+ namespace: apps # This namespace DOES NOT have to match the Kustomization namespace.
906+ roleRef:
907+ apiGroup: rbac.authorization.k8s.io
908+ kind: Role
909+ name: apps-role
910+ subjects:
911+ - apiGroup: rbac.authorization.k8s.io
912+ kind: ServiceAccount
913+ name: apps-sa
914+ namespace: apps # This namespace HAS to match the Kustomization namespace.
915+ ` ` `
879916
880917# ### Secret-based authentication
881918
0 commit comments