Sub topic 14
Locking down stores and access
This chapter assumes you can write a SecretStore and ExternalSecret, know how IRSA (IAM roles for service accounts on EKS) authenticates a ServiceAccount, and understand Kubernetes RBAC (role-based access control). It covers how to limit what ESO can read, who can ask it to read, and who can see the result.
Think in three layers
Access can leak at three points. Each needs its own control.
| Layer | Question | Control |
|---|---|---|
| Provider | What can the operator's identity read? | IAM policy scoped to specific secrets |
| Store | Which namespaces may use this identity? | SecretStore per namespace, or ClusterSecretStore conditions |
| Cluster | Who can read the synced Secret? | RBAC on Secrets, encryption at rest |
Scope the provider identity
The identity behind a store should read only what its consumers need. Avoid secretsmanager:* and avoid Resource: "*". This policy allows reads on secrets whose names start with prod/db and nothing else:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret"
],
"Resource": "arn:aws:secretsmanager:eu-west-1:111122223333:secret:prod/db-*"
}
]
}Use one role per team or environment instead of one role for the whole cluster. If a single store is compromised, the damage then stops at that role's boundary.
Keep credentials out of manifests
Prefer web identity (IRSA or a similar workload identity) over static access keys, as in the earlier SecretStore. If you must use a static key, store it in a Kubernetes Secret created out of band, and reference it with secretRef. Never put it in Git.
Limit which namespaces can use a store
A namespaced SecretStore can only be referenced by ExternalSecrets in its own namespace. That is the safest default. A ClusterSecretStore is usable from any namespace unless you restrict it with conditions:
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-secretsYou can also select namespaces by label with namespaceSelector. Name the ServiceAccount's namespace explicitly, because a ClusterSecretStore has no namespace of its own.
Protect the resulting Secret
ESO writes ordinary Kubernetes Secrets, so the usual cluster controls apply:
- Grant
get,listandwatchon Secrets only where needed. Alistpermission returns every Secret value in the namespace. - Enable encryption at rest for etcd, ideally with a KMS provider.
- Mount a Secret only into the Pods that need it, and use
readOnly: true. - Restrict who can edit ExternalSecrets and stores. Changing a
remoteRef.keyredirects which remote value lands in the cluster. - Limit access to the
external-secretsnamespace. The controller's ServiceAccount there carries the provider identity.
Check what you have
Run these two checks after you apply the policies above. The first lists the stores and their conditions. The second tests whether a given user can read Secrets in a namespace.
kubectl get clustersecretstore -o yaml | grep -A4 conditions
kubectl auth can-i list secrets -n team-a --as=janeExercise
A ClusterSecretStore has no conditions, and its IAM role can read every secret under prod/. A developer in namespace sandbox has permission to create ExternalSecrets there. What can they do, and which two changes close the gap?
Show answer
They can create an ExternalSecret that references the store and sync any prod/ secret into sandbox, then read it. Add conditions to the ClusterSecretStore so only approved namespaces can use it, and narrow the IAM policy to the specific secrets those namespaces need. A per-namespace SecretStore with its own role also works.