Skip to content

Feature/container uid#155

Merged
mblaschke merged 9 commits intodevelopfrom
feature/container-uid
Jan 20, 2017
Merged

Feature/container uid#155
mblaschke merged 9 commits intodevelopfrom
feature/container-uid

Conversation

@mblaschke
Copy link
Member

  • Add support for eg. docker run --user 999 webdevops/php-apache:ubuntu-16.04

@mblaschke mblaschke self-assigned this Dec 31, 2016
@htuscher
Copy link
Member

htuscher commented Jan 3, 2017

I'm not quite sure if that's within the concept of docker, because I don't know of any other image having that functionality. Usually you have a fixed user running everything inside the container e.g. nginx, elasticsearch, postgres, etc.
But implementation looks good though.

@mblaschke
Copy link
Member Author

The master process of FPM needs AFAIK root rights for eg. slowlog so it should be started as root.
Also most of the configuration files are not changeable for other users for security reasons: An attacker (via FPM) can modify configuration files or other files.

So i'm detecting that docker container is not running as root, privilege escalation via gosu and remove the suid bit after privilege escalation. So the main entrypoint is still running via root but the application can be run as normal user.
If we don't use privilege escalation then all processes must be able to run under this user which will be more difficult.

With this fix we can run FPM under any user and new files are also created under this UID and is not fixed to UID 1000 anymore.

@mblaschke
Copy link
Member Author

eg. FPM configuration and all other configuration which are modified after ENTRYPOINT startup (eg. by env vars) must be world writeable if we don't do privilege escalation. I'm really not happy with world writeable configuration files.

&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& gosu nobody true \
&& apt-get purge -y -f --force-yes wget \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding wget in next section (below)

&& /usr/local/bin/apt-install wget gnupg \
&& dpkgArch="amd64" \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture | awk -F- '{ print $NF }').asc"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only used the part from the "official" installation and wanted to keep the steps :)
https://github.com/tianon/gosu

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@htuscher
Copy link
Member

@mblaschke ok, I'll get it. Brilliant solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants