---
title: "Secrets"
description: "Infisical is the source of every secret, GitHub only holds the key to read it."
url: https://docs-staging-lehoetel.findmalek.engineer/docs/secrets
markdown: https://docs-staging-lehoetel.findmalek.engineer/docs/secrets.md
---

# Secrets

Secrets live in the self hosted Infisical on The Keep (`secrets.findmalek.engineer`, see [the keep](https://docs-staging-lehoetel.findmalek.engineer/docs/infrastructure/the-keep.md)). `.env.example` stays the documented list of keys, Infisical holds the values. Containers never talk to Infisical: the deploy scripts read it once and hand the result to Dokploy.

## Flow

1. A deploy job (`staging`, `release`) or a preview logs in to Infisical with Universal Auth (`INFISICAL_CLIENT_ID` and `INFISICAL_CLIENT_SECRET`) and exports the environment as dotenv.
2. The script merges, from weakest to strongest: what Dokploy already holds, the Infisical export, the values it computes (public urls, `DEPLOY_ENV`, `SEED`, `MESSAGING_LIVE`, `ALLOW_PREVIEW_ORIGINS`, `S3_PREFIX`; for previews also the database url and the demo password).
3. The merged env is written to the Dokploy compose service (`compose.update`) and the service is deployed.

Without the four `INFISICAL_*` settings nothing changes: staging and production keep the env Dokploy already has and previews keep using the `PREVIEW_APP_ENV` secret. Values are never printed, the job summary only shows the number of keys.

## Environments

| Infisical env | Used by |
| --- | --- |
| `dev` | `pnpm dev:secrets` on a laptop |
| `staging` | the `staging` workflow, every merge to `main` |
| `prod` | the `release` workflow, published release |
| `preview` | every PR preview, shared by all PRs (the per PR database, urls and passwords are computed) |

Previews, staging and dev must only hold log-only or test provider keys, they never send real messages.

## Locally

Install the Infisical cli, run `infisical login` (set `INFISICAL_API_URL=https://secrets.findmalek.engineer/api`), then `infisical init` once to fill `.infisical.json`. `pnpm dev:secrets` runs `turbo dev` with the `dev` environment. `pnpm dev` still reads the root `.env`. `pnpm secrets:pull dev .env.infisical` writes an environment to a file (needs the `INFISICAL_*` variables).

## Add a key

1. Declare it in `packages/env/src/api.ts` (or `next.ts`) and add it to `.env.example` with a comment. `pnpm env:check` runs in CI and fails when a key is in `.env.example` but not declared in `packages/env`.
2. Add the value to each Infisical environment that needs it. Run the `secrets-diff` workflow (Actions, run workflow) to list, per environment, the keys of `.env.example` that Infisical lacks, names only.
3. Redeploy: staging on the next merge, production on the next release, or run the `staging` workflow by hand.

Keys the deploy scripts compute (urls, `DEPLOY_ENV`, `SEED`, ...) are not stored in Infisical, the list is `COMPUTED` in `scripts/env-keys.mjs`. `POSTGRES_PASSWORD` must be stored in `staging` and `prod`: it has to stay stable because the database volume keeps the first one.

## Rotate

1. Change the value in Infisical for the environment.
2. Redeploy that environment. For `BETTER_AUTH_SECRET` all sessions end, for `POSTGRES_PASSWORD` change the role password in the database first.
3. Machine identity: create a new client secret in Infisical, update the GitHub secret `INFISICAL_CLIENT_SECRET`, then revoke the old one.

## What stays in GitHub

- secrets: `INFISICAL_CLIENT_ID`, `INFISICAL_CLIENT_SECRET`, plus the credentials of the deploy target itself (`DOKPLOY_TOKEN`) and `GITHUB_TOKEN`
- variables: `INFISICAL_URL`, `INFISICAL_PROJECT_ID`, the Dokploy ids and public urls (see [deploy runbook](https://docs-staging-lehoetel.findmalek.engineer/docs/deploy-runbook.md))

Everything the apps read at runtime (database, auth, providers, storage, analytics keys) moves to Infisical. `PREVIEW_APP_ENV` and any other app secret in GitHub can be deleted once the `preview` environment is filled.
