Skip to content

fix: use trust auth for docker-postgres - #1346

Merged
shunkakinoki merged 1 commit into
mainfrom
fix/postgres-trust-auth
Apr 4, 2026
Merged

fix: use trust auth for docker-postgres#1346
shunkakinoki merged 1 commit into
mainfrom
fix/postgres-trust-auth

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Apr 4, 2026

Copy link
Copy Markdown
Owner

Summary

Add POSTGRES_HOST_AUTH_METHOD=trust to the docker-postgres container.

Problem

POSTGRES_PASSWORD only sets the password on first container init. After crash recovery, the password in the auth system gets out of sync, causing password authentication failed errors that crash-loop paperclip and any other service using the postgres connection.

Fix

Trust all connections — no password needed. Safe since this postgres is only reachable from localhost/docker bridge, not exposed externally.

Note

Existing container needs to be recreated for this to take effect:

docker stop postgres && docker rm postgres
make systemctl-docker-postgres

Summary by cubic

Switch docker-postgres to trust auth by setting POSTGRES_HOST_AUTH_METHOD=trust. This prevents password mismatches after crash recovery that caused "password authentication failed" and crash loops in dependent services.

  • Migration
    • Recreate the container to apply the env var: run docker stop postgres && docker rm postgres, then make systemctl-docker-postgres.

Written for commit 68d1293. Summary will update on new commits.

POSTGRES_HOST_AUTH_METHOD=trust removes password auth for all
connections. The password kept going out of sync after crash recovery,
causing paperclip and other services to fail with 'password
authentication failed'. Safe since postgres is only reachable from
the host.
Copilot AI review requested due to automatic review settings April 4, 2026 10:44
@mesa-dot-dev

mesa-dot-dev Bot commented Apr 4, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@coderabbitai

coderabbitai Bot commented Apr 4, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Updated PostgreSQL Docker container configuration with additional authentication settings.

Walkthrough

A single environment variable POSTGRES_HOST_AUTH_METHOD=trust is added to the Docker container initialization command in the PostgreSQL startup script, enabling trust-based authentication for local PostgreSQL connections without password verification.

Changes

Cohort / File(s) Summary
PostgreSQL Docker Configuration
home-manager/services/docker-postgres/start-postgres.sh
Added POSTGRES_HOST_AUTH_METHOD=trust environment variable to the docker run invocation alongside existing database and password configuration variables.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

bug

Poem

🐰 A postgres container takes flight,
With trust authentication set just right,
No passwords needed, connections flow free,
The rabbit hops on, happy as can be! 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: setting trust authentication for the docker-postgres service.
Description check ✅ Passed The pull request description is comprehensive and directly related to the changeset, explaining the problem, solution, and migration steps required.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/postgres-trust-auth

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.

@mesa-dot-dev

mesa-dot-dev Bot commented Apr 4, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Add POSTGRES_HOST_AUTH_METHOD=trust to the docker-postgres container.

What changed?

  • Added POSTGRES_HOST_AUTH_METHOD=trust to the docker-postgres container configuration to prevent password authentication failed errors after crash recovery. This effectively disables password authentication for connections, which is safe as the PostgreSQL instance is only accessible from localhost/docker bridge.

Description generated by Mesa. Update settings

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the PostgreSQL Docker startup script to enable the 'trust' authentication method, allowing passwordless access. A security review identified that this change, combined with the current port mapping, could expose the database to the network; it is recommended to restrict the port binding to '127.0.0.1' to ensure the database remains accessible only from the local host.

-p "${HOST_PORT}:${CONTAINER_PORT}" \
-e POSTGRES_DB=trails_api \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_HOST_AUTH_METHOD=trust \

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.

security-high high

Using trust authentication allows passwordless access to the database. While the PR description suggests this is safe, the port mapping -p "${HOST_PORT}:${CONTAINER_PORT}" on line 47 binds to 0.0.0.0 by default, exposing the database to the network. To ensure it is only reachable from localhost as intended, the port mapping should be restricted to 127.0.0.1. Additionally, consider updating the tests in spec/docker_postgres_spec.sh to reflect this change.

@shunkakinoki
shunkakinoki merged commit 31ca229 into main Apr 4, 2026
33 of 34 checks passed
@shunkakinoki
shunkakinoki deleted the fix/postgres-trust-auth branch April 4, 2026 10:46

Copilot AI 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.

Pull request overview

This PR updates the Home Manager–managed docker-postgres startup script to avoid password auth issues after container lifecycle events by configuring PostgreSQL to trust host connections.

Changes:

  • Add POSTGRES_HOST_AUTH_METHOD=trust to the docker run environment for the postgres container.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -47,6 +47,7 @@ ensure_container() {
-p "${HOST_PORT}:${CONTAINER_PORT}" \

Copilot AI Apr 4, 2026

Copy link

Choose a reason for hiding this comment

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

POSTGRES_HOST_AUTH_METHOD=trust disables password checks for all TCP host connections. With the current -p "${HOST_PORT}:${CONTAINER_PORT}" publish syntax, Docker binds to 0.0.0.0 by default, so Postgres can become reachable from other machines on the network (depending on host firewall). To match the PR description (“only reachable from localhost/docker bridge”) and avoid unauthenticated remote access, bind the published port to loopback (e.g., 127.0.0.1) and/or avoid publishing the port entirely if only other containers need it.

Suggested change
-p "${HOST_PORT}:${CONTAINER_PORT}" \
-p "127.0.0.1:${HOST_PORT}:${CONTAINER_PORT}" \

Copilot uses AI. Check for mistakes.
Comment on lines 49 to +50
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_HOST_AUTH_METHOD=trust \

Copilot AI Apr 4, 2026

Copy link

Choose a reason for hiding this comment

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

This change introduces a new runtime behavior (trust auth) but the existing ShellSpec coverage for this script doesn’t assert it. Consider updating the docker-postgres spec to check for POSTGRES_HOST_AUTH_METHOD=trust (and ideally the chosen port bind strategy) so the security-sensitive configuration can’t regress silently.

Copilot uses AI. Check for mistakes.

@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.

2 issues found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="home-manager/services/docker-postgres/start-postgres.sh">

<violation number="1" location="home-manager/services/docker-postgres/start-postgres.sh:50">
P1: `POSTGRES_HOST_AUTH_METHOD=trust` removes authentication for host connections; with the published `5432` port this creates an unauthenticated database access path.</violation>

<violation number="2" location="home-manager/services/docker-postgres/start-postgres.sh:50">
P1: Setting `POSTGRES_HOST_AUTH_METHOD=trust` removes all authentication, but the port mapping on line 47 (`-p "${HOST_PORT}:${CONTAINER_PORT}"`) binds to `0.0.0.0` by default, exposing the database to the entire network without credentials. Restrict the bind address to localhost: `-p "127.0.0.1:${HOST_PORT}:${CONTAINER_PORT}"`</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

-p "${HOST_PORT}:${CONTAINER_PORT}" \
-e POSTGRES_DB=trails_api \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_HOST_AUTH_METHOD=trust \

@cubic-dev-ai cubic-dev-ai Bot Apr 4, 2026

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.

P1: POSTGRES_HOST_AUTH_METHOD=trust removes authentication for host connections; with the published 5432 port this creates an unauthenticated database access path.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/services/docker-postgres/start-postgres.sh, line 50:

<comment>`POSTGRES_HOST_AUTH_METHOD=trust` removes authentication for host connections; with the published `5432` port this creates an unauthenticated database access path.</comment>

<file context>
@@ -47,6 +47,7 @@ ensure_container() {
       -p "${HOST_PORT}:${CONTAINER_PORT}" \
       -e POSTGRES_DB=trails_api \
       -e POSTGRES_PASSWORD=postgres \
+      -e POSTGRES_HOST_AUTH_METHOD=trust \
       "$IMAGE"
     log "Container '$CONTAINER_NAME' created and started"
</file context>
Suggested change
-e POSTGRES_HOST_AUTH_METHOD=trust \
-e POSTGRES_HOST_AUTH_METHOD=scram-sha-256 \
Fix with Cubic

-p "${HOST_PORT}:${CONTAINER_PORT}" \
-e POSTGRES_DB=trails_api \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_HOST_AUTH_METHOD=trust \

@cubic-dev-ai cubic-dev-ai Bot Apr 4, 2026

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.

P1: Setting POSTGRES_HOST_AUTH_METHOD=trust removes all authentication, but the port mapping on line 47 (-p "${HOST_PORT}:${CONTAINER_PORT}") binds to 0.0.0.0 by default, exposing the database to the entire network without credentials. Restrict the bind address to localhost: -p "127.0.0.1:${HOST_PORT}:${CONTAINER_PORT}"

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/services/docker-postgres/start-postgres.sh, line 50:

<comment>Setting `POSTGRES_HOST_AUTH_METHOD=trust` removes all authentication, but the port mapping on line 47 (`-p "${HOST_PORT}:${CONTAINER_PORT}"`) binds to `0.0.0.0` by default, exposing the database to the entire network without credentials. Restrict the bind address to localhost: `-p "127.0.0.1:${HOST_PORT}:${CONTAINER_PORT}"`</comment>

<file context>
@@ -47,6 +47,7 @@ ensure_container() {
       -p "${HOST_PORT}:${CONTAINER_PORT}" \
       -e POSTGRES_DB=trails_api \
       -e POSTGRES_PASSWORD=postgres \
+      -e POSTGRES_HOST_AUTH_METHOD=trust \
       "$IMAGE"
     log "Container '$CONTAINER_NAME' created and started"
</file context>
Fix with Cubic

shunkakinoki added a commit that referenced this pull request Apr 5, 2026
* feat: add paperclip service (#1342)

* feat: add paperclip service

- Systemd service on kyber: runs `paperclipai run` via bun, depends on docker-postgres
- Config via builtins.toJSON: external postgres on kyber, embedded on macOS
- Setup script creates paperclip database on docker-postgres
- Makefile target: `make systemctl-paperclip`

* fix: add shellcheck disable and shell test coverage for paperclip

* fix: correct shellcheck disable directive syntax

* refactor: use config.template.json pattern for paperclip

* refactor: rename setup.sh to hydrate.sh for paperclip

* test: add auto-switch hook tests and update coverage spec

* fix: remove EnvironmentFile from paperclip service (#1344)

* fix: paperclip authenticated mode and required config fields (#1345)

* fix: remove EnvironmentFile from paperclip service

* fix: use authenticated mode on kyber, add required meta/logging fields

* fix: add allowedHostnames for paperclip.shunkakinoki.com

* fix: format config template json

* fix: use trust auth for docker-postgres (#1346)

POSTGRES_HOST_AUTH_METHOD=trust removes password auth for all
connections. The password kept going out of sync after crash recovery,
causing paperclip and other services to fail with 'password
authentication failed'. Safe since postgres is only reachable from
the host.

* fix: use k8s postgres via DATABASE_URL, remove docker-postgres dep, add authenticated mode (#1347)

* fix: use bun runtime for paperclip (pino-http node crash), k8s postgres via DATABASE_URL (#1348)

* fix: use nix-profile bun path for paperclip service (#1350)

* fix: add caret prefix to paperclipai dependency (#1349)

* fix: use extra-substituters to avoid untrusted user warnings (#1351)

* fix: run paperclip from cloned repo via pnpm dev:once (#1352)

* fix: run paperclip from cloned repo via pnpm dev:once

The global bun install flattens pino@10 + pino-http@10.5 together,
but pino-http needs pino@9. The repo lockfile resolves this correctly
with nested dependencies. Running from the repo avoids the crash.

* fix: use bun run server/src/index.ts instead of pnpm dev:once

* fix: pin pino@9.14.0 override, run paperclipai from dotfiles node_modules

The bun flat hoisting was resolving pino@10 which is incompatible
with pino-http@10.5. Pinning pino to 9.14.0 via overrides matches
the paperclip repo's lockfile resolution and fixes the crash.

* fix: use global bun paperclipai with pino override (#1353)

* fix: use global ~/.bun/bin/paperclipai with pino override

Propagate overrides from dotfiles package.json to ~/.bun/install/global/
so the global binary resolves pino@9.14.0 correctly.

* test: add tests for npm-globals dependency overrides

* fix: resolve GitHub Actions failures and code review issues

- Fix non-portable \s regex to [[:space:]] in auto-switch.sh (shfmt compat)
- Add jq dependency check alongside cswap
- Use printf instead of echo for safer output
- Fix claude-swap version from >=1.1.5 (non-existent) to >=0.7.1
- Add auto-switch.sh to Nix deployment config (default.nix)
- Sort covered_scripts list alphabetically in coverage_spec.sh

https://claude.ai/code/session_012GyQBesQGF1asTfKebWyLM

---------

Co-authored-by: Claude <noreply@anthropic.com>
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.

2 participants