# Environment Variables & CLI Flags

> Complete reference for all OvertCMS Core environment variables, CLI flags, defaults, precedence rules, and startup validation invariants.

OvertCMS Core loads runtime configuration in strictly increasing order of precedence:

1. **Built-in defaults** (`config.Default()`)
2. **Environment variables** (`OVERTCMS_*`)
3. **CLI flags** passed to `overtcms serve`, `overtcms migrate`, `overtcms export`, or `overtcms import`

Every option is validated strictly at startup before any database migration or network listener opens. Invalid URLs, duplicate bind addresses, missing S3 credentials, or short secret keys fail fast with a descriptive error.

## Database

| Environment Variable | CLI Flag | Default | Description |
| :--- | :--- | :--- | :--- |
| `OVERTCMS_DB_DRIVER` | `--db-driver` | `sqlite` | Storage engine: `sqlite` or `postgres`. |
| `OVERTCMS_DB_DSN` | `--db-dsn` | `./.data/overtcms.db` (for `sqlite`) | Database connection string. Required (no default) when `db-driver=postgres`. |

<Warning>
  When `OVERTCMS_DB_DRIVER=postgres`, you **must** explicitly provide `OVERTCMS_DB_DSN` (for example, `postgres://user:pass@host:5432/overtcms?sslmode=require`). Startup fails if `db-dsn` is empty.
</Warning>

## Runtime Planes & HTTP Listeners

OvertCMS Core can run all enabled HTTP planes on a single shared listener (`OVERTCMS_BIND`), or isolate individual planes onto separate ports/interfaces (`OVERTCMS_DELIVERY_BIND`, `OVERTCMS_AGENT_BIND`, `OVERTCMS_ADMIN_BIND`).

| Environment Variable | CLI Flag | Default | Description |
| :--- | :--- | :--- | :--- |
| `OVERTCMS_PLANES` | `--planes` | `delivery,agent,admin,worker` | Comma-separated list of active planes. Valid values: `delivery`, `agent`, `admin`, `worker`. At least one plane must be enabled. |
| `OVERTCMS_BIND` | `--bind` | `:8080` | Combined HTTP listener address (`host:port`) used by any enabled HTTP plane that does not have an explicit plane-specific bind. |
| `OVERTCMS_DELIVERY_BIND` | `--delivery-bind` | `""` | Dedicated `host:port` listener for the Delivery Plane (`/delivery/v1/*`). |
| `OVERTCMS_AGENT_BIND` | `--agent-bind` | `""` | Dedicated `host:port` listener for the Agent Plane (`/agent/v1/*`, `/mcp`, `/.well-known/agent-cms.json`, `/llms.txt`). |
| `OVERTCMS_ADMIN_BIND` | `--admin-bind` | `""` | Dedicated `host:port` listener for the Admin Plane (`/admin-api/v1/*`). |

**Listener validation rules:**
- All configured addresses must be valid `host:port` pairs.
- Duplicate non-ephemeral bind addresses across `bind`, `delivery-bind`, `agent-bind`, and `admin-bind` are rejected at startup.
- Port `:0` (ephemeral OS-assigned port) is allowed on multiple listeners simultaneously (useful in automated tests).
- Every HTTP listener exposes `/healthz` and `/readyz` and uses a `10s` `ReadHeaderTimeout`, `120s` `IdleTimeout`, and `15s` graceful shutdown drain timeout.

## Logging

| Environment Variable | CLI Flag | Default | Description |
| :--- | :--- | :--- | :--- |
| `OVERTCMS_LOG_LEVEL` | `--log-level` | `info` | Structured `slog` level: `debug`, `info`, `warn`, or `error`. |
| `OVERTCMS_LOG_FORMAT` | `--log-format` | `json` | Log encoder format: `json` or `text`. |

## Default Site Bootstrap

On startup, `overtcms serve` idempotently ensures the default organization (`default`) and default site exist. These values apply when bootstrapping a fresh database:

| Environment Variable | CLI Flag | Default | Description |
| :--- | :--- | :--- | :--- |
| `OVERTCMS_DEFAULT_SITE_NAME` | `--default-site-name` | `Default Site` | Display name of the bootstrapped default site (non-empty). |
| `OVERTCMS_DEFAULT_SITE_SLUG` | `--default-site-slug` | `default` | Slug of the default site. Must match `^[a-z0-9]+(?:-[a-z0-9]+)*$`. |
| `OVERTCMS_DEFAULT_SITE_BASE_URL` | `--default-site-base-url` | `""` | Optional canonical site base URL (`http://` or `https://`, no whitespace) used to compute `publicUrl` from `urlTemplate`. |
| `OVERTCMS_DEFAULT_SITE_TIMEZONE` | `--default-site-timezone` | `UTC` | Valid IANA timezone identifier (for example, `America/New_York`, `Europe/Berlin`). |

## Media Storage & S3 / R2

OvertCMS Core implements both local filesystem storage and pure-Go AWS Signature Version 4 S3/R2-compatible storage with zero external SDK dependencies.

| Environment Variable | CLI Flag | Default | Description |
| :--- | :--- | :--- | :--- |
| `OVERTCMS_MEDIA_DRIVER` | `--media-driver` | `local` | Media backend: `local` or `s3`. |
| `OVERTCMS_MEDIA_LOCAL_DIR` | `--media-local-dir` | `./.data/media` | Root directory for local media objects (required when `media-driver=local`). |
| `OVERTCMS_MEDIA_MAX_DIRECT_BYTES` | `--media-max-direct-bytes` | `26214400` (25 MiB) | Maximum byte size for direct multipart uploads and URL sideloading. Must be positive. |
| `OVERTCMS_MEDIA_MAX_PRESIGNED_BYTES` | `--media-max-presigned-bytes` | `524288000` (500 MiB) | Maximum byte size for presigned upload intents. Must be positive. |
| `OVERTCMS_MEDIA_CDN_URL_TEMPLATE` | `--media-cdn-url-template` | `""` | Optional public URL template for media assets. Must start with `http://`, `https://`, or `/` and contain no whitespace. Supported placeholders: `{key}`, `{id}`, `{siteId}`, `{ext}`. When empty, assets serve from `/delivery/v1/media/{id}`. |
| `OVERTCMS_S3_ENDPOINT` | `--s3-endpoint` | `""` | Custom S3-compatible endpoint URL (e.g., Cloudflare R2, MinIO, DigitalOcean Spaces). Defaults to `https://s3.{region}.amazonaws.com`. |
| `OVERTCMS_S3_REGION` | `--s3-region` | `us-east-1` | AWS/S3 region used for SigV4 credential scope (`auto` for Cloudflare R2). |
| `OVERTCMS_S3_BUCKET` | `--s3-bucket` | `""` | Bucket name (**required** when `media-driver=s3`). |
| `OVERTCMS_S3_ACCESS_KEY_ID` | `--s3-access-key-id` | `""` | S3 access key ID (**required** when `media-driver=s3`). |
| `OVERTCMS_S3_SECRET_ACCESS_KEY` | `--s3-secret-access-key` | `""` | S3 secret access key (**required** when `media-driver=s3`). |
| `OVERTCMS_S3_FORCE_PATH_STYLE` | `--s3-force-path-style` | `false` | Use path-style URLs (`https://endpoint/bucket/key`) instead of virtual-hosted style (`https://bucket.endpoint/key`). Set `true` for MinIO and most custom endpoints. |

## Authentication, Sessions, WebAuthn & OIDC

| Environment Variable | CLI Flag | Default | Description |
| :--- | :--- | :--- | :--- |
| `OVERTCMS_SECRET_KEY` | `--secret-key` | `""` (ephemeral random 32 bytes) | Master secret (**at least 32 bytes** when set) used for HMAC-SHA-256 API key hashing, Access JWT signing (HS256), and AES-256-GCM encryption of TOTP secrets and webhook signing secrets. |
| `OVERTCMS_AUTH_REQUIRED` | `--auth-required` | `true` | Enforce authentication on Agent and Admin planes. Set `false` only in isolated local development/testing. |
| `OVERTCMS_DELIVERY_REQUIRE_API_KEY` | `--delivery-require-api-key` | `false` | Require a valid `delivery:read` API key (`Authorization: Bearer ocms_...`) on all Delivery Plane routes and `/llms.txt`. |
| `OVERTCMS_ACCESS_TOKEN_TTL` | `--access-token-ttl` | `15m` | Lifetime of Admin Plane Access JWTs (`time.ParseDuration` format). Must be positive. |
| `OVERTCMS_REFRESH_TOKEN_TTL` | `--refresh-token-ttl` | `720h` (30 days) | Lifetime of rotating refresh sessions. Must be positive. |
| `OVERTCMS_STEP_UP_MFA_TTL` | `--step-up-mfa-ttl` | `15m` | Freshness window for Step-Up MFA verification before sensitive Admin mutations. Must be positive. |
| `OVERTCMS_COOKIE_SECURE` | `--cookie-secure` | `true` | Sets the `Secure` attribute on `overtcms_access`, `overtcms_refresh`, and `overtcms_oidc_state` cookies, and enforces `https://` Origin matching for cookie CSRF checks. Set `false` for plain-HTTP `localhost` development. |
| `OVERTCMS_WEBAUTHN_RP_ID` | `--webauthn-rp-id` | `localhost` | WebAuthn Relying Party ID (domain name, e.g. `cms.example.com`). Must not be empty. |
| `OVERTCMS_WEBAUTHN_RP_ORIGIN` | `--webauthn-rp-origin` | `http://localhost:8080` | Expected WebAuthn origin (`http://` or `https://`). Also accepted as an allowed CSRF `Origin` for Admin cookie mutations (ignored on non-localhost hosts if left at the default `http://localhost:8080`). |
| `OVERTCMS_OIDC_ISSUER` | `--oidc-issuer` | `""` | OIDC Provider Issuer URL (discovers `/.well-known/openid-configuration`). |
| `OVERTCMS_OIDC_CLIENT_ID` | `--oidc-client-id` | `""` | OIDC Client ID (**required** when `oidc-issuer` is set). |
| `OVERTCMS_OIDC_CLIENT_SECRET` | `--oidc-client-secret` | `""` | Optional OIDC Client Secret for confidential clients (PKCE S256 is always sent). |
| `OVERTCMS_OIDC_REDIRECT_URL` | `--oidc-redirect-url` | `""` | Registered OIDC callback URL, e.g. `https://cms.example.com/admin-api/v1/auth/oidc/callback` (**required** when `oidc-issuer` is set). |

<Warning>
  **Always set `OVERTCMS_SECRET_KEY` in production!** If omitted, OvertCMS Core generates a random ephemeral 32-byte key on startup—meaning every restart invalidates all existing API keys, Access JWTs, encrypted TOTP secrets, and encrypted webhook secrets.
</Warning>

## Caching, Rate Limiting, CDN Purge & Worker

| Environment Variable | CLI Flag | Default | Description |
| :--- | :--- | :--- | :--- |
| `OVERTCMS_REDIS_URL` | `--redis-url` | `""` | Optional Redis/Valkey URL (`redis://[:pass@]host:port[/db]` or `rediss://...`). Enables shared L2 Delivery Cache and distributed Lua rate limiting. Falls back gracefully to in-memory if unset or unreachable at startup. |
| `OVERTCMS_CDN_PURGE_WEBHOOK_URL` | `--cdn-purge-webhook-url` | `""` | Optional HTTP/HTTPS endpoint to receive `Surrogate-Key` purge notifications whenever outbox events are processed. |
| `OVERTCMS_CDN_PURGE_SECRET` | `--cdn-purge-secret` | `""` | Optional HMAC-SHA-256 secret used to sign `X-OvertCMS-Signature` on CDN purge webhook requests. |
| `OVERTCMS_WORKER_POLL_INTERVAL` | `--worker-poll-interval` | `5s` | Background worker tick interval for scheduled publish/unpublish, media cleanup, outbox fan-out, and webhook delivery. Worker lease TTL is `max(3 * pollInterval, 30s)`. |
| `OVERTCMS_WEBHOOK_ALLOW_PRIVATE_IPS` | `--webhook-allow-private-ips` | `false` | Allows outbound webhooks and CDN purges to target private/loopback IP addresses. Keep `false` in production to enforce SSRF protection. |

## Email & SMTP Notifications (Optional)

Outbound email is completely optional. When omitted, OvertCMS operates in link-only mode for team invitations. See [Email & SMTP Notifications](/self-hosting/email-and-smtp) for full setup and verification instructions.

| Environment Variable | CLI Flag | Default | Description |
| :--- | :--- | :--- | :--- |
| `OVERTCMS_SMTP_HOST` | `--smtp-host` | `""` | SMTP server hostname (e.g., `smtp.resend.com`). Leave empty to disable outbound SMTP. |
| `OVERTCMS_SMTP_PORT` | `--smtp-port` | `587` | SMTP server port (`1`–`65535`). |
| `OVERTCMS_SMTP_USERNAME` | `--smtp-username` | `""` | Optional SMTP authentication username. |
| `OVERTCMS_SMTP_PASSWORD` | `--smtp-password` | `""` | Optional SMTP authentication password or API key. |
| `OVERTCMS_SMTP_FROM` | `--smtp-from` | `""` | Sender address in RFC 5322 format (e.g., `OvertCMS <no-reply@example.com>`). **Required** when `smtp-host` is set. |
| `OVERTCMS_SMTP_TLS_MODE` | `--smtp-tls-mode` | `auto` | TLS negotiation mode: `auto` (implicit TLS on port `465`, STARTTLS otherwise), `starttls`, `tls`, or `none`. |
| `OVERTCMS_ADMIN_BASE_URL` | `--admin-base-url` | `""` | Base URL of your Admin UI (e.g., `https://cms.example.com`) used when generating clickable invitation links in emails. |

## Production Environment Example

```bash
# Database (PostgreSQL)
OVERTCMS_DB_DRIVER=postgres
OVERTCMS_DB_DSN=postgres://overtcms:strong-password@db.internal:5432/overtcms?sslmode=require

# Master Secret (32+ bytes)
OVERTCMS_SECRET_KEY=replace-with-64-hex-chars-from-openssl-rand-hex-32

# Split-Plane Listeners
OVERTCMS_PLANES=delivery,agent,admin,worker
OVERTCMS_DELIVERY_BIND=:8081
OVERTCMS_AGENT_BIND=10.0.1.10:8082
OVERTCMS_ADMIN_BIND=10.0.1.10:8083

# Site Defaults
OVERTCMS_DEFAULT_SITE_NAME="Acme Docs"
OVERTCMS_DEFAULT_SITE_SLUG=acme
OVERTCMS_DEFAULT_SITE_BASE_URL=https://acme.example.com
OVERTCMS_DEFAULT_SITE_TIMEZONE=UTC

# S3 / Cloudflare R2 Media Storage
OVERTCMS_MEDIA_DRIVER=s3
OVERTCMS_S3_ENDPOINT=https://<account-id>.r2.cloudflarestorage.com
OVERTCMS_S3_REGION=auto
OVERTCMS_S3_BUCKET=acme-cms-media
OVERTCMS_S3_ACCESS_KEY_ID=your-access-key
OVERTCMS_S3_SECRET_ACCESS_KEY=your-secret-key
OVERTCMS_S3_FORCE_PATH_STYLE=true
OVERTCMS_MEDIA_CDN_URL_TEMPLATE=https://cdn.acme.example.com/{key}

# Auth, WebAuthn & OIDC
OVERTCMS_COOKIE_SECURE=true
OVERTCMS_WEBAUTHN_RP_ID=cms.acme.example.com
OVERTCMS_WEBAUTHN_RP_ORIGIN=https://cms.acme.example.com

# Distributed Cache, Rate Limiting & CDN Purge
OVERTCMS_REDIS_URL=rediss://:valkey-pass@valkey.internal:6379/0
OVERTCMS_CDN_PURGE_WEBHOOK_URL=https://purge-bridge.acme.example.com/purge
OVERTCMS_CDN_PURGE_SECRET=replace-with-cdn-purge-secret
OVERTCMS_WORKER_POLL_INTERVAL=5s
```
