I'm running initdb in docker image (official Postgres image) in Openshift environment, with sets the strict security policy, that user that will run the container will have random UID, but GID will be 0, so I can assert that the process have all necessary rights.
I've tested my container with postgres user with GID changed to 0, and everything has worked fine. The final test with ANYUID policy has caused the image to fail:
initdb: could not change permissions of directory
which is clear: the user have full write rights to the directory, but is neither owner nor root. However, I don't see WHY initdb needs to change ownership of the directory, write rights should be enough.
The initdb
must be called after starting container because pgdata might be located on the volume, and anyuid policy asserts general cluster security, so I don't want to disable it. I know that it is generally possible to run Postgres docker images with that policy, because RedHat provides modified images for that, but they can be used only in OpenShift Enterprise.
How to allow initdb
process to run as any user with necessary write rights, but being neither owner nor root? Does it need to recompile the sources with special flags? I've found out that RedHat is using custom packaged version of Postgres, but I haven't found out if they modified the sources...