diff --git a/.env.example b/.env.example index 0f9d30b..4f5f68b 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,9 @@ # # The heimdall service serves the Blazor UI, REST API, SignalR hubs, # and Hangfire background jobs in a single process on port 5000. +# +# PRODUCTION: Use Docker secrets (docker/secrets/) for sensitive values. +# See docker-compose.prod.yml header for instructions. # Database DATABASE_URL=Host=postgresql;Port=5432;Database=heimdall;Username=heimdall;Password=heimdall @@ -33,7 +36,7 @@ ALARIK_JWT=ChangeMeAtLeast32BytesLongKeyInProd! # Primary: Sentry__Dsn (ASP.NET Core config convention) # Fallback: SENTRY_DSN (legacy, for backward compatibility) # When unset/empty, the Sentry SDK is not initialized (graceful no-op). -Sentry__Dsn=https://db94b9fc2f36425f9eb4b9f6f347dc73@glitchtip.tordais.cc/6 +Sentry__Dsn=https://db94b9...dc73@glitchtip.tordais.cc/6 Sentry__TracesSampleRate=0.05 Sentry__Release=heimdall@1.0.0 @@ -56,4 +59,14 @@ EMAIL__USE_SSL=true # ntfy push notifications NTFY__BASE_URL=http://ntfy:80 NTFY__TOKEN= -SENTRY_DSN=${Sentry__Dsn} + +# Coturn (TURN relay for WebRTC) +COTURN_SECRET=ChangeMeAtLeast32BytesLongCoturnSecret! +COTURN_REALM=heimdall.local + +# Ollama (local LLM for daily summaries) +OLLAMA_PORT=11434 + +# Redis (SignalR backplane, optional — scaling) +REDIS_PORT=6379 +REDIS_PASSWORD= diff --git a/.gitignore b/.gitignore index c225234..68aff6a 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,7 @@ docker-compose.override.yml docker/data/ docker/pgdata/ docker/recordings/ +docker/secrets/ # ────────────────────────────────────────────── # IDE diff --git a/docker/docker-compose.prod.yml b/docker/docker-compose.prod.yml index f5e11d2..7498fc6 100644 --- a/docker/docker-compose.prod.yml +++ b/docker/docker-compose.prod.yml @@ -3,6 +3,16 @@ # Usage: docker compose -f docker/docker-compose.prod.yml up -d # Prerequisite: cp .env.example .env && edit secrets # +# Secrets are stored in docker/secrets/ (gitignored). Create them with: +# mkdir -p docker/secrets +# openssl rand -base64 32 > docker/secrets/jwt_signing_key +# openssl rand -base64 32 > docker/secrets/jwt_refresh_key +# openssl rand -base64 32 > docker/secrets/coturn_secret +# echo -n "your-db-password" > docker/secrets/db_password +# echo -n "your-alarik-admin-password" > docker/secrets/alarik_admin_password +# echo -n "your-alarik-jwt" > docker/secrets/alarik_jwt +# echo -n "your-smtp-password" > docker/secrets/smtp_password +# # Images are published by the CI pipeline on main branch pushes: # eltruncho/heimdall:latest # eltruncho/heimdall-agent:latest @@ -23,7 +33,9 @@ services: environment: POSTGRES_DB: ${POSTGRES_DB:-heimdall} POSTGRES_USER: ${POSTGRES_USER:-heimdall} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required} + POSTGRES_PASSWORD_FILE: /run/secrets/db_password + secrets: + - db_password ports: - "${POSTGRES_PORT:-5432}:5432" volumes: @@ -48,9 +60,12 @@ services: API_BASE_URL: ${ALARIK_API_BASE_URL:-http://localhost:9000} CONSOLE_BASE_URL: ${ALARIK_CONSOLE_BASE_URL:-http://localhost:9001} ADMIN_USERNAME: ${ALARIK_ADMIN_USERNAME:-heimdall} - ADMIN_PASSWORD: ${ALARIK_ADMIN_PASSWORD:?ALARIK_ADMIN_PASSWORD is required} - JWT: ${ALARIK_JWT:?ALARIK_JWT is required} + ADMIN_PASSWORD_FILE: /run/secrets/alarik_admin_password + JWT_FILE: /run/secrets/alarik_jwt ALLOW_ACCOUNT_CREATION: false + secrets: + - alarik_admin_password + - alarik_jwt volumes: - alarik_storage:/app/Storage logging: *default-logging @@ -75,11 +90,9 @@ services: heimdall: image: eltruncho/heimdall:latest environment: - # Database + # Database (password from secret, rest from env) DATABASE_URL: ${DATABASE_URL:?DATABASE_URL is required} - # JWT - JWT__Key: ${JWT__Key:?JWT__Key is required} - JWT__RefreshKey: ${JWT__RefreshKey:?JWT__RefreshKey is required} + # JWT (keys from secrets) JWT__Issuer: ${JWT__Issuer:-heimdall} JWT__Audience: ${JWT__Audience:-heimdall-api} # ASP.NET @@ -90,14 +103,29 @@ services: # Monolith: internal HTTP calls (circuit-triggered) must target the # container's own listener, NOT the host-mapped origin the browser sees. API_BASE_URL: ${API_BASE_URL:-http://localhost:8080} - # Error tracking + # Ollama (optional — daily summaries) + Ollama__Endpoint: http://ollama:11434 + # Coturn (WebRTC relay) + Coturn__Url: turns:coturn:3478 + # Redis (SignalR backplane, optional — scaling) + ConnectionStrings__Redis: redis:6379 + # Sentry / GlitchTip (error tracking) + Sentry__Dsn: ${SENTRY_DSN:-} + Sentry__TracesSampleRate: ${SENTRY_TRACES_SAMPLE_RATE:-0.05} + Sentry__Release: ${SENTRY_RELEASE:-} + secrets: + - jwt_signing_key + - jwt_refresh_key ports: - "${WEB_PORT:-5000}:8080" volumes: - heimdall_data:/var/lib/heimdall + - dataprotection_keys:/root/.aspnet/DataProtection-Keys depends_on: postgresql: condition: service_healthy + redis: + condition: service_healthy healthcheck: test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/healthz"] interval: 30s @@ -152,6 +180,71 @@ services: logging: *default-logging # no networks: host networking + # ── Optional services ────────────────────────────────────────── + + coturn: + image: coturn/coturn:4.6 + # TURN relay for WebRTC — network_mode host required for UDP ports. + command: > + -n --use-auth-secret + --static-auth-secret-file=/run/secrets/coturn_secret + --realm=${COTURN_REALM:-heimdall.local} + --fingerprint + --no-tlsv1 + --no-tlsv1_1 + --log-file=stdout + network_mode: host + secrets: + - coturn_secret + restart: unless-stopped + logging: *default-logging + + ollama: + image: ollama/ollama:latest + # Local LLM for daily summaries and event analysis. + # GPU passthrough: add --gpus all or mount /dev/dri for Intel/AMD. + restart: unless-stopped + ports: + - "${OLLAMA_PORT:-11434}:11434" + volumes: + - ollama_data:/root/.ollama + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:11434/api/tags"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 30s + logging: *default-logging + networks: + - heimdall-net + # Uncomment for GPU passthrough: + # deploy: + # resources: + # reservations: + # devices: + # - driver: nvidia + # count: all + # capabilities: [gpu] + + redis: + image: redis:7-alpine + # SignalR backplane (scaling) + cache. + command: redis-server --requirepass ${REDIS_PASSWORD:-} --appendonly yes + ports: + - "${REDIS_PORT:-6379}:6379" + volumes: + - redis_data:/data + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s + restart: unless-stopped + logging: *default-logging + networks: + - heimdall-net + volumes: pgdata: driver: local @@ -163,6 +256,28 @@ volumes: driver: local ntfy_data: driver: local + dataprotection_keys: + driver: local + ollama_data: + driver: local + redis_data: + driver: local + +secrets: + db_password: + file: ./secrets/db_password + jwt_signing_key: + file: ./secrets/jwt_signing_key + jwt_refresh_key: + file: ./secrets/jwt_refresh_key + coturn_secret: + file: ./secrets/coturn_secret + alarik_admin_password: + file: ./secrets/alarik_admin_password + alarik_jwt: + file: ./secrets/alarik_jwt + smtp_password: + file: ./secrets/smtp_password networks: heimdall-net: diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 8da59d7..e6b3131 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -87,6 +87,12 @@ services: ASPNETCORE_URLS: http://+:8080 # CORS (for external agents and API clients) Cors__AllowedOrigins: ${Cors__AllowedOrigins:-*} + # Ollama (optional — daily summaries) + Ollama__Endpoint: http://ollama:11434 + # Coturn (WebRTC relay) + Coturn__Url: turns:coturn:3478 + # Redis (SignalR backplane, optional — scaling) + ConnectionStrings__Redis: redis:6379 # Error tracking ports: - "${WEB_PORT:-5000}:8080" @@ -153,6 +159,57 @@ services: logging: *default-logging # no networks: host networking + # ── Optional services (dev) ──────────────────────────────────── + + coturn: + image: coturn/coturn:4.6 + command: > + -n --use-auth-secret + --static-auth-secret=${COTURN_SECRET:-ChangeMeAtLeast32BytesLongCoturnSecret!} + --realm=${COTURN_REALM:-heimdall.local} + --fingerprint + --no-tlsv1 + --no-tlsv1_1 + --log-file=stdout + network_mode: host + restart: unless-stopped + logging: *default-logging + + ollama: + image: ollama/ollama:latest + restart: unless-stopped + ports: + - "${OLLAMA_PORT:-11434}:11434" + volumes: + - ollama_data:/root/.ollama + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:11434/api/tags"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 30s + logging: *default-logging + networks: + - heimdall-net + + redis: + image: redis:7-alpine + command: redis-server --appendonly yes + ports: + - "${REDIS_PORT:-6379}:6379" + volumes: + - redis_data:/data + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s + restart: unless-stopped + logging: *default-logging + networks: + - heimdall-net + volumes: pgdata: driver: local @@ -164,6 +221,10 @@ volumes: driver: local ntfy_data: driver: local + ollama_data: + driver: local + redis_data: + driver: local networks: heimdall-net: