diff --git a/.env.example b/.env.example index d26fde2..602fd8e 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,7 @@ DATABASE_URL="postgresql://user:pass@localhost:5432/page_manager" # For prisma dev, use its separate shadow port; never point this at DATABASE_URL. SHADOW_DATABASE_URL="" SESSION_SECRET="" # long random string (jose HS256) -TOKEN_ENCRYPTION_KEY="" # npm run gen-key (32 bytes base64) +TOKEN_ENCRYPTION_KEY="" # any random string (hashed to a 32-byte key) — npm run gen-key works too META_APP_ID="" META_APP_SECRET="" # verifies webhook X-Hub-Signature-256 META_SYSTEM_USER_TOKEN="" # optional — pages can be connected via "Login with Facebook" instead diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fe67738 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +services: + web: + build: + context: . + environment: + DATABASE_URL: postgresql://app:${SERVICE_PASSWORD_POSTGRES}@db:5432/app + SESSION_SECRET: ${SERVICE_PASSWORD_64_SESSION} + TOKEN_ENCRYPTION_KEY: ${SERVICE_PASSWORD_64_TOKENKEY} + CRON_SECRET: ${SERVICE_PASSWORD_64_CRON} + volumes: + - web-data:/app/.data + depends_on: + db: + condition: service_healthy + healthcheck: + test: ["CMD", "curl", "-fsS", "-o", "/dev/null", "http://127.0.0.1:3000/api/health"] + interval: 30s + timeout: 5s + retries: 5 + start_period: 20s + + db: + image: postgres:17-alpine + environment: + POSTGRES_USER: app + POSTGRES_PASSWORD: ${SERVICE_PASSWORD_POSTGRES} + POSTGRES_DB: app + volumes: + - pg-data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U app -d app"] + interval: 10s + timeout: 5s + retries: 10 + +volumes: + web-data: + pg-data: diff --git a/src/lib/crypto/tokenBox.ts b/src/lib/crypto/tokenBox.ts index de6735f..4e33744 100644 --- a/src/lib/crypto/tokenBox.ts +++ b/src/lib/crypto/tokenBox.ts @@ -5,12 +5,13 @@ import crypto from "node:crypto"; // yielding a garbage token. const VERSION = "v1"; +// Derived via SHA-256 (always 32 bytes) rather than requiring the operator to +// supply exactly 32 raw bytes in base64 — any sufficiently random string works, +// including one a host platform (e.g. Coolify's SERVICE_PASSWORD_64_*) generates. function key(): Buffer { const raw = process.env.TOKEN_ENCRYPTION_KEY; if (!raw) throw new Error("TOKEN_ENCRYPTION_KEY env var is not set"); - const buf = Buffer.from(raw, "base64"); - if (buf.length !== 32) throw new Error("TOKEN_ENCRYPTION_KEY must be 32 bytes (base64)"); - return buf; + return crypto.createHash("sha256").update(raw).digest(); } export function encryptToken(plain: string): string {