Skip to content

fix(selfhost): harden database and redis security for production depl…#14813

Open
LeonardoJaques wants to merge 2 commits intotoeverything:canaryfrom
LeonardoJaques:fix-selfhost-security
Open

fix(selfhost): harden database and redis security for production depl…#14813
LeonardoJaques wants to merge 2 commits intotoeverything:canaryfrom
LeonardoJaques:fix-selfhost-security

Conversation

@LeonardoJaques
Copy link
Copy Markdown

@LeonardoJaques LeonardoJaques commented Apr 10, 2026

…oyments

Remove POSTGRES_HOST_AUTH_METHOD: trust, add Redis password authentication, isolate services on internal Docker network, bind app to 127.0.0.1 only, and add security checklist to README.

Summary by CodeRabbit

  • Documentation

    • Added a self-hosted security checklist covering credentials, authentication, network exposure, and backup guidance.
  • Chores

    • Strengthened environment defaults to require strong DB and Redis passwords.
    • Enforced service authentication and local-only binding for the app.
    • Introduced internal network isolation for services and guidance to protect database/cache ports.

…oyments

Remove POSTGRES_HOST_AUTH_METHOD: trust, add Redis password authentication,
isolate services on internal Docker network, bind app to 127.0.0.1 only,
and add security checklist to README.
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions bot added the docs Improvements or additions to documentation label Apr 10, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

Updates to self-hosted Docker configs and docs to enforce credentials (DB/Redis), bind the app to loopback, enable Redis authentication, segment internal/external networks in Compose, and add a Security Checklist in README with deployment hardening steps.

Changes

Cohort / File(s) Summary
Environment Configuration
.docker/selfhost/.env.example
Set DB_PASSWORD placeholder to CHANGE_ME_to_a_strong_password; added REDIS_PASSWORD=CHANGE_ME_to_a_strong_redis_password and accompanying guidance comments.
Compose Configuration
.docker/selfhost/compose.yml
Bound app port to 127.0.0.1; made DB_USERNAME/DB_PASSWORD and REDIS_PASSWORD required via ${...:? ... not set}; added REDIS_SERVER_PASSWORD env for services; enabled redis-server --requirepass and updated authenticated healthcheck; removed POSTGRES_HOST_AUTH_METHOD: trust; introduced affine_internal and affine_external networks and adjusted service attachments.
Documentation
README.md
Added a "Security Checklist" under Self-Host instructing to copy/update .env, enforce DB/Redis passwords, avoid trust auth, use internal networks/no host ports, bind to 127.0.0.1 behind a reverse proxy with HTTPS, block DB/cache ports on host firewall, and choose appropriate backup methods.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: hardening database and Redis security for production self-hosted deployments, which aligns with the core modifications to credentials, authentication, network isolation, and security guidance.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.docker/selfhost/compose.yml:
- Around line 22-23: The Compose file uses unchecked variable interpolation
(e.g., REDIS_SERVER_PASSWORD=${REDIS_PASSWORD} and
DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@postgres:5432/${DB_DATABASE:-affine}),
which can expand to empty strings; update these to require the secrets at parse
time using the ${VAR:?message} form for REDIS_PASSWORD and DB_PASSWORD (and
similarly for DB_USERNAME/DB_DATABASE where appropriate) so interpolation fails
fast—replace REDIS_SERVER_PASSWORD=${REDIS_PASSWORD} with
REDIS_SERVER_PASSWORD=${REDIS_PASSWORD:?REDIS_PASSWORD not set} and change the
DATABASE_URL to use ${DB_USERNAME:?DB_USERNAME not
set}:${DB_PASSWORD:?DB_PASSWORD not set} (and apply the same ${VAR:?msg} pattern
to the other occurrences noted at lines 41-42, 55-57, 71-72).
- Line 57: The healthcheck currently uses "incr ping" which mutates Redis state;
change the command in the compose healthcheck from the redis-cli invocation that
contains ['CMD', 'redis-cli', '-a', '${REDIS_PASSWORD}', '--no-auth-warning',
'--raw', 'incr', 'ping'] to use a read-only PING probe instead (e.g., replace
'incr' with 'ping' so it runs redis-cli ... '--raw' 'ping'), preserving
authentication flags and '--no-auth-warning'. Ensure the healthcheck still
returns success on a proper PONG response and does not perform any writes.

In `@README.md`:
- Line 189: Replace the current sentence that says "Schedule regular `pg_dump`
backups of the `DB_DATA_LOCATION` volume" with a clarified statement that
`pg_dump` performs logical backups of the database (connects to the server and
exports SQL/data) and does not back up the `DB_DATA_LOCATION`/PGDATA filesystem;
explicitly instruct operators to use `pg_basebackup` or WAL archiving (or a
filesystem-level backup) for physical/PGDATA backups and keep `pg_dump` guidance
limited to logical backups of the database.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b06a1156-ae4f-4c2c-ac91-9512dc3a2b85

📥 Commits

Reviewing files that changed from the base of the PR and between 0b4d25f and a3d2667.

📒 Files selected for processing (3)
  • .docker/selfhost/.env.example
  • .docker/selfhost/compose.yml
  • README.md

…healthcheck, backup docs

- Use \${VAR:?msg} for REDIS_PASSWORD, DB_PASSWORD, DB_USERNAME in compose so
  docker compose fails immediately if secrets are unset instead of silently
  passing empty strings to the app/database/redis.
- Fix Redis healthcheck: replace 'incr ping' (mutating) with 'ping' (read-only).
- Clarify backup item in README: pg_dump is for logical backups; pg_basebackup
  or WAL archiving should be used for physical PGDATA backups.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
.docker/selfhost/compose.yml (1)

57-57: ⚠️ Potential issue | 🔴 Critical

Critical: Redis healthcheck password not interpolated due to single quotes.

On Line 57, ${REDIS_PASSWORD} is wrapped in single quotes within the YAML sequence. Docker Compose does not interpolate variables inside single quotes, causing the literal string ${REDIS_PASSWORD} to be passed to redis-cli. This fails to authenticate against the actual password set on Line 55 (redis-server --requirepass ${REDIS_PASSWORD:?...}), causing the healthcheck to fail and blocking dependent services from starting.

Switch to double quotes to enable interpolation:

Fix
-      test: ['CMD', 'redis-cli', '-a', '${REDIS_PASSWORD}', '--no-auth-warning', '--raw', 'ping']
+      test: ['CMD', 'redis-cli', '-a', "${REDIS_PASSWORD:?REDIS_PASSWORD not set}", '--no-auth-warning', '--raw', 'ping']
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.docker/selfhost/compose.yml at line 57, The healthcheck command entry
"test: ['CMD', 'redis-cli', '-a', '${REDIS_PASSWORD}', '--no-auth-warning',
'--raw', 'ping']" uses single quotes so ${REDIS_PASSWORD} is not interpolated;
update that YAML sequence to use double quotes around the ${REDIS_PASSWORD}
element (e.g., " ${REDIS_PASSWORD} ") so Docker Compose substitutes the actual
REDIS_PASSWORD value and the redis-cli authentication succeeds.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In @.docker/selfhost/compose.yml:
- Line 57: The healthcheck command entry "test: ['CMD', 'redis-cli', '-a',
'${REDIS_PASSWORD}', '--no-auth-warning', '--raw', 'ping']" uses single quotes
so ${REDIS_PASSWORD} is not interpolated; update that YAML sequence to use
double quotes around the ${REDIS_PASSWORD} element (e.g., " ${REDIS_PASSWORD} ")
so Docker Compose substitutes the actual REDIS_PASSWORD value and the redis-cli
authentication succeeds.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 061a0aa4-1acb-4fda-95ed-b29cba231976

📥 Commits

Reviewing files that changed from the base of the PR and between a3d2667 and 4160929.

📒 Files selected for processing (2)
  • .docker/selfhost/compose.yml
  • README.md
✅ Files skipped from review due to trivial changes (1)
  • README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants