Environment Variables Reference
Exhaustive reference for all Bryfo bootstrap environment variables, first-boot admin seeds, container resource limits, and hot-reloadable /admin overrides.
Bryfo separates configuration into two clear layers:
- Immutable Infrastructure Bootstrap (
.env, requires process restart): Network listeners, trusted reverse-proxy CIDRs, PostgreSQL / Valkey connection parameters, and the master AES-256-GCMCREDENTIALS_ENCRYPTION_KEYSkeyring. - Hot-Reloaded Operational Policies (PostgreSQL
system_settings+ Valkey Pub/Sub): OIDC SSO, Google/Microsoft Mail XOAUTH2, Cloudflare Turnstile, S3/R2 object storage (DynamicStore), System SMTP, AI providers & pricing, Stalwart mailserver, and payment gateways.
Precedence Rule: /admin Database Settings Override Optional Seed Variables
Optional seed environment variables (OIDC_*, S3_*, SYSTEM_SMTP_*, AI_*, STRIPE_*, LOG_LEVEL, etc.) act purely as initial fallback defaults when no setting has been saved in /admin yet. Once you save a configuration in /admin/*, the encrypted database record takes precedence across all api and worker nodes immediately without restarting containers.
1. Core Bootstrap, URL & Cryptography
| Variable | Kind | Default | Format / Behavior |
|---|---|---|---|
DEPLOYMENT_MODE | Bootstrap | self_hosted | self_hosted (unlimited local quotas, billing off, private LAN mail/site-AI permitted) or cloud (multi-tenant subscriptions, dual-pool ledger, strict public-only netguard egress, 2 MiB IMAP on-demand threshold, active-window IDLE). |
APP_PUBLIC_URL | Required | http://localhost:8080 | External origin without trailing slash (e.g. https://mail.example.com). Controls CSRF Origin/Referer verification, OIDC/XOAUTH2 callback URLs, and auto-enables COOKIE_SECURE=true when starting with https://. |
CREDENTIALS_ENCRYPTION_KEYS | Required | — | Comma-separated versioned 32-byte Base64 AES-256-GCM keys: 1:<base64>[,2:<base64>] (v1:<base64> and bare <base64> also parse as version 1; all-zero keys fail at boot). Generate via echo "1:$(openssl rand -base64 32)". |
SESSION_SECRET | Optional Bootstrap | HKDF-derived | Derived automatically from the primary CREDENTIALS_ENCRYPTION_KEYS key (bryfo/session-secret/v1) via HKDF-SHA256 when unset. |
COOKIE_SECURE | Optional Bootstrap | true on https:// | Overrides the Secure attribute on bryfo_session (HttpOnly, SameSite=Lax, 7d sliding / 30d absolute TTL). |
TRUSTED_PROXIES | Bootstrap | Empty (127.0.0.1/32 in template) | Comma-separated IPs or CIDRs (127.0.0.1/32,172.16.0.0/12) allowed to supply X-Forwarded-For, X-Real-IP, and X-Forwarded-Proto. Untrusted peers are ignored. |
PUBLIC_CORS_ORIGINS | Optional Bootstrap | Sibling apex / www | Extra comma-separated origins allowed on read-only /api/v1/public/plans and /api/v1/auth/providers for external landing sites. |
2. Initial Administrator Seed (First Boot Only)
| Variable | Kind | Default | Format / Behavior |
|---|---|---|---|
BOOTSTRAP_ADMIN_EMAIL | First-Boot Seed | Empty | Email address for the initial admin user. Applied only when SELECT COUNT(*) FROM users == 0 and both email + password are set. |
BOOTSTRAP_ADMIN_PASSWORD | First-Boot Seed | Empty | Initial admin password (8–128 characters/bytes; "ChangeMe123!" is rejected at boot). Hashed with Argon2id; safe to delete from .env after first login. |
BOOTSTRAP_ADMIN_NAME | First-Boot Seed | Admin | Display name assigned to the bootstrapped administrator account. |
3. Process Topology, Listeners, Queues & Container Limits
| Variable | Kind | Default | Format / Behavior |
|---|---|---|---|
APP_MODE | Bootstrap | all | all (HTTP + SSE + /mcp + IDLE + Asynq worker in one process), api (stateless web/API/SSE/MCP tier), or worker (Asynq + cron + internal health/metrics server). |
BRYFO_LISTEN_HOST | Bootstrap | 127.0.0.1 (Compose) | Host interface bound by Docker port mapping and bryfo binary (127.0.0.1 behind local reverse proxy; 0.0.0.0 for LAN/container-network exposure). |
BRYFO_HTTP_PORT | Bootstrap | 8080 | TCP port (1–65535). Often set to 18090 on multi-service hosts. |
LISTEN_ADDR | Optional Bootstrap | Derived from above | Explicit Go host:port override (e.g. :8080); takes precedence over BRYFO_LISTEN_HOST + BRYFO_HTTP_PORT inside the binary. |
WEB_DIST_DIR | Optional Bootstrap | /srv/web (in image) | Directory containing built frontend SPA static assets. |
WORKER_CONCURRENCY | Bootstrap | 4 | Concurrent Asynq job workers per all / worker process (critical:6, default:3, low:1 weighted priority). |
WORKER_METRICS_ADDR | Optional Bootstrap | Falls back to LISTEN_ADDR | Internal HTTP bind address (host:port or :port) exposing /healthz, /readyz, and /metrics when APP_MODE=worker. |
ASYNQ_TASK_RETENTION | Bootstrap | 24h | Go duration string (24h, 12h) controlling how long completed Asynq task results remain in Valkey. |
BRYFO_IMAGE | Compose Variable | ghcr.io/bryfo/bryfo:latest | Container image tag pulled by docker-compose.yml (pin explicit semver tags such as ghcr.io/bryfo/bryfo:v0.2.0 in production). |
BRYFO_APP_MEM_LIMIT | Compose Variable | 1g | Memory cap on the app service in deploy/docker-compose.yml. |
BRYFO_PG_MEM_LIMIT | Compose Variable | 1536m | Memory cap on postgres (shm_size defaults to 256m). |
BRYFO_VALKEY_MEM_LIMIT | Compose Variable | 512m | Memory cap on valkey (internal --maxmemory defaults to 384mb with noeviction). |
4. PostgreSQL 17 (pgvector) & Valkey 8
| Variable | Kind | Default | Format / Behavior |
|---|---|---|---|
DATABASE_URL | Bootstrap | Built from PG* | Full postgres://... DSN. If omitted, Bryfo safely constructs and URL-encodes the DSN from PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE, and PGSSLMODE. |
POSTGRES_PASSWORD / PGPASSWORD | Required | — | Password for PostgreSQL (PGHOST=postgres, PGPORT=5432, PGUSER=bryfo, PGDATABASE=bryfo, PGSSLMODE=disable inside Compose). |
DB_MAX_CONNS | Bootstrap | 16 | Maximum pgxpool connections per process (>= 1). |
AUTO_MIGRATE | Bootstrap | true | Runs embedded SQL migrations 0001–0019 at startup under pg_advisory_lock(7418529630147) with SHA-256 checksum validation. Set false if running bryfo migrate manually in CI/CD. |
REDIS_ADDR | Bootstrap | 127.0.0.1:6379 (valkey:6379 in Compose) | Valkey / Redis host:port endpoint. |
REDIS_PASSWORD | Optional Bootstrap | Empty | Enables --requirepass in deploy/docker-compose.yml and authenticates Go Valkey clients when non-empty. |
REDIS_DB | Optional Bootstrap | 0 | Integer database index (0–15). |
5. Object Storage, Mail Egress & IMAP IDLE
| Variable | Kind | Default | UI Override & Notes |
|---|---|---|---|
BLOB_DIR | Bootstrap | ./data/blobs (/data/blobs in Docker) | Filesystem root for STORAGE_BACKEND=local (sha256/<2>/<2>/<sha256>). |
STORAGE_BACKEND | Optional Seed | local | local or s3. Hot-switchable live in /admin/infra. |
S3_ENDPOINT | Optional Seed | Empty | Custom S3 HTTPS endpoint (e.g., https://<accountid>.r2.cloudflarestorage.com). Leave empty for standard AWS S3 regional endpoints. |
S3_BUCKET | Optional Seed | Empty | Target bucket name (HeadBucket probe available in /admin/infra). |
S3_REGION | Optional Seed | auto | Region identifier (auto for Cloudflare R2; e.g. us-east-1 for AWS S3). |
S3_ACCESS_KEY_ID / S3_SECRET_ACCESS_KEY | Optional Seed | Empty | S3 credentials (KeyRing-encrypted when saved via /admin/infra). |
S3_FORCE_PATH_STYLE | Optional Seed | false | Set true for Garage, SeaweedFS, or path-style S3 gateways; keep false for AWS S3, Cloudflare R2, and Aliyun OSS. |
S3_PRESIGN_DOWNLOAD | Optional Seed | false | Issues 302 presigned S3 redirects only on explicit ?download=1 (non-preview) attachment downloads so inline/preview requests remain same-origin under SandboxMediaCSP. |
STORAGE_ONDEMAND_THRESHOLD_BYTES | Optional Seed | 0 (self_hosted) / 2097152 (cloud) | Attachments larger than this byte threshold (> 0) store metadata only and stream on demand from IMAP (<= 35 MiB) into a 7-day ephemeral cache. Hot-reloadable in /admin/infra. |
MAIL_ALLOW_PRIVATE_SERVERS | Bootstrap | true (self_hosted) / false (cloud) | Permits private LAN/VPN IMAP & SMTP addresses in self_hosted mode. Hard-forced to false in cloud mode regardless of env var. |
IDLE_ACTIVE_WINDOW_MINUTES | Optional Seed | 30 | Active tenant window (user:active:<uid>) keeping live IMAP IDLE sockets open in cloud mode (/admin/infra). |
IDLE_OFFLINE_POLL_INTERVAL_MINUTES | Optional Seed | 15 | Background Asynq IMAP poll interval for inactive cloud tenants (/admin/infra). |
6. OIDC, Mail XOAUTH2, System SMTP, Turnstile & Web Push Seeds
All settings below are preferably configured in /admin/security (where secrets are encrypted at rest with KeyRing and hot-reloaded):
| Variable | Default | Notes |
|---|---|---|
OIDC_ENABLED / OIDC_AUTO_REGISTER | false / false | Enables OIDC SSO button on /login and controls automatic account creation for verified IdP emails (email_verified == true). |
OIDC_PROVIDER_NAME | SSO | Button label shown on /login (e.g. Pocket ID, Authentik, Okta). |
OIDC_ISSUER_URL | Empty | OIDC discovery base URL (without /.well-known/openid-configuration). Callback URL: ${APP_PUBLIC_URL}/api/v1/auth/oidc/callback. |
OIDC_CLIENT_ID / OIDC_CLIENT_SECRET | Empty | OIDC confidential client credentials. |
GOOGLE_OAUTH_CLIENT_ID / GOOGLE_OAUTH_CLIENT_SECRET | Empty | Enables 1-click Gmail XOAUTH2 linking (${APP_PUBLIC_URL}/api/v1/accounts/oauth/google/callback). |
MICROSOFT_OAUTH_CLIENT_ID / MICROSOFT_OAUTH_CLIENT_SECRET | Empty | Enables 1-click Outlook / M365 XOAUTH2 linking (${APP_PUBLIC_URL}/api/v1/accounts/oauth/microsoft/callback). |
SYSTEM_SMTP_HOST / SYSTEM_SMTP_PORT | Empty / 587 | Outbound transactional SMTP relay for registration codes, password resets, and security alerts. |
SYSTEM_SMTP_SECURITY | starttls | starttls (port 587), tls (implicit TLS port 465), or none (trusted internal relay only). |
SYSTEM_SMTP_USERNAME / SYSTEM_SMTP_PASSWORD / SYSTEM_SMTP_FROM | Empty | Transactional SMTP auth credentials and From address (e.g. Bryfo <noreply@example.com>). |
TURNSTILE_SITE_KEY / TURNSTILE_SECRET_KEY | Empty | Cloudflare Turnstile bot protection on registration and password reset forms. |
VAPID_PUBLIC_KEY / VAPID_PRIVATE_KEY / VAPID_SUBJECT | Auto-generated | Web Push VAPID keys. If left empty, Bryfo automatically generates an ECDSA P-256 keypair on first boot and persists it encrypted in system_settings. |
7. Site AI, Sidecars, Billing, Observability & Backups
| Variable | Default | UI Override & Notes |
|---|---|---|
AI_BASE_URL / AI_API_KEY | https://openrouter.ai/api/v1 / Empty | Default site LLM OpenAI-compatible endpoint & key (/admin/ai). |
AI_CHAT_MODEL / AI_CLASSIFY_MODEL | openai/gpt-4.1-mini / openai/gpt-4.1-nano | Default chat/summarize/compose model and background classification model (/admin/ai). |
AI_EMBEDDING_BASE_URL / AI_EMBEDDING_API_KEY / AI_EMBEDDING_MODEL | Empty / Empty / openai/text-embedding-3-small | Separate vector embedding endpoint & model (<= 2000 dims uses vector HNSW; 2001–4000 dims uses halfvec HNSW). |
AI_USER_AGENT / AI_EMBEDDING_USER_AGENT | Empty | Optional custom HTTP User-Agent sent to upstream AI gateways. |
AI_ALLOW_PRIVATE_ENDPOINTS | true (self_hosted) / false (cloud) | Allows site admins in self_hosted mode to point Site AI at LAN Ollama/vLLM. User BYOK always forces public-only egress (ForcePublicOnly: true) in every mode. |
AI_EMBEDDING_SIDECAR_HOSTS | embedding,ollama | Comma-separated internal Docker service hostnames permitted for local embedding/LLM sidecars. |
MAILSERVER_SIDECAR_HOSTS | stalwart | Comma-separated internal Docker service hostnames permitted for the managed Stalwart sidecar (/admin/mailserver). |
BILLING_ENABLED | false (self_hosted) / true (cloud) | Enables /billing/*, /admin/plans, /admin/orders, and /api/v1/public/plans (/admin/security). |
STRIPE_SECRET_KEY / STRIPE_WEBHOOK_SECRET / STRIPE_PUBLISHABLE_KEY / STRIPE_CURRENCY | Empty (USD) | Seed credentials for Stripe Checkout & /api/v1/webhooks/stripe (/admin/orders). |
LOG_LEVEL / LOG_FORMAT | info / text | debug, info, warn, error (LOG_LEVEL hot-reloads via /admin/infra); LOG_FORMAT=json recommended in production. |
METRICS_TOKEN | Empty | Bearer token authenticating GET /metrics for Prometheus (/admin/infra supports live rotation). |
SENTRY_DSN | Empty | Optional Sentry or self-hosted GlitchTip DSN for backend panic/error capture (/admin/infra). |
BACKUP_DIR / AGE_KEY_FILE | ./backups / Empty | Used by scripts/backup.sh and scripts/restore.sh for snapshot output path and age encryption/decryption identity. |
Quick Start & Initial Admin Account
Deploy Bryfo with Docker Compose, create your first administrator account, choose LAN HTTP vs. HTTPS reverse proxy, and complete your 5-minute post-boot setup.
Production Hardening, Split Topologies & Reverse Proxy
Hardened deploy/docker-compose.yml container sandboxing, APP_MODE=api|worker horizontal scaling, Nginx/Caddy/Cloudflare SSE templates, and local bge-m3 embedding sidecar.