-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tomcat process runs as ROOT within container #46
Comments
Though not entirely a solution to this issue, I run this image as a non root user with namespaces like this: It works well. |
Tomcat official base image doesn't have non-root option currently (still?) but there's one suggested workaround in this issue comment; I'm not sure if that's a commonly accepted practice or whether it's still valid. If there's interest in a Lucee non-root image that works out of the box then perhaps we could provide an alternative tag for it at least. The main downside is working with volumes, some users may experience permission issues with files when the UID/GID changes/doesn't match. |
Also if anyone has working examples that they've implemented and would like to share that could be a good starting point. |
My build process doesn't use these Dockerfiles, nor do I use the tomcat image from Docker, because I need to use different JVMs with tomcat on various different child images - I use Corretto 8, Zulu 7 and Oracle 8, and eventually I'll need to do things with 11, so I have my own copy of the tomcat Dockerfile. I put tomcat in /opt/tomcat instead of /usr/local.... And I provision a tomcat user:
tomcat:tomcat for things the daemon needs to write to. Later, I run the tomcat daemon using runit: Running catalina with "run" versus "start" keeps it in the foreground. chpst is making it run as tomcat, with the www-data supplemental group. This should be completely possible without runit by, for example, using "USER tomcat" in the dockerfile, and setting the CMD to ["/opt/tomcat/bin/catalina.sh", "run" ] (or using an entrypoint that does that) |
Thanks Joe that's super helpful, much appreciated :D I'll take a look in the coming weeks to see how I might be able to integrate this or at least offer it as an alternative. |
My Dockerfile change to work around this. (I have a # add tomcat user to supervisord.conf
# grep fails the command if the line isn't found.
RUN grep -q '\[program:lucee\]' /etc/supervisor/conf.d/supervisord.conf && \
sed -i '/^\[program:lucee\]$/a user=tomcat' /etc/supervisor/conf.d/supervisord.conf
# add the external docker group
RUN set -x && \
groupadd -g $DATA_GID www-data-docker && \
groupadd tomcat && \
usermod www-data -aG www-data-docker
# set tomcat to run as a non-root user
# root:tomcat -> /usr/local/tomcat/webapps/ROOT/WEB-INF ?
# tomcat:tomcat /usr/local/tomcat/.java ?
# root:www-data-docker /var/www/WEB-INF ?
RUN set -x && \
useradd -c "tomcat" -M -g www-data-docker tomcat && \
usermod -G tomcat tomcat && \
chown -R root:tomcat /usr/local/tomcat/ /opt/lucee/ && \
chown -R tomcat:tomcat \
/usr/local/tomcat/logs \
/usr/local/tomcat/temp \
/usr/local/tomcat \
/usr/local/tomcat/conf/Catalina \
/opt/lucee/web/ \
/opt/lucee/server/ \
&& \
chmod -R u+rwX,g+rX-w,o-rwx /usr/local/tomcat
# ensure that tomcat doesn't screw up and re-create the lucee-server directory inside tomcat
RUN touch /usr/local/tomcat/lucee-server && chmod u-rw,g-rw,o-rw /usr/local/tomcat/lucee-server |
Well, that looks easy - we should do this ? Does it effect accessing files file a volume ( |
There are ramifications for host volumes (see this, for instance: docker-solr/docker-solr#118 (comment)). I'm not saying it shouldn't be done, but IIRC, it does introduce complications. As long as we're on the subject, I got an assist from an OpenShift developer a while back when I was trying to lobby the Solr image developers for changes to its image. It still might be relevant if the Lucee Docker project is considering changes to user/permissions. docker-solr/docker-solr#126 (comment) |
nginx is properly configured to drop privileges and run as www-data
The generic tomcat images do NOT create a tomcat service account. It's relatively trivial to create your own, and run as that user, but the default Docker Community images don't provide it.
While containers do have some levels of isolation it's best practice to NOT run internet accessible services as root, whether they're in a container or not.
The text was updated successfully, but these errors were encountered: