zalando / spilo

Highly available elephant herd: HA PostgreSQL cluster using Docker
Apache License 2.0
1.56k stars 387 forks source link

Change user ID for spilo docker image #827

Closed DrissiReda closed 1 year ago

DrissiReda commented 1 year ago

Is it possible to change user ID for the spilo image dynamically?

I tried:

docker run -ti -u 1000:1000 registry.opensource.zalan.do/acid/spilo-14

But it doesn't work.

I tried modifying the Dockerfile to change postgres user ID manually, and that works. But it doesn't give me the ability to change postgres user ID at run time.

I added this line:

RUN groupadd -g 10006 postgres && useradd -u 10006 -g postgres postgres

Here: https://github.com/zalando/spilo/blob/master/postgres-appliance/Dockerfile#L35

Is there any way to achieve that?

This is the error I'm getting:

mkdir: cannot create directory ‘/home/postgres/pgdata’: Permission denied
mkdir: cannot create directory ‘/home/postgres/pgdata’: Permission denied
mkdir: cannot create directory ‘/run/tmp’: Permission denied
mkdir: cannot create directory ‘/run/certs’: Permission denied
/launch.sh: 23: /launch.sh: cannot create /run/tmp/passwd: Directory nonexistent
/launch.sh: 24: /launch.sh: cannot create /etc/passwd: Permission denied
rm: cannot remove '/run/tmp/passwd': No such file or directory
touch: cannot touch '/home/postgres/pgdata/pgroot/pg_log/postgresql-0.csv': No such file or directory
touch: cannot touch '/home/postgres/pgdata/pgroot/pg_log/postgresql-1.csv': No such file or directory
touch: cannot touch '/home/postgres/pgdata/pgroot/pg_log/postgresql-2.csv': No such file or directory
touch: cannot touch '/home/postgres/pgdata/pgroot/pg_log/postgresql-3.csv': No such file or directory
touch: cannot touch '/home/postgres/pgdata/pgroot/pg_log/postgresql-4.csv': No such file or directory
touch: cannot touch '/home/postgres/pgdata/pgroot/pg_log/postgresql-5.csv': No such file or directory
touch: cannot touch '/home/postgres/pgdata/pgroot/pg_log/postgresql-6.csv': No such file or directory
touch: cannot touch '/home/postgres/pgdata/pgroot/pg_log/postgresql-7.csv': No such file or directory
chown: cannot access '/home/postgres/pgdata/pgroot': No such file or directory
chown: cannot access '/run/certs': No such file or directory
chmod: cannot access '/home/postgres/pgdata/pgroot': No such file or directory
chmod: cannot access '/run/tmp': No such file or directory
chmod: cannot access '/home/postgres/pgdata/pgroot/data': No such file or directory
2023-01-17 15:50:06,307 - bootstrapping - INFO - Figuring out my environment (Google? AWS? Openstack? Local?)
2023-01-17 15:50:08,310 - bootstrapping - INFO - Could not connect to 169.254.169.254, assuming local Docker setup
2023-01-17 15:50:08,311 - bootstrapping - INFO - No meta-data available for this provider
2023-01-17 15:50:08,311 - bootstrapping - INFO - Looks like your running local
Traceback (most recent call last):
  File "/scripts/configure_spilo.py", line 1129, in <module>
    main()
  File "/scripts/configure_spilo.py", line 1042, in main
    link_runit_service(placeholders, 'etcd')
  File "/scripts/configure_spilo.py", line 76, in link_runit_service
    os.makedirs(rw_service)
  File "/usr/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/run/service'
hughcapet commented 1 year ago

While not really getting what you are doing and why, UID is changed using usermod -u command, GUID - groupmod -g

docker run -u doesn't create or change anything. It just runs a container with the given command as a given user

With all that being said, you better not change postgres uid, as it breaks all the configured permissions/ownerships (unless you want to change them all manually).