Sub topic 7
Mapping keys with data and dataFrom
This chapter assumes you can write an ExternalSecret and have a working SecretStore, as covered in the previous chapters. It shows how to choose which remote values end up in the target Secret, and under which key names.
Two ways to pick remote values
An ExternalSecret has two fields for selecting remote data:
datalists individual mappings. Each entry names one remote value and the key it gets in the Kubernetes Secret.dataFrompulls many values at once, without naming each one.
You can use both in the same ExternalSecret. Use data when you need control over names. Use dataFrom when the remote secret already has the shape you want.
Mapping single values with data
Each data entry has a secretKey, which is the key in the target Secret, and a remoteRef, which points at the remote value.
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: passwordHere key is the name of the remote secret, prod/db. property selects one field from a JSON secret. If the remote value is a plain string, leave property out. The secretKey can differ from the property name, so you can rename values for your application.
Pulling everything with dataFrom
dataFrom with extract reads a remote JSON secret and creates one target key for every property.
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: db-all
namespace: app
spec:
refreshInterval: 1h
secretStoreRef:
name: aws-store
kind: SecretStore
target:
name: db-all
dataFrom:
- extract:
key: prod/dbIf prod/db holds {"username": "app", "password": "s3cret"}, the Secret db-all gets the keys username and password.
Combining both and handling conflicts
You can pull everything with dataFrom and then override or add single keys with data. When the same key appears in both, the data entry wins. Between several dataFrom entries, later entries override earlier ones.
Common mistakes
- Missing
property. If the remote secret is JSON and you omitpropertyindata, the whole JSON document becomes the value, not one field. - Wrong key path. The
keymust match the provider's secret name exactly, including any folder-like prefix. - Expecting changes to appear instantly. New remote properties appear in the Secret only after the next refresh.
- Key collisions. Two
dataFromentries that share property names silently overwrite each other, so check the order.
Exercise
The remote secret prod/db contains {"username": "app", "password": "s3cret"}. You want a Secret with only one key, DB_PASS, holding the password. Which field do you use, and what does the entry look like?
Show answer
Use data, because you need to rename the key and select only one property. The entry is - secretKey: DB_PASS with remoteRef: {key: prod/db, property: password}. dataFrom would create username and password keys instead.
Exercise
An ExternalSecret has a dataFrom extract of prod/db and a data entry with secretKey: password pointing at a different remote secret. Which value ends up in the password key?
Show answer
The value from the data entry, because data takes precedence over dataFrom when keys conflict.