Sub topic 6
Syncing your first secret with an ExternalSecret
An ExternalSecret declares which remote values to read through a store and which Kubernetes Secret to produce. This chapter assumes you have installed ESO, created the aws-store SecretStore in the app namespace, and know basic kubectl and YAML. It also assumes the eso-reader ServiceAccount can read prod/db in AWS Secrets Manager.
What the controller does
The ExternalSecret holds no secret values. It is a request. The ESO controller reads it, asks the referenced store for the remote data, and writes a native Kubernetes Secret. It repeats this on a schedule.
The manifest
Suppose prod/db in AWS Secrets Manager holds JSON such as {"username": "app", "password": "s3cret"}. This ExternalSecret copies the password property.
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: db-credentials
namespace: app
spec:
refreshInterval: 1h
secretStoreRef:
name: aws-store
kind: SecretStore
target:
name: db-credentials
creationPolicy: Owner
data:
- secretKey: password
remoteRef:
key: prod/db
property: passwordOlder ESO releases use apiVersion: external-secrets.io/v1beta1. Check which versions your CRDs serve with kubectl get crd externalsecrets.external-secrets.io.
The fields work as follows:
secretStoreRefnames the store.kinddefaults toSecretStore, so set it toClusterSecretStorewhen you use a cluster-wide store.refreshIntervalis how often the controller re-reads the remote value. Rotation is covered in a later chapter.target.nameis the name of the Secret to create. If you omit it, the Secret takes the name of the ExternalSecret.creationPolicy: Ownermeans the ExternalSecret creates the Secret and owns it. Deleting the ExternalSecret then deletes the Secret.datais a list of mappings.remoteRef.keyis the remote secret name,propertyselects one field of its JSON, andsecretKeyis the key written into the Kubernetes Secret.
The ExternalSecret must be in the same namespace as the SecretStore it references. That is why both use app here.
Apply and verify
Apply the manifest, then check the status and decode the value.
kubectl apply -f db-credentials.yaml
kubectl get externalsecret db-credentials -n app
kubectl describe externalsecret db-credentials -n app
kubectl get secret db-credentials -n app -o jsonpath='{.data.password}' | base64 -dA healthy resource shows STATUS as SecretSynced and READY as True. The last command should print s3cret. Kubernetes stores Secret values base64-encoded, so you must decode them to read them.
Common errors
| Symptom | Likely cause |
|---|---|
| `SecretSyncedError` with an access denied message | The IAM role behind `eso-reader` lacks `secretsmanager:GetSecretValue` on `prod/db`. |
| `Secret does not exist` | `remoteRef.key` is misspelled, or the region in the store is wrong. |
| `property not found` | The remote value is not JSON, or it has no `password` field. |
| `could not find SecretStore` | The store is in a different namespace, or `secretStoreRef.name` is wrong. |
Exercise
You create an ExternalSecret with target.name: db-credentials and creationPolicy: Owner. Later you delete the ExternalSecret. What happens to the db-credentials Secret, and what happens to the value in AWS Secrets Manager?
Show answer
The Secret is deleted, because the ExternalSecret owns it under creationPolicy: Owner. The value in AWS Secrets Manager is not touched, since ESO only reads from it in this setup.
Exercise
The ExternalSecret reports an error saying the property password was not found in prod/db, but the secret exists. Name two things to check.
Show answer
Check that the remote value is valid JSON, and that it contains a field named exactly password. A plain-text secret has no properties, so you would omit property and read the whole value.