server icon indicating copy to clipboard operation
server copied to clipboard

Nginx container permission problem with custom UID/GID

Open Ndr6 opened this issue 8 years ago • 4 comments

I run Bitwarden with a custom user (set in bwdata/env/uid.env). The nginx container creates the "/var/run/nginx.pid" file with the correct owner (as in uid.env), but the "/var/run" folder belongs to root so when the nginx process tries to delete the nginx.pid file the permission is denied and nginx stops.

A way to fix this would be to add to entrypoint.sh :

...
touch /var/run/nginx.pid
chown -R $USERNAME:$GROUPNAME /var/run/nginx.pid
chown root:$GROUPNAME /var/run
chmod 775 /var/run
...

This allows to keep the root ownership, while allowing nginx to delete the file

Ndr6 avatar Aug 30 '18 11:08 Ndr6

I would assume that if /var/run/nginx.pid has the correct permissions it should still be able to be deleted even if the directory containing it does not. Am I mistaken?

kspearrin avatar Aug 30 '18 12:08 kspearrin

As seen in here, you need to be able to delete the file from the directory files list

Ndr6 avatar Aug 30 '18 13:08 Ndr6

Thanks. I am not sure allowing our application group write access to /var/run is a good idea though...? https://serverfault.com/a/159349/405627

kspearrin avatar Aug 30 '18 18:08 kspearrin

You're right. I made a pull request moving nginx.pid to /var/run/nginx owned by the application user

Ndr6 avatar Aug 31 '18 08:08 Ndr6