Merge pull request 'fix(security): secure redis instance, harden prod compose, and fix minio media proxy' (#6) from redis-issue-fix into main

Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-ops/pulls/6
Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
Amit Salunke 2026-10-20 04:49:59 +00:00
commit 6504fd3e68
3 changed files with 188 additions and 25 deletions

View File

@ -87,7 +87,15 @@ server {
return 301 https://acupedia.in$request_uri; return 301 https://acupedia.in$request_uri;
} }
# MinIO S3 Presigned Media Proxy (/acupedia-media/) # MinIO S3 Presigned Media Proxy (/accupedia-media/ and /acupedia-media/)
location /accupedia-media/ {
proxy_pass http://minio_storage;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /acupedia-media/ { location /acupedia-media/ {
proxy_pass http://minio_storage; proxy_pass http://minio_storage;
proxy_set_header Host $http_host; proxy_set_header Host $http_host;

View File

@ -29,8 +29,9 @@ services:
image: redis:7-alpine image: redis:7-alpine
container_name: acupedia-redis container_name: acupedia-redis
restart: unless-stopped restart: unless-stopped
command: redis-server --requirepass "${REDIS_PASSWORD:-AcupediaSecureRedis2026!#}"
ports: ports:
- "${REDIS_PORT:-6379}:6379" - "127.0.0.1:${REDIS_PORT:-6379}:6379"
volumes: volumes:
- acupedia-redis-data:/data - acupedia-redis-data:/data
networks: networks:
@ -106,9 +107,10 @@ services:
MEDIA_URL_TTL_SECONDS: 900 MEDIA_URL_TTL_SECONDS: 900
REDIS_HOST: redis REDIS_HOST: redis
REDIS_PORT: 6379 REDIS_PORT: 6379
REDIS_URL: redis://redis:6379/0 REDIS_PASSWORD: ${REDIS_PASSWORD:-AcupediaSecureRedis2026!#}
REDIS_URL: redis://:${REDIS_PASSWORD:-AcupediaSecureRedis2026!#}@redis:6379/0
CACHE_ENABLED: "true" CACHE_ENABLED: "true"
CACHE_REDIS_URL: redis://redis:6379/0 CACHE_REDIS_URL: redis://:${REDIS_PASSWORD:-AcupediaSecureRedis2026!#}@redis:6379/0
SMTP_HOST: mailhog SMTP_HOST: mailhog
SMTP_PORT: 1025 SMTP_PORT: 1025
JWT_SECRET: ${JWT_SECRET:-b4f8c9b3d0a2f4c9b3d0a2f4c9b3d0a2f4c9b3d0a2f4c9b3d0a2f4c9b3d0a2f4} JWT_SECRET: ${JWT_SECRET:-b4f8c9b3d0a2f4c9b3d0a2f4c9b3d0a2f4c9b3d0a2f4c9b3d0a2f4c9b3d0a2f4}

View File

@ -1,51 +1,204 @@
version: '3.8'
services: services:
# ============================================================
# 1. PostgreSQL Database
# ============================================================
postgres: postgres:
image: ${ACUPEDIA_POSTGRES_IMAGE:?Set ACUPEDIA_POSTGRES_IMAGE} image: postgres:16-alpine
container_name: acupedia-postgres
restart: unless-stopped restart: unless-stopped
environment: environment:
POSTGRES_DB: ${POSTGRES_DB:-acupedia} POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER:-acupedia} POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ports: ports:
- "${POSTGRES_PORT:-5432}:5432" # Bound strictly to 127.0.0.1 (Localhost only - safe from public internet)
- "127.0.0.1:${POSTGRES_PORT:-5432}:5432"
volumes: volumes:
- acupedia-postgres-data:/var/lib/postgresql/data - acupedia-postgres-data:/var/lib/postgresql/data
healthcheck: healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-acupedia} -d ${POSTGRES_DB:-acupedia}"] test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 5s interval: 5s
timeout: 5s timeout: 5s
retries: 20 retries: 20
networks:
- acupedia-net
# ============================================================
# 2. Redis Cache (Secured & Internal)
# ============================================================
redis: redis:
image: ${ACUPEDIA_REDIS_IMAGE:?Set ACUPEDIA_REDIS_IMAGE} image: redis:7-alpine
container_name: acupedia-redis
restart: unless-stopped restart: unless-stopped
command: redis-server --requirepass "${REDIS_PASSWORD}"
ports: ports:
- "${REDIS_PORT:-6379}:6379" - "127.0.0.1:${REDIS_PORT:-6379}:6379"
volumes: volumes:
- acupedia-redis-data:/data - acupedia-redis-data:/data
networks:
- acupedia-net
# ============================================================
# 3. MinIO Object Storage
# ============================================================
minio: minio:
image: ${ACUPEDIA_MINIO_IMAGE:?Set ACUPEDIA_MINIO_IMAGE} image: minio/minio
container_name: acupedia-minio
restart: unless-stopped restart: unless-stopped
command: server /data --console-address ":9001" command: server /data --console-address ":9001"
environment: environment:
MINIO_ROOT_USER: ${MINIO_ACCESS_KEY:?Set MINIO_ACCESS_KEY} MINIO_ROOT_USER: ${MINIO_ACCESS_KEY}
MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY:?Set MINIO_SECRET_KEY} MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY}
ports: ports:
- "${MINIO_PORT:-9000}:9000" # Bound strictly to 127.0.0.1 - Nginx proxies public /acupedia-media/ requests
- "${MINIO_CONSOLE_PORT:-9001}:9001" - "127.0.0.1:${MINIO_PORT:-9000}:9000"
- "127.0.0.1:${MINIO_CONSOLE_PORT:-9001}:9001"
volumes: volumes:
- acupedia-minio-data:/data - acupedia-minio-data:/data
networks:
- acupedia-net
acupedia-content: # ============================================================
image: gcr.io/google-containers/pause:3.9 # 4. MailHog SMTP Server (Optional / Dev fallback)
container_name: acupedia-content # ============================================================
mailhog:
image: mailhog/mailhog:latest
container_name: acupedia-mailhog
restart: unless-stopped
ports:
# Bound strictly to 127.0.0.1 so test mail UI is not exposed publicly
- "127.0.0.1:1025:1025"
- "127.0.0.1:8025:8025"
networks:
- acupedia-net
# ============================================================
# 5. Acupedia Backend API (FastAPI)
# ============================================================
backend:
build:
context: ${ACUPEDIA_API_PATH:-../acupedia-api}
dockerfile: Dockerfile
container_name: acupedia-api
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_started
minio:
condition: service_started
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
DATABASE_HOST: postgres
DATABASE_PORT: 5432
DATABASE_URL: ${DATABASE_URL}
SYNC_DATABASE_URL: ${SYNC_DATABASE_URL}
MINIO_ENDPOINT: ${MINIO_ENDPOINT}
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
MINIO_SECURE: "${MINIO_SECURE:-false}"
MINIO_BUCKET: ${MINIO_BUCKET_NAME:-accupedia-media}
MEDIA_STORAGE_SECURE: ${MEDIA_STORAGE_SECURE:-true}
MEDIA_PRESIGN_ENDPOINT: ${MEDIA_PRESIGN_ENDPOINT:-https://api.acupedia.in}
MEDIA_STORAGE_ACCESS_KEY: ${MINIO_ACCESS_KEY}
MEDIA_STORAGE_SECRET_KEY: ${MINIO_SECRET_KEY}
MEDIA_STORAGE_BUCKET: ${MINIO_BUCKET_NAME:-accupedia-media}
MEDIA_STORAGE_REGION: ${MEDIA_STORAGE_REGION:-us-east-1}
MEDIA_URL_TTL_SECONDS: ${MEDIA_URL_TTL_SECONDS:-900}
REDIS_HOST: redis
REDIS_PORT: ${REDIS_PORT:-6379}
REDIS_PASSWORD: ${REDIS_PASSWORD}
REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379/0
CACHE_ENABLED: "true"
CACHE_REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379/0
SMTP_HOST: ${SMTP_HOST:-mailhog}
SMTP_PORT: ${SMTP_PORT:-1025}
JWT_SECRET: ${JWT_SECRET}
ACCESS_TOKEN_EXPIRE_MINUTES: ${ACCESS_TOKEN_EXPIRE_MINUTES:-1440}
RAZORPAY_KEY_ID: ${RAZORPAY_KEY_ID}
RAZORPAY_KEY_SECRET: ${RAZORPAY_KEY_SECRET}
RESEND_API_KEY: ${RESEND_API_KEY}
ENVIRONMENT: production
ports:
# Bound to localhost for local testing (Nginx proxies all public API traffic)
- "127.0.0.1:${BACKEND_PORT:-8000}:8000"
volumes: volumes:
- acupedia-content-data:/app/data - ${CONTENT_PATH:-../acupedia-content}:/app/content:ro
networks:
- acupedia-net
# ============================================================
# 6. Storefront Web App (Vite/React)
# ============================================================
store:
build:
context: ${ACUPEDIA_STORE_PATH:-../acupedia_store_ui}
dockerfile: Dockerfile
args:
VITE_BASE_PATH: ${VITE_STORE_BASE_PATH:-/store/}
container_name: acupedia-store
restart: unless-stopped
depends_on:
- backend
ports:
# Bound to localhost only (Nginx handles public traffic)
- "127.0.0.1:${STORE_PORT:-3000}:80"
networks:
- acupedia-net
# ============================================================
# 7. Admin Portal Web App (Vite/React)
# ============================================================
admin:
build:
context: ${ACUPEDIA_ADMIN_PATH:-../acupedia_web_ui}
dockerfile: Dockerfile
args:
VITE_BASE_PATH: ${VITE_ADMIN_BASE_PATH:-/admin/}
container_name: acupedia-admin
restart: unless-stopped
depends_on:
- backend
ports:
# Bound to localhost only (Nginx handles public traffic)
- "127.0.0.1:${ADMIN_PORT:-3001}:80"
networks:
- acupedia-net
# ============================================================
# 8. Central Nginx Reverse Proxy (Only public gateway)
# ============================================================
nginx:
image: nginx:alpine
container_name: acupedia-nginx
restart: unless-stopped
depends_on:
- backend
- store
- admin
- minio
ports:
# The ONLY services exposed to the public internet
- "${HTTP_PORT:-80}:80"
- "${HTTPS_PORT:-443}:443"
volumes:
- ./config/nginx/acupedia.conf:/etc/nginx/conf.d/default.conf:ro
- /etc/letsencrypt:/etc/letsencrypt:ro
- /var/www/certbot:/var/www/certbot
networks:
- acupedia-net
volumes: volumes:
acupedia-postgres-data: acupedia-postgres-data:
acupedia-redis-data: driver: local
acupedia-minio-data: acupedia-minio-data:
acupedia-content-data: driver: local
acupedia-redis-data:
driver: local
networks:
acupedia-net:
driver: bridge