postgres: Recent versions seems to have broken auth when POSTGRES_PASSWORD is set
I’ve tried 9.6 and 9.5 and alpine variants too.
Getting rid of the POSTGRES_PASSWORD fixes it so I’m generally ok, but this could trip other people up too… looks like it might be the issue at: https://github.com/MagicStack/asyncpg/issues/158
compose:
postgres_sx:
image: postgres
environment:
- POSTGRES_PASSWORD=postgres
postgres_sx_1 | FATAL: password authentication failed for user "postgres"
postgres_sx_1 | DETAIL: Connection matched pg_hba.conf line 95: "host all all all md5"
postgres_sx_1 | FATAL: password authentication failed for user "postgres"
postgres_sx_1 | DETAIL: Connection matched pg_hba.conf line 95: "host all all all md5"
postgres_sx_1 | FATAL: password authentication failed for user "postgres"
postgres_sx_1 | DETAIL: Connection matched pg_hba.conf line 95: "host all all all md5"
services_sx_1 | { error: password authentication failed for user "postgres"
services_sx_1 | at Connection.parseE (/app/services/sx/node_modules/pg-promise/node_modules/pg/lib/connection.js:539:11)
services_sx_1 | at Connection.parseMessage (/app/services/sx/node_modules/pg-promise/node_modules/pg/lib/connection.js:366:17)
services_sx_1 | at Socket.<anonymous> (/app/services/sx/node_modules/pg-promise/node_modules/pg/lib/connection.js:105:22)
services_sx_1 | at emitOne (events.js:115:13)
services_sx_1 | at Socket.emit (events.js:210:7)
services_sx_1 | at addChunk (_stream_readable.js:250:12)
services_sx_1 | at readableAddChunk (_stream_readable.js:237:11)
services_sx_1 | at Socket.Readable.push (_stream_readable.js:195:10)
services_sx_1 | at TCP.onread (net.js:586:20)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 18 (3 by maintainers)
Hi @lelit I tried to follow this discussion here but not sure how I can fix this.
I still immediately get this error when I set “POSTGRES_PASSWORD” using v10.1. What is the current state on this? How to fix this?
I was facing the same issue when deploying the PostgreSQL image on Kubernetes. The problem was really subtle, but was caused by a trailing newline character on my password environment variable. That’s why when creating base64 secrets using the command line, one should always use
echo -n
:What makes this hard to spot, is that there’s no visible difference when inspecting the container’s environment variables. Here’s an example using the password
hunter2
with a trailing\n
:And without it:
The fact that the PostgreSQL server in this image allows local connections without a password makes the debug of this issue even more confusing:
That’s why testing the connection using
psql
without-h
isn’t enough.It works fine without POSTGRES_PASSWORD set in docker compose env. For some reason that’s when it breaks. I’ll try repro with regular docker.
On Sat, 8 Jul. 2017, 6:47 am yosifkit, notifications@github.com wrote: