connection failed: fe_sendauth: no password supplied | can't access databases inside the master database using pgpassfile
I have deployed pgAdmin4 (version 7.1) as a Docker swarm service and have mounted servers.json (contents below) file. Along with that I have provided pgpassfile (contents below) as a secret. Service is deployed successfully and I can see all the databases inside the master database. When I try to view the database I am getting an error saying connection failed: fe_sendauth: no password supplied. I have also added a few entrypoint commands in order to copy pgpassfile into correct directory.
docker-compose.yml
version: "3.9"
services:
pgadmin:
image: dpage/pgadmin4:7.1
user: 5050:5050
environment:
- PGADMIN_DEFAULT_EMAIL
- PGADMIN_DEFAULT_PASSWORD
- PGADMIN_DISABLE_POSTFIX
- PGADMIN_LISTEN_PORT
- PGADMIN_SERVER_JSON_FILE
- PGADMIN_CONFIG_CONSOLE_LOG_LEVEL
volumes:
- /mnt/data/pgadmin:/var/lib/pgadmin
- ./pgadmin/servers.json:/pgadmin4/servers.json
ports:
- ${PGADMIN_LISTEN_PORT}:${PGADMIN_LISTEN_PORT}
networks:
- swarmnet
- infra
deploy:
mode: replicated
replicas: 1
restart_policy:
condition: on-failure
resources:
limits:
cpus: "0.3"
memory: 400M
reservations:
cpus: "0.2"
memory: 300M
secrets:
- pgpassfile
entrypoint: >
/bin/sh -c "
mkdir -m 700 -p /var/lib/pgadmin/storage/${PGADMIN_DEFAULT_EMAIL_STORAGE};
chown -R 5050:5050 /var/lib/pgadmin/storage/${PGADMIN_DEFAULT_EMAIL_STORAGE};
cp /var/run/secrets/pgpassfile /var/lib/pgadmin/storage/${PGADMIN_DEFAULT_EMAIL_STORAGE}/;
chmod 600 /var/lib/pgadmin/storage/${PGADMIN_DEFAULT_EMAIL_STORAGE}/pgpassfile;
/entrypoint.sh
"
...other services
networks:
...networks
secrets:
pgpassfile:
external: true
...other secrets
servers.json
{
"Servers": {
"1": {
"Name": "Postgres RDS",
"Group": "Servers",
"Port": 5432,
"Username": "master",
"Host": "<postgresql-endpoint>",
"SSLMode": "prefer",
"MaintenanceDB": "<master-db>",
"PassFile": "/pgpassfile"
}
}
}
pgpassfile
<postgresql-endpoint>:5432:master:<master-db>:<master-password>
When I add the master database manually from pgAdmin4 UI then I can successfully access all the databases inside the master database.
@ipajumets
We have added the connection parameter tab from v6.21 so the structure of the server.json file is also changed. Can you please try the following structure in your server.json
"Servers": {
"1": {
"Name": "PostgreSQL 12",
"Group": "Servers",
"Host": "localhost",
"Port": 5434,
"MaintenanceDB": "postgres",
"Username": "postgres",
"Comment": "Auto-detected PostgreSQL 12 installation with the data directory at /Library/PostgreSQL/12/data",
"ConnectionParameters": {
"sslmode": "prefer",
"connect_timeout": 10,
"passfile": "/Users/akshayjoshi/Desktop/pgpassfile"
}
}
}
@ipajumets We are not able to reproduce the issue. Can you please try with latest version & new form of servers.json? If issue is still reproducible, can you please check password_file past in server properties > parameters tab?
@akshay-joshi @yogeshmahajan-1903
Issue is still reproducible after updating the servers.json file by adding the ConnectionParameters.
Servers sidebar menu is showing all of the databases inside the master database.
But this is the error message when I try to interact with one of the databases inside the master database.
@ipajumets If you have only one entry for master database in pgpass file, then you will be able to connect only to db specified in pgpass file. If you want to connect different database, you might need to add another entry in papas file. Something like -
test.net:5432:testdb:testuser:testpass
test1.net:5432:testdb1:testuser1:testpass1
test2.net:5432:testdb2:testuser2:testpass2
I had the same issue. For me the following changes resolved the issue:
- Use
*for db name in password file.
db:5432:*:postgres:postgres
test-db:5432:*:postgres:postgres
- Mount the password file in
/tmpfolder. - Set file permission to 600
volumes:
- ./pgadmin-servers.json:/pgadmin4/servers.json
- ./pgadmin.pgpass:/tmp/pgpass
entrypoint: >
/bin/sh -c "
chmod 600 /tmp/pgpass;
/entrypoint.sh;
"
I had the same issue. For me the following changes resolved the issue:
- Use
*for db name in password file.db:5432:*:postgres:postgres test-db:5432:*:postgres:postgres
By adding * in the password file resolved the issue for me. Thanks a lot!
Closing per user confirmation.
Can we document this somewhere? I think pgadmin4 image will be more an more frequently used by developers in docker-compose setup where they need to provide servers.json and with that a PassFile.
I spent around 4 hours finding solution on this. And almost give it up completely.
Something like this worked for me:
pgadmin:
container_name: pgadmin_container
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: admin
PGADMIN_DEFAULT_PASSWORD: admin
ports:
- "${PGADMIN_PORT}:80"
volumes:
- ./servers.json:/pgadmin4/servers.json
- ./pgpass:/tmp/pgpass
networks:
- postgres
restart: unless-stopped
entrypoint: >
/bin/sh -c "
chmod 600 /tmp/pgpass;
mkdir -p /var/lib/pgadmin/storage/admin_admin.com;
cp /tmp/pgpass /var/lib/pgadmin/storage/admin_admin.com/.;
/entrypoint.sh;
"
servers.json:
{
"Servers": {
"1": {
"Name": "postgres-local-test",
"Group": "Servers",
"Host": "db", // replace with the actual host name
"Port": 5432,
"MaintenanceDB": "test", // replace with the actual DB name
"Username": "postgres", // repalce with the actual username
"PassFile": "/pgpass",
"SSLMode": "prefer"
}
}
}
pgpass (the password bit is set by postgres ofc, the postgres below is the username):
db:5432:*:postgres:password
Nope, this is still a problem. I get errors like
pgadmin_container | cp: can't stat '/pgadmin4/pgpass': No such file or directory
pgadmin_container | chmod: /var/lib/pgadmin/pgpass: No such file or directory
pgadmin_container | chown: unknown user/group pgadmin:pgadmin
when running docker-compose up.
How can I fix that?
The only thing that worked was adding user: - root to the pgadmin block in docker-compose
Nope, this is still a problem. I get errors like
pgadmin_container | cp: can't stat '/pgadmin4/pgpass': No such file or directory pgadmin_container | chmod: /var/lib/pgadmin/pgpass: No such file or directory pgadmin_container | chown: unknown user/group pgadmin:pgadminwhen running
docker-compose up.How can I fix that?
turns out it's not pgadmin:pgadmin. It's pgadmin:root
Funny, isn't it?
You can see compiled container here (STEP 16)
Maybe related: https://github.com/pgadmin-org/pgadmin4/issues/6741#issuecomment-1722212595
Came here for the same issue, running pgadmin in a docker compose environment as a service. The example of @Corwinpro was very helpful, thanks!
Please place these informations in a more prominent way (e.g. in a chapter specifically for the use within a docker environment). Crucial for me was:
- The passfile reference in the servers.json is not absolute, but relative to /var/lib/pgadmin/storage/
(why though?) - thus the passfile needs to be placed in the respective user folder (e.g. /var/lib/pgadmin/storage/pgadmin_pgadmin.com)
- Additionally chmod 600 must be executed on the pgpass file, otherwise it will be ignored
- the docker-compose service must be run with an additional entrypoint:
pgadmin:
image: dpage/pgadmin4:7.0
entrypoint: >
/bin/sh -c "
mkdir -p /var/lib/pgadmin/storage/pgadmin_pgadmin.com;
cp /tmp/pgpass /var/lib/pgadmin/storage/pgadmin_pgadmin.com/pgpass;
chmod 600 /var/lib/pgadmin/storage/pgadmin_pgadmin.com/pgpass;
/entrypoint.sh;
"
user: root
- the pgpass file itself must contain * instead of the servername
postgres:5432:*:user:password
@moto3101 I hope you didn't spend time figuring out this by yourself?
https://github.com/pgadmin-org/pgadmin4/issues/6741#issuecomment-1722212595 :)
Came here for the same issue, running pgadmin in a docker compose environment as a service. The example of @Corwinpro was very helpful, thanks!
Please place these informations in a more prominent way (e.g. in a chapter specifically for the use within a docker environment). Crucial for me was:
- The passfile reference in the servers.json is not absolute, but relative to /var/lib/pgadmin/storage/ (why though?) Because each user has his own storage directory and done in order to maintain security.
- thus the passfile needs to be placed in the respective user folder (e.g. /var/lib/pgadmin/storage/pgadmin_pgadmin.com) Yes. Another place could be shared storage.
- Additionally chmod 600 must be executed on the pgpass file, otherwise it will be ignored That is requirement by postgres.
- the docker-compose service must be run with an additional entrypoint:
pgadmin: image: dpage/pgadmin4:7.0 entrypoint: > /bin/sh -c " mkdir -p /var/lib/pgadmin/storage/pgadmin_pgadmin.com; cp /tmp/pgpass /var/lib/pgadmin/storage/pgadmin_pgadmin.com/pgpass; chmod 600 /var/lib/pgadmin/storage/pgadmin_pgadmin.com/pgpass; /entrypoint.sh; " user: root
the pgpass file itself must contain * instead of the servername
postgres:5432:*:user:password
Hi @moto3101, Alternatively, you can use a shared storage as well for passfile - https://www.pgadmin.org/docs/pgadmin4/development/storage_manager.html#shared-storage. This will be accessible to all the users.
@moto3101 I hope you didn't spend time figuring out this by yourself?
ah, no of course I spent time figuring it out by myself :) Thanks for the hint though, your comment should go to the documentation somewhere :)
I have the same issue
Definition of init_pgadmin.sh
#!/bin/sh
rm -rf /tmp/pgpass/ && mkdir /tmp/pgpass/
cat <<EOF > /tmp/pgpass/.pgpass
hostname1:5432:*:user1:password1
hostname2:5432:*:user2:password2
EOF
echo ".pgpass created with correct permissions."
# Continue to start pgAdmin
exec /entrypoint.sh
Servers.json file
{
"Servers": {
"1": {
"Name": "PSS",
"Group": "PSSGroup",
"Port": 5432,
"Username": "user1",
"ConnectionParameters": {
"passfile": "/var/lib/pgadmin/storage/diq_test.de/.pgpass",
"sslmode": "prefer",
"connect_timeout": 10
},
"Host": "hostname1",
"MaintenanceDB": "postgres",
"PostConnectionSQL": "set timezone='America/New_York'"
},
"2": {
"Name": "Servers",
"Group": "GrafanaGroup",
"Host": "hostname2",
"Port": 5432,
"MaintenanceDB": "postgres",
"Username": "user2",
"ConnectionParameters": {
"passfile": "/var/lib/pgadmin/storage/diq_test.de/.pgpass",
"sslmode": "prefer",
"connect_timeout": 10
},
"sslmode": "prefer",
"connect_timeout": 10,
"PostConnectionSQL": "set timezone='America/New_York'"
}
}
}
PS: /var/lib/pgadmin/storage/diq_test.de/.pgpass is generated with the correct content of .pgpass because of PGPASS_FILE is set I figured this out while reading the entrypoint.sh file. This means the passfile path is correct and the permissions as well
The definition in docker-compose file
pg_admin:
hostname: pg_admin
image: dpage/pgadmin4:9.4.0
entrypoint: ["/bin/sh", "/pgadmin4/init_pgadmin.sh"]
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: ${DIQDB_USER}@test.de
PGADMIN_DEFAULT_PASSWORD: ${DIQDB_PASSWORD}
PGADMIN_LISTEN_ADDRESS: 0.0.0.0
PGPASS_FILE: "/tmp/pgpass/.pgpass"
PGADMIN_CONFIG_CONSOLE_LOG_LEVEL: 10
ports:
- "8080:80"
deploy:
resources:
limits:
cpus: "4.0"
memory: 8G
volumes:
- ./servers.json:/pgadmin4/servers.json
- ./init_pgadmin.sh:/pgadmin4/init_pgadmin.sh
But I get this error
For whaterver reason the password is not loaded from the .pgpass file
Update After many research, I found the solution here from user503582 https://stackoverflow.com/questions/66578506/where-is-the-pgpass-file-in-pgadmin4-docker-container-when-this-file-is-mounted
"passfile": "/.pgpass",
the path is not absolute '/' apparently point the the storage directory already 👎
the path is not absolute '/' apparently point the the storage directory already 👎
Noticed it in my other comment as well: https://github.com/pgadmin-org/pgadmin4/issues/6741#issuecomment-1722212595
Value of recently added "passfile" in "ConnectionParameters" is not an absolute path (even if it starts with root-like slash). It's relative. And in reality /.pgpass is actually /var/lib/pgadmin/storage/{normalized form of PGADMIN_DEFAULT_EMAIL with '@' replaced to '_'}/.pgpass. In my case because I set PGADMIN_DEFAULT_EMAIL="[email protected]", my path inside docker container dpage/pgadmin4 was /var/lib/pgadmin/storage/admin_hello.com/.pgpass
I noticed you have also been there under the issue where I left my comment. It's sad that GitHub collapses old conversations, so that is likely why you haven't seen it.