Manage worker secrets
Set up the store the Runtime reads worker secrets from, and add, change or remove keys. What a worker can reference and the rules are in Worker Secrets.
Deployment
The Runtime reads one secret from one Dapr secret store:
| Environment variable | Default | Meaning |
|---|---|---|
WORKER_SECRETS_STORE |
workersecrets |
Dapr secret store component |
WORKER_SECRETS_NAME |
virtufin-worker-secrets |
The secret whose entries are the keys |
WORKER_SECRETS_TTL_SECONDS |
60 |
How long fetched values are reused |
On Kubernetes, the Helm chart (workerSecrets values) defines the store as
secretstores.kubernetes, scoped to the Runtime. It runs the Runtime under its own
service account, which may read exactly that one Secret. So no worker can reference the
API's own keys or the registry token. The Secret itself is created outside the chart:
kubectl -n virtufin create secret generic virtufin-worker-secrets \
--from-literal=alpaca-paper-key="$ALPACA_API_KEY" \
--from-literal=alpaca-paper-secret="$ALPACA_API_SECRET"
deploy-local runs the Runtime with the same workersecrets store, backed by a local file
(.local/worker-secrets.json) instead of the Secret; fill it with
scripts/worker_secret.sh set <key> <ENV_VAR> and restart the Runtime (see the
deploy-local README).
Managing the Secret
On medusa the Secret is managed by Ansible (k3s-common role virtufin_backend): it is
built from VIRTUFIN_WORKER_SECRETS, a JSON object key -> value in the cluster .env,
on every deploy. Change it there and redeploy; edits made with kubectl are overwritten
by the next deploy. Elsewhere, use kubectl as below. Keep values out of your shell
history: read them from a file or from variables, never type them on the command line.
| Task | Command |
|---|---|
| Create the Secret, or replace all its keys | kubectl -n virtufin create secret generic virtufin-worker-secrets --from-env-file=worker-secrets.env --dry-run=client -o yaml \| kubectl apply -f - |
| Add or change one key | kubectl -n virtufin patch secret virtufin-worker-secrets --type merge --patch-file=patch.json with {"stringData": {"my-key": "..."}} in patch.json |
| Remove one key | kubectl -n virtufin patch secret virtufin-worker-secrets --type json -p '[{"op":"remove","path":"/data/my-key"}]' |
| List the keys (never the values) | kubectl -n virtufin get secret virtufin-worker-secrets -o go-template='{{range $k, $v := .data}}{{$k}}{{"\n"}}{{end}}' |
worker-secrets.env holds one key=value per line and stays out of git. Keys follow the
reference rule above ([A-Za-z0-9._-]).
What a change does to running workers:
- Changed value: every worker that references the key gets the new value within
WORKER_SECRETS_TTL_SECONDS(60 s). No worker has to be recreated. - New key: only workers created afterwards can reference it. A worker's references are fixed when it is created, like its config.
- Removed key: a running worker's triggers keep the last values it was handed (the
Runtime logs a warning once), but its
GetSecretsAsyncfails withsecret '<key>' not found. The next time that worker loads it goesLOAD_FAILED. Add the key back, or delete the worker. - Store unreachable: the Runtime keeps the last values it fetched and logs a warning, so running workers continue. A worker that loads for the first time on a pod without cached values fails to load.
Any other Dapr secret store works too, such as Vault or a cloud key vault: point
WORKER_SECRETS_STORE at it, and make WORKER_SECRETS_NAME a secret that holds a map of
keys.