Security
Where Spyria’s secrets live and how to replace them. Commands use spyria compose (operations). How sign-in, permissions and credentials work: architecture › security.
Secrets in files
The server, its operator CLI, the Compose migrations and spyria-host read each secret from the environment, or from a file when <NAME>_FILE holds its path. Example: SPYRIA_SECRETS_KEY_FILE=/run/secrets/spyria_secrets_key instead of SPYRIA_SECRETS_KEY=…. This works with Docker secrets, Kubernetes secret volumes and vault agents.
- A trailing newline in the file is dropped.
- A secret given both ways (non-empty value and
_FILEpath) stops the process at start, naming the setting. - So does a file that cannot be read.
| Process | Secrets it reads from a file |
|---|---|
| Server, operator CLI, migrations (Compose) | DATABASE_URL, SPYRIA_TOKEN_SECRET, SPYRIA_SECRETS_KEY, SPYRIA_PREVIOUS_SECRETS_KEYS, SPYRIA_SETUP_TOKEN, SPYRIA_INSTALL_HOST_TOKEN, SPYRIA_GOOGLE_CLIENT_SECRET, SPYRIA_MICROSOFT_CLIENT_SECRET, SPYRIA_OIDC_CLIENT_SECRET, SPYRIA_GATEWAY_ADMIN_PASSWORD, OTEL_EXPORTER_OTLP_HEADERS |
spyria-host |
SPYRIA_HOST_CLAIM_URL, OTEL_EXPORTER_OTLP_HEADERS, HTTPS_PROXY, HTTP_PROXY |
The other Compose services are not Spyria’s:
- Postgres reads
POSTGRES_PASSWORD_FILEitself. - zero-cache and the gateway read their secrets from the environment only. So
SPYRIA_POSTGRES_PASSWORDandSPYRIA_GATEWAY_ADMIN_PASSWORDalways stay in.env, and must match the values in the files.
An install made by spyria setup keeps its secrets in .env: spyria compose runs only the Compose file it installed. On an install made by hand, put the files in an override file and add it to the alias (-f compose.prod.yml -f compose.secrets.yml):
services:
server:
environment:
SPYRIA_SECRETS_KEY: ''
SPYRIA_SECRETS_KEY_FILE: /run/secrets/spyria_secrets_key
secrets: [spyria_secrets_key]
secrets:
spyria_secrets_key:
file: ./secrets/spyria_secrets_key
The empty SPYRIA_SECRETS_KEY counts as unset, so the value from .env does not conflict with the file.
Rotation intervals
Rotate a secret at once when it may have leaked or someone who held it leaves. Write each new value in .env (.env.prod on an install made by hand), and also in its file when a service reads it from a file.
| Secret | Rotate | How |
|---|---|---|
SPYRIA_SECRETS_KEY |
Every 12 months | Rotating the secrets key. No downtime; runtimes move to the new key as they restart. |
SPYRIA_TOKEN_SECRET |
Every 12 months | Set a new value, restart the server. Members stay signed in (sessions are not signed with it; 15-minute session tokens are renewed from them). A sign-in, GitHub connection or GitHub App creation in progress starts over. |
SPYRIA_GOOGLE_CLIENT_SECRET, SPYRIA_MICROSOFT_CLIENT_SECRET, SPYRIA_OIDC_CLIENT_SECRET |
Every 12 months, and before the provider expires it (Microsoft Entra allows at most 24 months) | Add a second secret at the provider, set it (account providers), restart the server, then delete the old one at the provider. |
SPYRIA_POSTGRES_PASSWORD, SPYRIA_GATEWAY_DB_PASSWORD |
Every 12 months | Steps below the table. |
SPYRIA_ZERO_ADMIN_PASSWORD |
Every 12 months | Set a new value, run spyria compose up -d zero-cache. |
SPYRIA_GATEWAY_ADMIN_PASSWORD |
Every 12 months | Write it in .env (and the file of SPYRIA_GATEWAY_ADMIN_PASSWORD_FILE if used), run spyria compose up -d gateway server, check /health does not list gateway as failing. |
OTEL_EXPORTER_OTLP_HEADERS, CLOUDFLARE_TUNNEL_TOKEN |
Per the collector’s or Cloudflare’s policy | Issue a new token there, set it, restart the services that use it. |
SPYRIA_GATEWAY_ENCRYPTION_KEY |
Only after a leak | Changing it makes members’ API keys in the gateway unreadable: wipe the gateway’s database and have members enter their keys again. |
SPYRIA_GATEWAY_SETUP_TOKEN |
Only after a leak | Set a new value, run spyria compose up -d gateway, check /health does not list gateway as failing. |
SPYRIA_SETUP_TOKEN, SPYRIA_INSTALL_HOST_TOKEN, SPYRIA_HOST_CLAIM_URL |
Not needed | One-time: spent once the first workspace exists or the host is paired. |
To rotate SPYRIA_POSTGRES_PASSWORD or SPYRIA_GATEWAY_DB_PASSWORD (the Postgres role keeps the password it was created with):
- Run
spyria compose exec postgres psql -U spyria, then\password spyria(or\password bifrostfor the gateway’s). This keeps the new value out of shell history. - Write it in
.env, and in the files ofDATABASE_URL_FILEandPOSTGRES_PASSWORD_FILEif used. - Run
spyria compose up -d. It restarts the services that use it, Postgres included, for a few seconds.
Good to know:
spyria setupgenerates long-lived secrets from 32 random bytes each; the intervals limit how long a copied value stays useful.- The cloud modules generate secrets in the cloud’s secret manager. They cannot rotate
SPYRIA_SECRETS_KEYyet.
Rotating the secrets key
SPYRIA_SECRETS_KEY seals stored secrets (SSO client secrets, GitHub App credentials, members’ GitHub tokens) and derives the key the server uses to reach each runtime. To replace it:
-
In
.env(.env.prodon an install made by hand):- Move the current
SPYRIA_SECRETS_KEYintoSPYRIA_PREVIOUS_SECRETS_KEYS(comma-separated after any key already there). - Set
SPYRIA_SECRETS_KEYto a new value of at least 32 characters, for example fromopenssl rand -hex 32.
When they are read from files, edit the files instead (the override blanks the
.envvalues): append the current key to the file ofSPYRIA_PREVIOUS_SECRETS_KEYS_FILE(create that file and setting if needed), and write the new key into the file ofSPYRIA_SECRETS_KEY_FILE. - Move the current
-
Run
spyria compose up -d server. The server now seals with the new key and still opens what previous keys sealed; running runtimes keep answering. -
Seal every stored secret again:
spyria compose exec server bun apps/server/src/operator-cli.ts secrets:resealIt reports how many secrets it resealed and how many running runtimes still use a previous key. Run it again later until it reports none:
- A runtime moves to the new key the next time it starts.
- An idle runtime stops after an hour.
- A runtime in constant use never goes idle: Stop runtime in its chat’s runtime menu stops it, and the next prompt starts it on the new key.
-
Remove
SPYRIA_PREVIOUS_SECRETS_KEYS(orSPYRIA_PREVIOUS_SECRETS_KEYS_FILEand its file) and runspyria compose up -d serveragain.
Good to know:
- Keep the previous key with the backups taken before step 3: their secrets are sealed with it.
- The cloud modules do not take a previous key yet, so a cloud deployment cannot rotate the key this way.