n8n-io / n8n

Free and source-available fair-code licensed workflow automation tool. Easily automate tasks across different services.
https://n8n.io
Other
48.37k stars 7.52k forks source link

n8n deployed on docker seems to add extra new line to username and password when using secrets #10818

Open bartoszrapp opened 1 month ago

bartoszrapp commented 1 month ago

Bug Description

When you try to deploy n8n with Postgres and you want to use secrets to safely pass the DB credentials is seems the \n is added at the end of content read from /run/secrets/.... resulting in authorization error. With user and password passed explicite using env variable everything works as expected.

n8n_postgres | 2024-09-14 16:52:27.159 UTC [68] FATAL: password authentication failed for user "n8n_db_user n8n_postgres | " n8n_postgres | 2024-09-14 16:52:27.159 UTC [68] DETAIL: Role "n8n_db_user n8n_postgres | " does not exist. n8n_postgres | Connection matched file "/var/lib/postgresql/data/pg_hba.conf" line 128: "host all all all scram-sha-256" n8n_app | Error: There was an error initializing DB n8n_app | DatabaseError: password authentication failed for user "n8n_db_user n8n_app | "

To Reproduce

services: n8n: image: docker.n8n.io/n8nio/n8n container_name: n8n_app restart: always ports:

volumes: n8n_data: name: n8n_data n8n_postgres_data: name: n8n_postgres_data

networks: proxy_bus_network: name: proxy_bus_network external: true internal_n8n: name: internal_n8n

secrets: db_username: file: ./db_username.txt name: n8n_pg_username db_password: file: ./db_password.txt name: n8n_pg_password

Expected behavior

Using DB_POSTGRESDB_USER_FILE and DB_POSTGRESDB_PASSWORD_FILE should work the same as using DB_POSTGRESDB_USER and DB_POSTGRESDB_PASSWORD

Operating System

Ubuntu Linux 24.04 LTS

n8n Version

1.58.2

Node.js Version

20.15.0

Database

PostgreSQL

Execution mode

main (default)

Joffcom commented 1 month ago

Hey @bartoszrapp,

We have created an internal ticket to look into this which we will be tracking as "GHC-232"

bartoszrapp commented 1 month ago

As an additional information. It is for sure a problem on n8n side. Postgres set with secrets and _FILE and n8n set with regular password env variable works perfectly fine. Only when I use xxx_FILE on n8n the error manifestates.

Joffcom commented 1 month ago

Hey @bartoszrapp

Just to confirm your secret file doesn't have a new line character at the end of it right? I will test this on Monday but I have seen some text editors automatically add a return when saving so want to quickly rule that out.

bartoszrapp commented 1 month ago

No there is no new line. I have checked it few times. I have even added a new line once to check the result in the logs. It was than with extra new line. Looked like this: n8n_postgres | 2024-09-14 16:52:27.159 UTC [68] DETAIL: Role "n8n_db_user n8n_postgres | n8n_postgres | " does not exist.

Also the same file is used and shared by the postgres container. It works well. When I run the postgres with secrets from files and n8n with normal explicit password and user in docker-compose file it works.

Joffcom commented 1 month ago

Hey @bartoszrapp,

Perfect, I have taken a look and managed to reproduce the issue.

bartoszrapp commented 1 month ago

Hey @Joffcom,

Thank you for the update. I hope this will be an easy fix and nothing serious that would require a lot of work :)