Files
trustos/infra/docker-compose.yml
drjones c44fa6fcda
Some checks failed
Deploy / deploy (push) Has been cancelled
Deploy / docker-build (push) Has been cancelled
Test / backend-test (push) Has been cancelled
Test / frontend-test (push) Has been cancelled
Test / security-scan (push) Has been cancelled
Fix cross-origin API access, bcrypt login break, and weak secret key
The frontend only worked from localhost:3000 — the browser made absolute
cross-origin calls to localhost:8000, which (a) points at the visitor's own
machine when accessed via the LAN IP or Cloudflare tunnel, and (b) was blocked
by CORS (backend only allowed localhost:3000). Now all API calls are
same-origin and proxied to the backend:

- api.ts: default API base to same-origin ("") instead of localhost:8000
- docker-compose: NEXT_PUBLIC_API_URL="" (client uses relative /api)
- next.config.ts: server-side rewrite uses API_INTERNAL_URL (http://backend:8000
  inside Docker) so :3000 direct access proxies correctly
- main.py: broaden CORS via allow_origin_regex (localhost + private LAN) and an
  optional CORS_ORIGINS env var, as defense-in-depth for direct :8000 access

Login was returning 500: passlib 1.7.4 is incompatible with the bcrypt 5.0.0
actually installed in the image (requirements pin 4.1.2, but the image drifted).
- security.py: call bcrypt directly, truncating to 72 bytes; existing $2b$
  hashes verify unchanged, and it works under both bcrypt 4.x and 5.x

Security: SECRET_KEY was a known placeholder string while the app is exposed on
the LAN and via Cloudflare tunnel — anyone could forge admin JWTs. Regenerated
to a strong random value in backend/.env (gitignored; not committed).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 15:13:23 +00:00

63 lines
1.6 KiB
YAML

services:
postgres:
image: postgres:16-alpine
container_name: trustos_postgres
environment:
POSTGRES_USER: trustos
POSTGRES_PASSWORD: trustos_dev
POSTGRES_DB: trustos
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U trustos -d trustos"]
interval: 5s
timeout: 5s
retries: 10
backend:
build:
context: ../backend
dockerfile: ../infra/Dockerfile.backend
container_name: trustos_backend
env_file:
- ../backend/.env
environment:
DATABASE_URL: postgresql+asyncpg://trustos:trustos_dev@postgres:5432/trustos
SYNC_DATABASE_URL: postgresql://trustos:trustos_dev@postgres:5432/trustos
STORAGE_PATH: /app/storage
ports:
- "8000:8000"
volumes:
- ../backend:/app
- storage:/app/storage
depends_on:
postgres:
condition: service_healthy
command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
frontend:
build:
context: ../frontend
dockerfile: ../infra/Dockerfile.frontend
container_name: trustos_frontend
environment:
# Empty = same-origin API calls (proxied to backend by nginx / Next rewrite).
# Works via localhost, LAN IP, and Cloudflare tunnel without CORS.
NEXT_PUBLIC_API_URL: ""
API_INTERNAL_URL: "http://backend:8000"
ports:
- "3000:3000"
volumes:
- ../frontend:/app
- /app/node_modules
- /app/.next
depends_on:
- backend
command: npm run dev
volumes:
pgdata:
storage: