> For AI agents: the complete documentation index is available at https://docs.hod.sh/llms.txt, the full documentation bundle is available at https://docs.hod.sh/llms-full.txt.

# Secrets

The server stores secrets for pipelines (`hod secret set`) encrypted with a key that never goes into the database. Postgres, its logs, replicas and backups only ever hold ciphertext.

```sh
hod-server generate-key /etc/hod/secrets.key     # mode 0600; never replaces a file
HOD_SECRETS_KEY_FILE=/etc/hod/secrets.key hod-server
```

- **Back the key up apart from the database.** Without it, stored secrets can't be read; with it and a backup, they all can.
- **Give the file to the server's user only.** The server refuses a key file its group or others can read. With systemd, `LoadCredential=secrets.key:/etc/hod/secrets.key` and `HOD_SECRETS_KEY_FILE=%d/secrets.key`; on Kubernetes, mount a Secret with `defaultMode: 0400`. The key is never given as a value in the environment.
- **The server won't start** if secrets are stored and no key, or the wrong key, is configured.
- **Rotating the key:**

  1. `hod-server generate-key new.key`;
  2. set `HOD_SECRETS_KEY_FILE` to the new key and add the old one to `HOD_SECRETS_OLD_KEY_FILES` (or `secrets.key_file` and `secrets.old_key_files` in the config file);
  3. restart every server;
  4. run `hod-server rotate-key` with the same configuration. It rewraps each secret's data key with the new key (values aren't re-encrypted) and says when no secret needs the old key;
  5. remove the old key. Until then the server warns at startup.

  Rotation doesn't undo a leak: an old key still opens old backups. If a key may have leaked, rotate it and also change the secrets themselves.
- **Releases are audited.** When the server assigns a job, it decrypts each secret the job's steps are granted and sends it to the runner with the job; the `secret_releases` table records which secret (its scope, name and version) went to which job, step and attempt. A job granted a secret it can't have (not set, refused by the secret's rule or by its seal, or a fork's run) fails with `secret` before it reaches a runner.
- **A secret can be sealed** to published components (`--component`), and pinned to the inputs that say where they send it (`--with`): see [Components](https://docs.hod.sh/self-hosting/components.md).
