As part of the tenant provisioning process, Flux needs to generate RBAC resources. This policy will create a ServiceAccount and RoleBinding when a new or existing Namespace is labeled with `toolkit.fluxcd.io/tenant`. Use of this rule may require an additional binding for the Kyverno ServiceAccount so it has permissions to properly create the RoleBinding.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: generate-flux-multi-tenant-resourcesannotations:policies.kyverno.io/title: Generate Flux Multi-Tenant Resourcespolicies.kyverno.io/category: Fluxkyverno.io/kyverno-version: 1.6.2policies.kyverno.io/minversion: 1.6.0kyverno.io/kubernetes-version: "1.23"policies.kyverno.io/subject: ServiceAccount, RoleBindingpolicies.kyverno.io/description: As part of the tenant provisioning process, Flux needs to generate RBAC resources. This policy will create a ServiceAccount and RoleBinding when a new or existing Namespace is labeled with `toolkit.fluxcd.io/tenant`. Use of this rule may require an additional binding for the Kyverno ServiceAccount so it has permissions to properly create the RoleBinding.spec:rules:- name: generate-flux-samatch:any:- resources:kinds:- Namespaceselector:matchLabels:toolkit.fluxcd.io/tenant: "?*"generate:apiVersion: v1kind: ServiceAccountname: "{{request.object.metadata.labels.\"toolkit.fluxcd.io/tenant\"}}"namespace: "{{request.object.metadata.name}}"synchronize: falsedata:metadata:labels:toolkit.fluxcd.io/tenant: "{{request.object.metadata.labels.\"toolkit.fluxcd.io/tenant\"}}"name: "{{request.object.metadata.labels.\"toolkit.fluxcd.io/tenant\"}}"namespace: "{{request.object.metadata.name}}"- name: generate-flux-rolebindingmatch:any:- resources:kinds:- Namespaceselector:matchLabels:toolkit.fluxcd.io/tenant: "?*"generate:apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingname: "{{request.object.metadata.labels.\"toolkit.fluxcd.io/tenant\"}}"namespace: "{{request.object.metadata.name}}"synchronize: falsedata:metadata:labels:toolkit.fluxcd.io/tenant: "{{request.object.metadata.labels.\"toolkit.fluxcd.io/tenant\"}}"name: flux-{{request.object.metadata.labels."toolkit.fluxcd.io/tenant"}}namespace: "{{request.object.metadata.name}}"roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: cluster-adminsubjects:- kind: Username: flux:{{request.object.metadata.name}}:{{request.object.metadata.labels."toolkit.fluxcd.io/tenant"}}- kind: ServiceAccountname: "{{request.object.metadata.labels.\"toolkit.fluxcd.io/tenant\"}}"namespace: "{{request.object.metadata.name}}"
This policy generates and synchronizes Argo CD cluster secrets from Rancher managed cluster.provisioning.cattle.io/v1 resources and their corresponding CAPI secrets. In this solution, Argo CD integrates with Rancher managed clusters via the central Rancher authentication proxy which shares the network endpoint of the Rancher API/GUI. The policy implements work-arounds for Argo CD issue https://github.com/argoproj/argo-cd/issues/9033 "Cluster-API cluster auto-registration" and Rancher issue https://github.com/rancher/rancher/issues/38053 "Fix type and labels Rancher v2 provisioner specifies when creating CAPI Cluster Secret".
By default, Kubernetes allows communications across all Pods within a cluster. The NetworkPolicy resource and a CNI plug-in that supports NetworkPolicy must be used to restrict communications. A default NetworkPolicy should be configured for each Namespace to default deny all ingress and egress traffic to the Pods in the Namespace. Application teams can then configure additional NetworkPolicy resources to allow desired traffic to application Pods from select sources. This policy will create a new NetworkPolicy resource named `default-deny` which will deny all traffic anytime a new Namespace is created.
By default, Kubernetes allows communications across all Pods within a cluster. The NetworkPolicy resource and a CNI plug-in that supports NetworkPolicy must be used to restrict communications. A default NetworkPolicy should be configured for each Namespace to default deny all ingress and egress traffic to the Pods in the Namespace. Application teams can then configure additional NetworkPolicy resources to allow desired traffic to application Pods from select sources. This policy will create a new NetworkPolicy resource named `default-deny` which will deny all traffic anytime a new Namespace is created.