Skip to content

Database least privilege: split migration and runtime roles #101

Open

Description

@JuansesDev

Problem

SendDock connects to Postgres as a single role that owns the schema, runs migrations (DDL) and serves runtime traffic (DML). In the bundled Compose stack that role is also the POSTGRES_USER, which the official image makes a superuser of the instance. The database is not published to the host, so the blast radius is contained to the container — but:

  • Self-hosters connecting to an external or shared Postgres have no guidance for creating a least-privilege role, so they reuse a powerful one.
  • The runtime process holds DDL rights it never needs after boot.
  • docker-compose.prod.yml falls back to a well-known default password (senddock) when POSTGRES_PASSWORD is unset.

Proposal

  • Support two connection strings: DATABASE_URL for runtime (DML only) and an optional MIGRATIONS_DATABASE_URL used by the entrypoint for goose. When the second is unset, behave as today — no breaking change.
  • Document the recommended role setup for external Postgres: a senddock_migrate owner role and a senddock_app role with SELECT/INSERT/UPDATE/DELETE on the schema and USAGE on sequences, with the exact CREATE ROLE / GRANT statements, and default privileges so future migrations extend grants automatically.
  • Make the bundled Compose the secure default: create the app role with limited grants in an init script and let the migration step use the owner role.
  • Require POSTGRES_PASSWORD in docker-compose.prod.yml the way docker-compose.image.yml already does, instead of falling back to a known default.

Acceptance

  • MIGRATIONS_DATABASE_URL honored by the entrypoint, falling back to DATABASE_URL
  • Bundled Compose creates separate migrate/app roles by default
  • prod.yml fails fast without an explicit POSTGRES_PASSWORD
  • Docs: "Database roles" section under self-hosting configuration with copy-paste SQL for external Postgres
  • Upgrade note in the changelog confirming existing single-role setups keep working

Activity

  1. added this to the 0.9 milestone on Aug 21, 2026
  2. added
    documentation
    on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationinfrasecurity

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions