-
Notifications
You must be signed in to change notification settings - Fork 79
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
draft: feat: Run as non-root by default to allow easier deployment on the restricted environments like OpenShift, Kubernetes and any corporate (or just secure) environments where root privileges are not allowed #308
base: master
Are you sure you want to change the base?
Changes from all commits
afd6192
13fb159
94d6aac
e2f4980
ff2ea1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,13 +99,16 @@ jobs: | |
- name: Spin up services | ||
run: docker-compose -f docker-compose.yml up -d | ||
- name: Wait | ||
run: sleep 60 | ||
run: sleep 70 | ||
- name: Check status | ||
run: docker ps -a | ||
- name: Test | ||
run: curl http://localhost:8080/ -L --fail -s | grep 'Sign in</button>' -q | ||
run: curl http://localhost:8080/ -L --fail -vvv | grep 'Sign in</button>' -q | ||
- name: Test Email | ||
run: docker-compose exec -T humhub php /var/www/localhost/htdocs/protected/yii test/email '[email protected]' | grep 'Message successfully sent!' -q | ||
- name: Collect logs | ||
if: ${{ always() }} | ||
run: docker-compose -f docker-compose.prod.yml logs | ||
test_prod: | ||
needs: build_variants | ||
runs-on: ubuntu-latest | ||
|
@@ -140,13 +143,16 @@ jobs: | |
- name: Spin up services | ||
run: docker-compose -f docker-compose.prod.yml up -d | ||
- name: Wait | ||
run: sleep 60 | ||
run: sleep 70 | ||
- name: Check status | ||
run: docker ps -a | ||
- name: Test | ||
run: curl http://localhost:8080/ -L --fail -s | grep 'Sign in</button>' -q | ||
run: curl http://localhost:8080/ -L --fail -vvv | grep 'Sign in</button>' -q | ||
- name: Test Email | ||
run: docker-compose exec -T humhub php /var/www/localhost/htdocs/protected/yii test/email '[email protected]' | grep 'Message successfully sent!' -q | ||
- name: Collect logs | ||
if: ${{ always() }} | ||
run: docker-compose -f docker-compose.prod.yml logs | ||
push_ghcr: | ||
needs: ["test_aio", "test_prod"] | ||
runs-on: ubuntu-latest | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ ARG RUNTIME_DEPS="\ | |
php7-xmlwriter \ | ||
php7-zip \ | ||
sqlite \ | ||
supervisor \ | ||
multirun \ | ||
tzdata \ | ||
" | ||
|
||
|
@@ -112,17 +112,15 @@ RUN apk add --no-cache --update $RUNTIME_DEPS && \ | |
apk add --no-cache --virtual temp_pkgs gettext && \ | ||
cp /usr/bin/envsubst /usr/local/bin/envsubst && \ | ||
apk del temp_pkgs && \ | ||
rm -rf /var/cache/apk/* | ||
rm -rf /var/cache/apk/* && \ | ||
chmod +x /usr/bin/multirun | ||
|
||
ENV PHP_POST_MAX_SIZE=16M | ||
ENV PHP_UPLOAD_MAX_FILESIZE=10M | ||
ENV PHP_MAX_EXECUTION_TIME=60 | ||
ENV PHP_MEMORY_LIMIT=1G | ||
ENV PHP_TIMEZONE=UTC | ||
|
||
RUN touch /var/run/supervisor.sock && \ | ||
chmod 777 /var/run/supervisor.sock | ||
|
||
# 100=nginx 101=nginx (group) | ||
COPY --from=builder --chown=100:101 /usr/src/humhub /var/www/localhost/htdocs/ | ||
COPY --chown=100:101 humhub/ /var/www/localhost/htdocs/ | ||
|
@@ -132,23 +130,40 @@ RUN mkdir -p /usr/src/humhub/protected/config/ && \ | |
rm -f var/www/localhost/htdocs/protected/config/common.php /usr/src/humhub/protected/config/common.php && \ | ||
echo "v${HUMHUB_VERSION}" > /usr/src/humhub/.version | ||
|
||
# Non-root directories | ||
RUN mkdir -p /var/www/localhost/htdocs/protected/runtime/logs && \ | ||
mkdir -p /var/www/localhost/htdocs/uploads /var/www/localhost/htdocs/assets /var/www/localhost/htdocs/protected/modules /var/www/localhost/htdocs/themes /var/www/localhost/htdocs/protected/config && \ | ||
mkdir -p /run/nginx /run/php-fpm && \ | ||
touch /var/www/localhost/htdocs/protected/runtime/logs/app.log && \ | ||
chown 100:101 -R /var/www/localhost/htdocs/protected/runtime/logs /run/nginx /run/php-fpm \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for an openshift setup using the group 0 might be better than 101 because openshift gives the user a "random" high-id and the group 0. If we just allow the group 0 to read/write most parts of the files this should work in most scenarios. |
||
/var/www/localhost/htdocs/uploads /var/www/localhost/htdocs/assets \ | ||
/var/www/localhost/htdocs/protected/modules /var/www/localhost/htdocs/themes \ | ||
/var/www/localhost/htdocs/protected/config | ||
|
||
|
||
COPY base/ / | ||
COPY docker-entrypoint.sh /docker-entrypoint.sh | ||
|
||
RUN chmod 600 /etc/crontabs/nginx && \ | ||
chown 100:101 /etc/crontabs/nginx && \ | ||
rm /etc/crontabs/root && \ | ||
chmod +x /docker-entrypoint.sh | ||
|
||
VOLUME /var/www/localhost/htdocs/uploads | ||
VOLUME /var/www/localhost/htdocs/protected/config | ||
VOLUME /var/www/localhost/htdocs/protected/modules | ||
|
||
ENTRYPOINT ["/docker-entrypoint.sh"] | ||
CMD ["supervisord", "-n", "-c", "/etc/supervisord.conf"] | ||
|
||
|
||
#+----------- | ||
# HumHub PHP | ||
#+----------- | ||
FROM base as humhub_phponly | ||
|
||
LABEL variant="phponly" | ||
|
||
USER root | ||
RUN apk add --no-cache fcgi | ||
|
||
COPY phponly/ / | ||
|
@@ -159,7 +174,13 @@ RUN chmod +x /usr/local/bin/php-fpm-healthcheck \ | |
&& adduser --uid 100 -g 101 -S nginx | ||
|
||
EXPOSE 9000 | ||
USER nginx | ||
CMD ["multirun", "/usr/sbin/php-fpm7 --fpm-config /etc/php-fpm.d/pool.conf -O -F", "tail -f /var/www/localhost/htdocs/protected/runtime/logs/app.log", "crond -f -L /proc/self/fd/2"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tailing on this file is not the best idea ... it still writes to the top-layer potentially filling up the nodes local storage. We should use a symlink to /proc/self/fd/2 for that (if possible). |
||
|
||
|
||
#+------------- | ||
# HumHub NGINX | ||
#+------------- | ||
FROM docker.io/library/nginx:1.23.3-alpine as humhub_nginx | ||
|
||
LABEL variant="nginx" | ||
|
@@ -168,16 +189,29 @@ ENV NGINX_CLIENT_MAX_BODY_SIZE=10m \ | |
NGINX_KEEPALIVE_TIMEOUT=65 \ | ||
NGINX_UPSTREAM=humhub:9000 | ||
|
||
USER root | ||
COPY nginx/ / | ||
COPY --from=builder --chown=nginx:nginx /usr/src/humhub/ /var/www/localhost/htdocs/ | ||
RUN mkdir -p /var/cache/nginx /run/nginx && \ | ||
chown nginx:nginx -R /etc/nginx /var/cache/nginx /run/nginx | ||
|
||
USER nginx | ||
|
||
#+------------------ | ||
# HumHub All-in-one | ||
#+------------------ | ||
FROM base as humhub_allinone | ||
|
||
LABEL variant="allinone" | ||
|
||
USER root | ||
RUN apk add --no-cache nginx && \ | ||
chown -R nginx:nginx /var/lib/nginx/ | ||
mkdir -p /etc/nginx && \ | ||
chown -R nginx:nginx /var/lib/nginx/ /etc/nginx | ||
|
||
COPY nginx/ / | ||
RUN chown nginx:nginx -R /etc/nginx | ||
|
||
EXPOSE 80 | ||
USER nginx | ||
CMD ["/usr/bin/multirun", "/usr/sbin/php-fpm7 --fpm-config /etc/php-fpm.d/pool.conf -O -F", "tail -f /var/www/localhost/htdocs/protected/runtime/logs/app.log", "crond -f -L /proc/self/fd/2", "/usr/sbin/nginx -g 'daemon off;'"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
listen = /run/php-fpm.sock | ||
listen = /run/nginx/php-fpm.sock | ||
listen.owner = nginx | ||
listen.group = nginx |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if HumHub has been fully tested with multirun, you should probably run some tests before switching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.humhub.org/docs/admin/asynchronous-tasks/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case
crond
is used instead ofsupervisor
.