Sub topic 11
Sharing a store across namespaces with ClusterSecretStore
This chapter assumes you can write a SecretStore and an ExternalSecret, and that you know how Kubernetes namespaces and ServiceAccounts relate. If you need a refresher, see the chapters on SecretStore and provider authentication.
Why a namespaced store is not always enough
A SecretStore lives in one namespace, and only ExternalSecrets in that namespace can use it. That isolation is useful. It becomes repetitive when ten teams need the same provider, region and credentials. You would copy the same store into ten namespaces and keep every copy in sync.
A ClusterSecretStore is the cluster-scoped version of a SecretStore. It has the same spec.provider block. Any ExternalSecret can reference it, unless you restrict it.
A scoped ClusterSecretStore
apiVersion: external-secrets.io/v1
kind: ClusterSecretStore
metadata:
name: aws-shared
spec:
conditions:
- namespaces:
- team-a
- team-b
provider:
aws:
service: SecretsManager
region: eu-west-1
auth:
jwt:
serviceAccountRef:
name: eso-reader
namespace: external-secretsTwo details differ from a namespaced store:
conditionslimits which namespaces may use the store. An ExternalSecret in any other namespace is rejected. Withoutconditions, every namespace can use the store.serviceAccountRef.namespaceis required. A ClusterSecretStore has no namespace of its own, so ESO cannot guess where to find the ServiceAccount. Here it points toexternal-secrets.
Note that the store's credentials, not the requesting namespace, decide what can be read. If eso-reader can read every secret in the account, team-a can ask for any of them.
Referencing the store
An ExternalSecret must say it is pointing at a cluster-scoped store by setting kind. The default is SecretStore.
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: db-credentials
namespace: team-a
spec:
refreshInterval: 1h
secretStoreRef:
name: aws-shared
kind: ClusterSecretStore
target:
name: db-credentials
data:
- secretKey: password
remoteRef:
key: team-a/db
property: passwordThe target Secret is created in team-a, the namespace of the ExternalSecret, not in the namespace of the store's ServiceAccount.
Choosing between the two
| Need | Use |
|---|---|
| Each team has its own provider account or credentials | SecretStore per namespace |
| One shared provider identity for several namespaces | ClusterSecretStore with `conditions` |
| Stronger isolation between tenants | SecretStore per namespace |
Common errors
- Forgetting
kind: ClusterSecretStore. ESO looks for a namespaced SecretStore with that name and reports that it cannot find it. - Omitting
serviceAccountRef.namespace. The store reports an invalid configuration, because the ServiceAccount cannot be resolved. - A namespace missing from
conditions. The ExternalSecret fails with an error that the namespace is not allowed to use the store. Check its events withkubectl describe externalsecret.
Exercise
A ClusterSecretStore has conditions listing only team-a. An ExternalSecret in team-c references it correctly with kind: ClusterSecretStore. What happens, and what are two ways to fix it?
Show answer
The ExternalSecret fails to sync, because team-c is not an allowed namespace, and the error appears in its status and events. You can add team-c to the store's conditions, or create a namespaced SecretStore in team-c and point the ExternalSecret at it. The second option keeps the team's access separate from the shared store.