Automatically copying resources to downstream clusters
From Fleet v0.14.0 onwards, Fleet supports propagating external resources to downstream clusters. Since v0.16.0, this feature is no longer experimental, and always enabled.
This simplifies dealing with dependencies of charts, such as values coming from external resources. See also valuesFrom.
How it works
HelmOps support a new downstreamResources field, which can be used to reference resources by kind and name.
Those resources must:
-
Be either secrets or config maps. No other `kind`s are currently supported.
-
Exist before being referenced from the HelmOp, and live in the same namespace as the HelmOp referencing them.
-
Match an entry of
allowedDownstreamResourcesin aPolicyin that namespace, if aPolicythere setsrequireServiceAccount: trueor has any entries. See Tenant namespaces.
Example:
apiVersion: fleet.cattle.io/v1alpha1
kind: HelmOp
[...] # metadata
spec:
helm:
[...] # Helm options
downstreamResources:
- kind: Secret
name: my-secret
- kind: ConfigMap
name: my-config
This instructs the Fleet controller to copy those resources to each targeted downstream cluster, before deploying the workload (in this case specified through a Helm chart) to said downstream cluster.
When a cluster is not targeted anymore, the Fleet agent will delete those resources from the cluster as well. They will remain on the upstream cluster, though.
|
If resources referenced through |
Permissions
Since Fleet v0.16.2, when a ServiceAccount is resolved for the deployment on the downstream cluster, the agent writes the copies as that ServiceAccount. This is the account set in serviceAccount, or the fleet-default account if none is set and it exists. The ServiceAccount needs get, create and update on the copied kinds in the deployment namespace, and the namespace must already exist unless the ServiceAccount may create namespaces. If a permission is missing, the deployment reports not ready and retries until the permission is granted. See Permissions for downstreamResources.
Tenant namespaces
The Fleet controller reads the referenced Secrets and ConfigMaps on the management cluster with its own credentials. Without a restriction, anyone who can create a deployment in the namespace could have any Secret or ConfigMap in it copied to a downstream cluster, where a workload in the deployment namespace can read it.
Since Fleet v0.16.4 and v0.17.0, a Policy decides which of them may be copied, through the field allowedDownstreamResources. Each entry names a kind, Secret or ConfigMap, and either a name or a namePattern:
kind: Policy
apiVersion: fleet.cattle.io/v1alpha1
metadata:
name: tenant-policy
namespace: workspace1
requireServiceAccount: true
allowedDownstreamResources:
- kind: Secret
name: my-secret
- kind: ConfigMap
namePattern: app-config-.*
The entries of all Policy objects in the namespace are combined into one list, and requireServiceAccount counts as true if any Policy there sets it:
-
If the combined list has entries, every Secret and ConfigMap in
downstreamResourcesmust match one of them, whicheverPolicyit comes from. -
If the combined list is empty and a
PolicysetsrequireServiceAccount: true, no Secret or ConfigMap is copied. -
If the combined list is empty and no
PolicysetsrequireServiceAccount: true, every referenced object is copied, as before.
If a referenced object is not allowed, Fleet refuses the Bundle. The Bundle, and the GitRepo or HelmOp it comes from, report Ready=False with a message naming the object:
downstream resource Secret my-secret is not allowed by Policy: it is not listed in allowedDownstreamResources
The check covers the downstreamResources of the deployment and those set on its targets. It only compares kinds and names and does not read the objects. While the Bundle is refused, its existing deployments stay as they are and no changes are rolled out. Once the Policy allows the object, Fleet picks up the change and proceeds without further action.
Removing an entry refuses the Bundle again. Copies that were already made are kept, on the management cluster and on downstream clusters, but no longer updated.
Whoever can write Policy objects in a namespace decides what may be copied from it. See Tenant Setup for the required RBAC.
Finding the objects to list
After upgrading from a version before v0.16.4, Bundles in a namespace whose Policy sets requireServiceAccount: true are refused until every Secret and ConfigMap they reference matches an entry. The following lists those objects, and can be run before the upgrade. It needs kubectl and jq, and read access to Policy and Bundle objects on the management cluster:
for ns in $(kubectl get policies.fleet.cattle.io -A -o json |
jq -r '.items[] | select(.requireServiceAccount == true) | .metadata.namespace' | sort -u); do
kubectl get bundles.fleet.cattle.io -n "$ns" -o json |
jq -r --arg ns "$ns" '.items[]
| (.spec.downstreamResources // []) + ([.spec.targets[]?.downstreamResources // []] | add // [])
| .[] | select(.kind | ascii_downcase | . == "secret" or . == "configmap")
| "\($ns) \(.kind) \(.name)"'
done | sort -u
Each line is <namespace> <kind> <name>. List an object only if its content may be visible to whoever deploys from that namespace. The entries can go into any Policy in the namespace, including a new one, since the lists of all Policy objects in a namespace are combined.
Monitoring
From version v0.15.0 onwards, Fleet monitors changes made to secrets and configmaps that are listed in DownstreamResources. It also checks whether a secret or configmap was created after the Bundle was created.
When a referenced secret or configmap is created or updated on the upstream cluster, Fleet will propagate those changes to downstream clusters, and re-deploy the workload.
This enables deployments to make use of the latest versions of those referenced resources, which may represent configuration, Helm values, etc.
Since Fleet v0.16.4 and v0.17.0, changes to a Policy in the namespace are picked up the same way, see Tenant namespaces.