Secrets
Where secrets live
Section titled “Where secrets live”| Environment | Storage | How they reach the running process |
|---|---|---|
| Local dev | Doppler project kottia-com, branch config dev_local (inherits dev, overrides the localhost infra + workstation tooling keys); binding pinned in the repo-root doppler.yaml | doppler run -- <cmd> injects them as process env. The repo-root .env.local is the no-Doppler fallback: Bun --env-file, Vite loadEnv and the e2e seed all fill only keys the environment does not already set. |
| Dev (deployed) | Doppler project kottia-com: root config dev is the shared layer (synced to nothing); branches dev_api → Railway api, dev_web → svelte-web, dev_worker → worker, pushed by the Doppler → Railway integration (one-way; edit in Doppler, not in Railway). Internal wiring stays a Railway service reference, stored escaped in Doppler (\${{valkey.VALKEY_URL}}). Setup + rules: deploy/README.md § Secrets and integrations. | Railway injects service variables at runtime and passes matching variables as Docker build arguments for declared ARGs. Secret values stay out of .railway/railway.ts and source control. |
| Staging + Production | Doppler root configs stg / prd (key skeletons exist: every key present, non-secret knobs filled, secrets empty); GCS access is Workload Identity, so no static storage keys exist in either tier | Doppler → GCP Secret Manager sync (automatic multi-region replication), injected into Cloud Run at deploy; rotation is a Doppler edit that the sync turns into a secret-version bump. Decided, not provisioned yet — see Production landscape. |
| Native mobile builds | Per-app build config (buildConfigField / build settings) + gitignored signing/keystore files | Compiled into the binary at native build time; client-safe values only. |
Where each kind of variable lives
Section titled “Where each kind of variable lives”Doppler holds every variable an app service reads — “public” or not — because the sync owns the service’s whole variable set and one config must be the complete spec of a deployment. What differs per class is the value, not the home:
| Class | Examples | Home | Per tier? |
|---|---|---|---|
| Platform wiring | DATABASE_URL, DIRECT_URL, VALKEY_URL, VALKEY_DURABLE_URL, MEILISEARCH_HOST, MEILISEARCH_*_KEY, PORT | Tier root config. DEV stores escaped Railway references (\${{postgres.DATABASE_URL}}, \${{valkey-volatile.VALKEY_URL}}, \${{valkey.VALKEY_URL}}, \${{meilisearch.…}}) that Railway resolves after the sync; GCP tiers hold the literal private-IP URLs (rediss:// + VALKEY_CA_CERT) | yes |
| Tier topology | ORIGIN, CORS_ORIGINS, PUBLIC_API_URL, BETTER_AUTH_URL(_API), COOKIE_DOMAIN, QUEUE_SUFFIX, TRUSTED_PROXY_CIDRS, SENTRY_ENVIRONMENT, feature flags | Tier root config; a service’s branch config when that service differs | yes |
| Third-party secrets | Stripe, FacturAPI, Knock, Resend, GetStream, Google, Anthropic / Black Forest Labs, Sentry token, Cloudflare | Tier root config — a separate vendor key set per tier | yes |
Client-safe PUBLIC_* | PUBLIC_GETSTREAM_API_KEY, PUBLIC_KNOCK_*, PUBLIC_GOOGLE_MAPS_BROWSER_KEY, PUBLIC_POSTHOG_* | Same as above — client-safe is about exposure, not ownership | yes |
| Build-time ARGs | PUBLIC_API_URL, VITE_SENTRY_DSN, SENTRY_AUTH_TOKEN / SENTRY_ORG / SENTRY_PROJECT | Doppler → Railway service variable → Docker ARG (unchanged mechanism) | yes |
| Workstation tooling | E2E_*, PLAYWRIGHT_BASE_URL, DEV_REFRESH_*, FIREBASE_*, APPLE_TEAM_ID, KNOCK_SERVICE_TOKEN | dev_local only — never in a root config, never in stg / prd | no |
| CI vendor sync | KNOCK_SERVICE_TOKEN, a test-mode STRIPE_SECRET_KEY (restricted key: Products, Prices, Webhook Endpoints, Billing Portal), PUBLIC_GETSTREAM_API_KEY, GETSTREAM_API_SECRET; variable STRIPE_WEBHOOK_URL | GitHub environment development (branch-restricted), read only by ci.yml’s vendor-sync job on development pushes. GitHub environment production holds the KNOCK_SERVICE_TOKEN the manual knock.yml promotion reads. The only credentials in GitHub Actions. | no |
| Platform layer | R2 credentials, IMGPROXY_KEY / IMGPROXY_SALT, imgproxy bind/port/S3 settings | Doppler project kottia-infra (dev / stg / prd), synced to the imgproxy service. kottia-com holds cross-project references (${kottia-infra.dev.IMGPROXY_KEY}) to the shared values, never copies | yes |
| Not in Doppler | RAILWAY_GIT_COMMIT_SHA, image ENV (NODE_ENV, HOST, BODY_SIZE_LIMIT), the data stores’ own variables (postgres, valkey, valkey-volatile, meilisearch, docs) | Railway / Dockerfile / IaC preserve() | — |
Shared constants are duplicated per tier rather than referenced across configs, so prd never
depends on another environment. PII_ENCRYPTION_KEY is generated per tier and never copied between
tiers.
Categories of secrets
Section titled “Categories of secrets”| Category | Server-only | Client-safe |
|---|---|---|
| Database | DATABASE_URL, DIRECT_URL | — |
| Auth | BETTER_AUTH_SECRET, GOOGLE_CLIENT_SECRET | GOOGLE_CLIENT_ID (public on OAuth consent) |
| Cache / queues | VALKEY_URL, VALKEY_DURABLE_URL (incl. passwords) | — |
| Search | MEILISEARCH_ADMIN_API_KEY | MEILISEARCH_SEARCH_API_KEY (read-only, scoped to public indexes) |
| Storage | AWS_SECRET_ACCESS_KEY | — |
| Image proxy | IMGPROXY_KEY, IMGPROXY_SALT | imgproxy URLs (signed) |
RESEND_API_KEY | — | |
| Chat | GETSTREAM_API_SECRET | PUBLIC_GETSTREAM_API_KEY (public-by-design, gated by server-issued user tokens) |
| Notifications | KNOCK_SECRET_API_KEY, KNOCK_FCM_CHANNEL_ID, KNOCK_APNS_CHANNEL_ID | PUBLIC_KNOCK_API_KEY, PUBLIC_KNOCK_FEED_CHANNEL_ID |
| Maps | GOOGLE_MAPS_API_KEY (server) | Android Maps key in the Android project (iOS uses MapKit — no key); restricted by package name + signing-cert SHA-1 |
| Analytics | SENTRY_AUTH_TOKEN, POSTHOG_PERSONAL_API_KEY | SENTRY_DSN, PUBLIC_POSTHOG_KEY |
| AI | ANTHROPIC_API_KEY, BFL_API_KEY, AI_STAGING_USER_HASH_SECRET | — |
| Payments | STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SIGNING_SECRET | — (hosted Checkout, so no publishable key ships — there is no Stripe.js on the client) |
| Fiscal / CFDI | FACTURAPI_SECRET_KEY (the FACTURAPI_PRODUCT_KEY / _UNIT_KEY / _PAYMENT_FORM overrides are SAT catalog values, not secrets) | — |
| Fiscal data | PII_ENCRYPTION_KEY — non-re-issuable, see below | — |
Non-re-issuable secrets
Section titled “Non-re-issuable secrets”Every secret above this line can be replaced. Lose RESEND_API_KEY and you issue a new one; lose AI_STAGING_USER_HASH_SECRET and the old pseudonyms stop correlating, which costs nothing anyone can name. The rotation procedure below assumes exactly that, and its first step — “issue a new credential in the provider dashboard” — is meaningless for a key with no dashboard behind it.
PII_ENCRYPTION_KEY is the first secret in this repo that does not work that way.
It is a data-encrypting key. It is self-generated (openssl rand -base64 32), no provider holds a copy, and it is the only thing that can read tax_profiles.{taxId,legalName,zip,email} and cfdi_documents.{receiverTaxId,receiverLegalName} — the RFC, razón social and fiscal domicile of every paying customer (FSR-014, packages/api/src/services/pii-crypto.ts).
Consequences that follow from that, and are not optional:
- An escrowed copy must exist outside both Railway and Dokploy. A deployment-platform account problem must not be the same event as permanent data loss.
- The owner must verify that escrow before the Hostinger VPS is cancelled. This page intentionally does not invent or assert a vault/location; owner verification is still required.
- Never derive it from another secret, and never reuse it. Coupling it to something with a routine rotation cadence is exactly the mistake documented under
BETTER_AUTH_SECRETbelow. - Rows written before FSR-014 shipped are plaintext at rest and stay readable with or without the key, which is what makes a rollback safe — it does not make the key optional for anything written since.
Rotation procedure
Section titled “Rotation procedure”- Issue a new credential in the provider dashboard (Better Auth, Resend, Knock, etc.).
- Update the value in Doppler (
kottia-com/dev, or the owning service’s branch config) first — the Railway sync pushes it to DEV and redeploys. Never edit the Railway variable directly; the next sync reverts it. Take thedev_localsnapshot first (below) if the key is also used locally. - Redeploy and verify nothing breaks.
- Update STG (once it exists) — the same key in the Doppler
stgconfig; the Secret Manager sync creates the new version, then redeploy and verify. Skipping STG defeats the reason it exists: rotation is exactly the class of change that should break on a rehearsal tier rather than in production. - Update production the same way (once it exists).
- Revoke the old credential in the provider dashboard.
For BETTER_AUTH_SECRET rotation: rotating the secret invalidates all sessions. Coordinate with the team so users get a single sign-out event instead of a silent log-out mid-flow.
For IMGPROXY_KEY / IMGPROXY_SALT rotation: all currently rendered HTML pages and SSR caches still hold URLs signed with the old key. Either (a) keep the old key alongside the new for an overlap window (imgproxy supports multiple keys), or (b) accept a short window of broken images while pages re-render.
BFL_API_KEY belongs only on the worker; apps/api holds no AI provider credential and no staging webhook. Rotate it by issuing a new key in the Black Forest Labs dashboard, updating the worker, and redeploying with AI_ROOM_STAGING_ENABLED=false; tasks already created keep polling under the new key.
Mobile-specific guardrails
Section titled “Mobile-specific guardrails”Any client-side key compiled into a native binary ships to user devices. Anyone with the IPA / APK can extract these keys (via strings, decompilation, or sniffing the first network request).
Provider-side restrictions are mandatory before public ship. See Architecture → Deployment for the per-key restriction recipes.
Server-only secrets like GETSTREAM_API_SECRET and KNOCK_SECRET_API_KEY must never be
shipped to a mobile bundle. They belong in apps/api’s env (Doppler dev_local locally, the Doppler
dev_api config — inheriting dev — synced to Railway’s api service in deployed DEV) — never in any client app.
Audit checklist
Section titled “Audit checklist”- No
.env*(except.env.example) committed. - No
*_vault.yml(decrypted) committed. - No
*.tfvars(real values) committed. - No
google-services.jsoncommitted. - No
*.pem/*.jkscommitted. - Railway build/deploy logs and GitHub Actions logs contain no secret values.
-
PII_ENCRYPTION_KEYwas copied verbatim and its off-platform escrow was owner-verified before Hostinger cancellation. - Sentry
beforeSendscrubber is installed in every Sentry init. - Mobile builds have provider-side API key restrictions applied.