Skip to content

Auth method failed #913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
felipe-heredia opened this issue Dec 3, 2021 · 5 comments
Closed

Auth method failed #913

felipe-heredia opened this issue Dec 3, 2021 · 5 comments
Labels
question Usability question, not directly related to an error with the image

Comments

@felipe-heredia
Copy link

felipe-heredia commented Dec 3, 2021

I'm try to deploy my app with postgres, but I gotten this error:

postgres_1  | 2021-12-03 23:24:15.438 UTC [33] FATAL:  password authentication failed for user "postgres"
postgres_1  | 2021-12-03 23:24:15.438 UTC [33] DETAIL:  Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"

I've see #911 and see postgres:14 have an auth bug, I think.

My docker-compose

  postgres:
    image: postgres:latest
    env_file:
      - .env
    container_name: jano_postgres
    ports:
      - ${DB_PORT}:${DB_PORT}
    restart: always
    volumes:
      - postgres:/var/lib/postgresql/data

Error from my prisma (using to connect to db)

PrismaClientInitializationError: Authentication failed against database server at `jano_postgres`, the provided database credentials for `postgres` are not valid.

My .env

# POSTGRES
POSTGRES_USER="postgres"
POSTGRES_PASSWORD="admin"
POSTGRES_DB="holdbtc100"

# Nest run locally
#DB_HOST=localhost
# Nest run in docker, change host to database container name
DB_HOST="jano_postgres"
DB_PORT="5432"

# Prisma database connection
DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:${DB_PORT}/${POSTGRES_DB}"
SECRET_KEY="secretKeyToDev"

I don't know the why, but this .env work on my local machine (created 2 months ago), but in the EC2 machine no.

I need this for yesterday, if you know how I can solve (if postgres:13 or another mode) tell me, please

@yosifkit
Copy link
Member

yosifkit commented Dec 4, 2021

I'm uncertain, but would guess that prisma client doesn't yet support scram-sha-256 authentication or needs to be told to use it?

Options:

  • use postgres:13
  • use a combination of POSTGRES_INITDB_ARGS=--auth-host=, -c password_encryption=, or POSTGRES_HOST_AUTH_METHOD to adjust the password authentication of postgres:14 (see this comment).

@felipe-heredia
Copy link
Author

On use postgres:13 o gotten this:

PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_1  |
postgres_1  | 2021-12-04 11:34:53.228 UTC [1] FATAL:  database files are incompatible with server
postgres_1  | 2021-12-04 11:34:53.228 UTC [1] DETAIL:  The data directory was initialized by PostgreSQL version 14, which is not compatible with this version 13.5 (Debian 13.5-1.pgdg110+1).

How I can adjust the password authentication on docker-compose file? Using build args? I really don't know.

@felipe-heredia
Copy link
Author

I solved this problem, removing my app from a docker image and running docker run not docker-compose.

This solved my problem, but if you know a way to adjust the password auth using docker-compose I accept this too.

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Dec 6, 2021
@tianon
Copy link
Member

tianon commented Dec 6, 2021

You should be able to set those same environment variables in a docker-compose.yml -- the biggest difference with docker-compose is that it's going to try very hard to avoid removing your data volume (and to reattach the old volume proactively), and if you want to change these values via environment variables, you have to explicitly delete and reinitialize your database. See also #203 (comment).

(For further help, I would suggest trying a dedicated support forum, such as the Docker Community Forums, the Docker Community Slack, or Stack Overflow.)

@tianon tianon closed this as completed Dec 6, 2021
@fhodun
Copy link

fhodun commented Dec 19, 2021

I've found solution to solve this error that appears with latest postgresql in docker compose.
You need to add this environment variable entry POSTGRES_INITDB_ARGS=--auth-host=scram-sha-256 in your postgres docker-compose.yml config.

Just like this:

  postgres:
    image: "postgres:latest"
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=someuser
      - POSTGRES_PASSWORD=changeme
      - POSTGRES_DB=database
      - POSTGRES_INITDB_ARGS=--auth-host=scram-sha-256
    volumes:
      - postgres-data:/var/lib/postgresql

It's explained on docker postgresql website: hub.docker.com/_/postgres (Environment Variables
> POSTGRES_HOST_AUTH_METHOD > Note 3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

5 participants