Sharing local SSH key with pgadmin4 docker container; permission denied

Viewed 227

I have troubles finding a way to share my local SSH keys to the pgadmin4 docker container.

Here is how I proceed, by mounting my ~/.ssh folder into the container:

version: '3.8'

services:
  pgadmin4:
    image: dpage/pgadmin4:5.5
    environment:
      - PGADMIN_DEFAULT_EMAIL=email@domain.org
      - PGADMIN_DEFAULT_PASSWORD=********
      - PGADMIN_LISTEN_PORT=5050
    volumes:
      - pgadmin-data:/var/lib/pgadmin
      - ~/.ssh:/var/lib/pgadmin/storage/postgres_local.host/.ssh
    restart: unless-stopped

volumes:
  pgadmin-data: {}

Then, when setting up a connection, in the "SSH Tunnel" tab, I click the three little dots in front of the "Identify file" option:

enter image description here

But then, when browsing for an SSH key file, that bind folder has a small "lock" icon attached to it, and indeed, I got a "Permission denied" error when I try to open it:

enter image description here

Hence my question: what's the best and most convenient way to safely share some SSH identity files with that container?
Is it a good idea to do so?
Please note that they are obviously chmoded 600 on my local machine.

1 Answers

This issue is almost certainly related to permissions and I've managed to get my SSH tunnel to work by running the pgAdmin container as root.

This can be done by adding the user: root property to your service in Docker Compose file, e.g.:

services:
  pgadmin4:
    image: dpage/pgadmin4
    user: root
    # other properties here

Please note, running Docker containers as superuser comes with security risks so use this approach with caution.

This has been tested on an M1 Mac since the native pgAdmin 4 application is not yet available for this architecture.

Related