Skip to content

fix(self-hosting): stop publishing Postgres and require POSTGRES_PASSWORD - #8035

Merged
waleedlatif1 merged 6 commits into
stagingfrom
fix/compose-postgres-defaults
Sep 19, 2026
Merged

waleedlatif1 merged 6 commits into
stagingfrom
fix/compose-postgres-defaults

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • docker-compose.prod.yml, docker-compose.local.yml and docker-compose.ollama.yml no longer publish the db service to the host. Every service already reaches it as db:5432 over the Compose network. A ports: mapping bound every interface, and Docker's iptables rules bypass host firewalls
  • docker-compose.prod.yml now requires POSTGRES_PASSWORD (${VAR:?}) in the db service and all three DATABASE_URLs instead of falling back to postgres, matching the auth secrets next to it. The local and Ollama dev stacks keep their defaults, since every secret there is a dev default and the port is what made it reachable
  • The error message covers upgrades too. Postgres only applies POSTGRES_PASSWORD when it creates the volume, so an install that never set it must use postgres; a freshly generated value would lock the app out of its own database
  • sim-setup writes the value before bringing the stack up (setup, start, restart, update), but only when the compose file on disk requires it. It generates a password for a new install; for an existing postgres_data volume (found by Compose labels, project name read from docker compose config --no-interpolate) it keeps postgres and prints how to rotate it. A value set in the shell environment wins, matching Compose
  • The simstudio CLI stops publishing 5432. Its containers already use their own Docker network, and it recreates them on every run
  • Docs: security, Docker and upgrade guides updated to match. The README's Cursor setup prompt now generates POSTGRES_PASSWORD

Type of Change

  • Bug fix

Testing

  • New compose-database.test.ts: password choice (new vs. existing volume vs. already set), shell-env precedence, and checks on the real compose files: no db port in any of them, and every prod POSTGRES_PASSWORD reference required. All five compose-file checks fail against the previous files
  • End to end with docker compose and pgvector/pgvector:pg17, three scenarios, all passing:
    • Install created from the previous file with no password, then switched to the new file: Compose stops with the message, sim-setup writes postgres, and the app's DATABASE_URL authenticates
    • Fresh install: sim-setup generates a 64-hex password and the app's DATABASE_URL authenticates
    • Project name derived from the directory instead of COMPOSE_PROJECT_NAME: sim-setup finds the existing volume, keeps postgres, and the app's DATABASE_URL authenticates
    • In every case docker port shows no host bindings, and a second run changes nothing
  • Local and Ollama files still render with zero config
  • sim-setup 168/168, type-check (sim-setup, cli), lint, check:audits (47), docs-manifest:check

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

🤖 Generated with Claude Code

…WORD

The Compose files published the db service on every host interface, and the production file fell back to the password postgres when POSTGRES_PASSWORD was unset. The db is now reachable only over the Compose network, and the production file refuses to start without POSTGRES_PASSWORD. sim-setup writes the value an install needs before bringing it up: a generated password for a new database, and the legacy one for a volume created before it was required, since Postgres ignores POSTGRES_PASSWORD on an existing data directory.
@vercel

vercel Bot commented Sep 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Sep 19, 2026 10:54pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with no outstanding actionable findings from the latest changes.

Summary

This PR hardens self-hosted PostgreSQL deployments by removing host port publication, requiring an explicit production database password, and teaching setup workflows to preserve compatibility with existing volumes.

  • Removes PostgreSQL host bindings from production, local, Ollama, and standalone CLI deployments.
  • Generates a password for new production installs while retaining the legacy password for detected existing volumes.
  • Updates lifecycle commands, tests, and operator documentation for installation, upgrades, rotation, and URL-safe credentials.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Start or update Compose install] --> B{Production Compose requires password?}
    B -- No --> C[Continue unchanged]
    B -- Yes --> D{Shell exports POSTGRES_PASSWORD?}
    D -- Yes --> E[Let Compose use shell value]
    D -- No --> F{Password exists in .env?}
    F -- Yes --> G[Keep recorded value]
    F -- No --> H{Existing labeled database volume?}
    H -- Yes --> I[Write legacy password postgres]
    H -- No --> J[Generate and write random password]
    E --> K[Run Compose]
    G --> K
    I --> K
    J --> K
Loading

Reviews (6) · Last reviewed commit: "docs(self-hosting): note that POSTGRES_*..."

Comment thread packages/sim-setup/src/compose-database.ts Outdated
Comment thread packages/sim-setup/src/compose-database.ts Outdated
Comment thread packages/sim-setup/src/compose-database.ts Outdated
…ctive role

A password exported only in the shell is now written to .env, so a later run without the export does not fall back to the legacy value. Rotation steps use the install's POSTGRES_USER and ALTER ROLE CURRENT_USER.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

Comment thread packages/sim-setup/src/compose-database.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 12 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread packages/sim-setup/src/compose-database.ts Outdated
Comment thread packages/sim-setup/src/lifecycle.ts
Comment thread packages/sim-setup/src/compose-database.ts Outdated
…WORD

An empty export, one that differs from .env, or one .env cannot hold verbatim now stops setup with instructions instead of silently picking a value the database may not have been created with.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 12 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread packages/sim-setup/src/compose-database.ts Outdated
Comment thread packages/sim-setup/src/compose-database.ts
Comment thread packages/sim-setup/src/compose-database.ts Outdated
… POSTGRES_USER export

DATABASE_URL embeds the password unescaped, so a shell-only password is persisted only when it is made of URL-unreserved characters. An empty POSTGRES_USER export resolves to the Compose default, matching ${POSTGRES_USER:-postgres}.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 12 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread packages/sim-setup/src/compose-database.ts Outdated
Comment thread packages/sim-setup/src/compose-database.ts Outdated
Compose interpolates a shell value over .env, so the wizard no longer copies it into .env and no longer needs rules for values .env or DATABASE_URL would change. An empty export is still refused, since Compose would use it and refuse to start.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

Comment thread packages/sim-setup/src/compose-database.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 12 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

docker-compose.prod.yml composes DATABASE_URL from them as written, so a value containing a URL delimiter initializes the database but breaks the connection string.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 12 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 6b46f69 into staging Sep 19, 2026
34 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/compose-postgres-defaults branch September 19, 2026 22:59

This branch was successfully deployed

1 active deployment
Preview 6b45b97a Deployed Sep 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant