# Secret storage A DAG names secrets with `secrets['path']['key']`. This page explains where their values live and who reads them. To use them in a DAG, see [Secrets](../02-dags/13-secrets.md). A DAG may give a fallback for a missing key (`.get(key, fallback)`). It is written in the DAG, shown in the DAG's JSON, the API and the UI, and never masked: **never put a real secret in a fallback** ([Fallbacks are not secret](../02-dags/13-secrets.md#fallbacks-are-not-secret)). Put each environment's real values in its storage. The **worker agent** that runs a task fetches its secrets, never the master or the webserver, and never the task's own code. Values are held in the agent's memory, given to the task, and masked in its log and output before anything leaves the worker. The master, the database's run tables, the API and the UI only ever see names. A [connection](../02-dags/14-connections.md) can also carry secrets to a task. Before the task starts, the worker renders each connection it declares, fetching its secrets and adding their values to the mask for its log and output. The mask also covers the percent-encoded form used in a URL and the shell-quoted form printed by `schedr task-ctx connection --env`; `min_mask_length` and `unmasked_prefixes` (below) apply as to any other secret. The agent serves only connections the task declares. For commands, the worker writes connection files, including passwords and keys, in the attempt's private folder (directories 0700, files 0600). The default is memory-backed where `/dev/shm` exists; the fallback and an override may be on disk. See [Commands' connection files](05-workers.md#commands-connection-files). Passwords are removed from URL variables and put in the tool's file, so the documented invocations don't put them on the command line; commands can still expose secrets themselves. The mask covers JSON-escaped forms (also Mongo's YAML strings), curl's escapes, `.pgpass` escapes and MySQL option-file escapes, and passwords extracted from a masked URL, subject to the same masking settings. Masking protects against accidental output, not a task deliberately encoding a secret. Some values cannot be written safely: curl config values and `.pgpass` fields reject line breaks and NUL; MySQL option-file values reject NUL. SQL and Mongo URLs reject secret query keys such as `sslpassword` and `tlsCertificateKeyFilePassword`; Postgres `password` is extracted first, while MySQL's `password` query key is refused. These failures are `render_failed`. See [In a command](../02-dags/14-connections.md#in-a-command) for the variables and invocations. A task normally inherits the worker's `HOME`. Keep `~/.curlrc` and `~/.my.cnf` out of that user's home: curl and MySQL clients can read them too. The DAG page uses `curl -q -K` to skip curl's default config and `mysql --defaults-file` instead of `--defaults-extra-file` to avoid the user's MySQL options overriding the connection file. For SQL and Mongo, give a password as `password` apart from the URL; it goes to the driver as a separate value. Values filled into a URL by a t-string are percent-encoded. See [Built-in types](../02-dags/14-connections.md#built-in-types) for the forms and their rules. When a client needs a file path, the built-in types pass keys and certificates through an anonymous memory file on Linux, never a disk. Elsewhere they use a temporary file, mode 0600, removed when the connection's file context closes. Two kinds of storage exist: | Kind | Where the values are | Where | |---|---|---| | `db` | schedr's own database, each value encrypted | standalone only | | `vault` | HashiCorp Vault, a KV v2 mount | standalone and workers | ## Checking a deployment's connections Before a run needs its secrets, use `schedr connections check [ROOT]` to check and render connections using a worker's storages. It reports each secret's state, never its value, and does not open the connection. `schedr connections test NAME` opens it from a worker, where tasks run, and runs its check. For commands, options and examples see [Checking them on a worker](../02-dags/14-connections.md#checking-them-on-a-worker). Both commands use the webserver's API (also available in standalone), with its configured authentication. schedr has no user roles: anyone accepted by that API can run them. A check reads the storages without the worker's cache, so a corrected secret can be checked at once. The worker and its timing are described in [Workers](05-workers.md#checking-connections). ## Configuration Each storage is a table of its own, named by its key; DAGs write that name (`secrets.vault['...']`): ```toml [secret_storage] default = "vault" # which storage secrets['...'] means min_mask_length = 5 # shorter values are not masked [secret_storage.vault] type = "vault" address = "https://vault.example.com:8200" mount = "secret" # the KV v2 mount (default "secret") namespace = "team-x" # Vault Enterprise, optional ca_cert = "/etc/schedr/vault-ca.pem" # only these CAs, optional auth = { method = "kubernetes", role = "schedr-worker" } cache_ttl = "60s" # how long a value is kept in memory; "0s": never unmasked_prefixes = ["variables/"] # values under these aren't masked ``` - **The default storage** is `default`; without it, the only configured storage; with none, standalone's `db`. Several storages without `default` are a startup error ("set [secret_storage] default"), so adding a storage never moves the secrets DAGs read with `secrets[...]`. - **A name** is letters, digits, `_` and `-`, not `default`, and without `__` (environment variables split there). Environment variables lowercase it, so a storage configured only through them has a lowercase name. - **Only workers use it** (and standalone, which has one). Each worker reports its storage names, and the master refuses a DAG naming one that the worker which parsed it lacks. - **`unmasked_prefixes`** marks parts of a storage as settings, not credentials: values under them are not masked (a bucket name would otherwise be `****` on every log line). Each ends with `/`. Keep nothing secret there. - Every key is also `SCHEDR_CONFIG__SECRET_STORAGE____`. The full list is in the [Configuration reference](../_generated/04-reference/01-configuration.md). ## The `db` storage (standalone) Standalone always has a storage named `db`, in its own database (SQLite or Postgres). With no other storage configured it is the default, so `secrets['etl/db']['password']` works with no `[secret_storage]` at all. With Vault configured too, `db` stays reachable as `secrets.db['etl/db']['password']`. A secret is a path with keys, as in Vault. Each value is encrypted with XChaCha20-Poly1305 under **`SCHEDR_SECRET_KEY`** (32 bytes, base64), bound to its `path#key`, so a database dump, a backup or a copy of the SQLite file shows paths and key names but no value. Make a key with `schedr secrets new-key` and keep it as you keep the database's password: a lost key means setting every secret again. Without the key, standalone still starts; reading the `db` storage then fails as `secret_denied`, naming the missing variable. This protects against leaks of the database, not against someone who can read the process's environment. The `schedr secrets` commands write the table directly, as `schedr db migrate` does: the database is `[database] url`, else standalone's SQLite file in its data directory, and its schema must be up to date. In Kubernetes, run them with `kubectl exec` in the pod. | Command | Does | |---|---| | `schedr secrets set etl/db password=- user=etl` | Sets keys; the secret's other keys are kept. `key=@FILE` is a file's content exactly; `key=-` reads standard input, one trailing newline dropped, so a value stays out of the shell's history. | | `schedr secrets list [etl/]` | Paths and key names, never values. | | `schedr secrets get etl/db#password` | Prints one value; `get etl/db` prints the whole secret as JSON. Prints values to standard output. | | `schedr secrets delete etl/db` | Deletes the secret, all its keys. | | `schedr secrets export --to DIR` | Writes each secret as `DIR/.json` (mode 0600), for Vault. | | `schedr secrets new-key` | Prints a new key for `SCHEDR_SECRET_KEY`. | `set`, `get` and `export` need `SCHEDR_SECRET_KEY`; `list` and `delete` don't. The API and the UI never show a value. For a local try, `make standalone` and `make standalone-separate-ui` keep a key in each standalone's data folder as `secret.key` and set the documentation examples' secrets where missing. They reuse the key and leave existing secret keys in place. **Moving to Vault**, e.g. before moving from standalone to separate roles (workers have no database, so they can't read `db`): `schedr secrets export --to DIR` requires a new or empty directory. It prints the number of secrets exported and the next steps, without their values. Then load each file with `vault kv put secret/ @DIR/.json`, configure the Vault storage as the default, and delete `DIR`. ## Vault A `vault` storage reads **KV v2** (KV v1 isn't supported): `secrets['etl/db']['password']` is the key `password` of the secret `etl/db` under `mount`. A value that isn't a string is read as its JSON text, as `vault kv get -field=` prints it: `5432` is `"5432"`, `true` is `"true"`. A deleted latest version is not found. **Logging in:** - `auth = { method = "kubernetes", role = "...", mount = "kubernetes" }`: Vault's Kubernetes auth with the pod's service-account token (`token_file`, by default `/var/run/secrets/kubernetes.io/serviceaccount/token`; the chart mounts its own). The Vault role binds the service account. On OpenShift the auth mount is often `openshift`. - `auth = { method = "token" }`: a token from `SCHEDR_CONFIG__SECRET_STORAGE____TOKEN`, for development. A token in the configuration file is a startup error. Nothing is sent to Vault before the first read, so a worker starts while Vault is down. The agent keeps its token and, if it is renewable, renews it at two thirds of its time to live (with a minimum wait of 1 s). With Kubernetes auth it logs in again when renewal fails; with a supplied token it retries renewal while that token is still valid. A read refused with Kubernetes auth logs in again once and retries. Reads never wait for a renewal while the token is still good. **Answers:** Vault's JSON 404 response to a secret read is `secret_not_found`. A non-JSON 404, such as a proxy's error page, is `secret_unavailable`. Responses 400, 401 and 403, and a 404 on a login or token lookup, are `secret_denied`, with Vault's message when present. Other errors, an answer that is not a KV v2 secret, a timeout (`[secret_storage.] request_timeout`, 30 s by default) or no connection are `secret_unavailable`, which allows a retry under the task's retry policy. The client follows no redirect: the next host would get the token. Values are kept in the agent's memory for `cache_ttl` (60 s by default), so many short tasks don't each call Vault. A new read fetches a changed secret once the cache entry expires. An attempt keeps values it has already fetched for that attempt. ## In the chart | Value | Sets | |---|---| | `secretStorage.db.existingSecret`, `secretKey` | standalone's `SCHEDR_SECRET_KEY`, from an existing Secret (`secret-key` by default). The chart never makes one. | | `secretStorage.vault.enabled` | A Vault storage on standalone or the workers (never the master or the webserver). | | `secretStorage.vault.name` | Its name, as DAGs write it (`vault`). | | `secretStorage.vault.address`, `mount`, `namespace` | As in the configuration. | | `secretStorage.vault.auth.role`, `auth.mount` | The Vault role and the Kubernetes auth mount. | | `secretStorage.vault.auth.tokenExpirationSeconds`, `auth.audience` | The projected token Vault's login uses. | | `secretStorage.vault.caCert.configMap`, `key` | A ConfigMap with the CA certificates Vault's certificate is checked against. | The pods mount no service-account token otherwise (`serviceAccount.automountToken: false`); with Vault on, the chart mounts a **projected token** of its own at `/var/run/secrets/schedr/vault/token`, for Vault's login only. Under Istio's `REGISTRY_ONLY`, a Vault outside the mesh needs a ServiceEntry (`istio.serviceEntries`, [Deployment](10-deployment.md)). With another storage in `config` too, set `SECRET_STORAGE__DEFAULT` there. ## What a task can reach Every task on a worker runs as the agent's user. So a task can read what the agent can: its environment (standalone's `SCHEDR_SECRET_KEY`), its files, and the token Vault's login uses. With that token it can log in as its worker and read **whatever the worker's Vault role allows**, also secrets it never declared, and the UI won't list them. This reaches no more than a DAG could declare (any path can be declared); it skips only the declaration. So a worker is one trust domain: its tasks, its agent and its Vault role. **Teams that must be kept apart run separate deployments**, each with its own master, database, workers, service accounts and Vault role; queues don't separate them, since a release's workers share one role. One [UI](12-ui.md) can still show them all, as a federation of deployments.