-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: run all services as unprivileged containers
With this change, containers are no longer run as "root" but as unprivileged users. This is necessary in some environments, notably some Kubernetes clusters. To make this possible, we need to manually fix bind-mounted volumes in docker-compose. This is pretty much equivalent to the behaviour in Kubernetes, where permissions are fixed at runtime if the volume owner is incorrect. Thus, we have a consistent behaviour between docker-compose and Kubernetes. We achieve this by bind-mounting some repos inside "*-permissions" services. These services run as root user on docker-compose and will fix the required permissions, as per build/permissions/setowner.sh These services simply do not run on Kubernetes, where we don't rely on bind-mounted volumes. There, we make use of Kubernete's built-in volume ownership feature. With this change, we get rid of the "openedx-dev" Docker image, in the sense that it no longer has its own Dockerfile. Instead, the dev image is now simply a different target in the multi-layer openedx Docker image. This makes it much faster to build the openedx-dev image. Because we declare the APP_USER_ID in the dev/docker-compose.yml file, we need to pass the user ID from the host there. The only way to achieve that is with a tutor config variable. The downside of this approach is that the dev/docker-compose.yml file is no longer portable from one machine to the next. We consider that this is not such a big issue, as it affects the development environment only. We take this opportunity to replace the base image of the "forum" image. There is now no need to re-install ruby inside the image. The total image size is only decreased by 10%, but re-building the image is faster. In order to run the smtp service as non-root, we switch from namshi/smtp to devture/exim-relay. This change should be backward-compatible. Note that the nginx container remains privileged. We could switch to nginxinc/nginx-unprivileged, but it's probably not worth the effort, as we are considering to get rid of the nginx container altogether. Close #323.
- Loading branch information
Showing
20 changed files
with
230 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM docker.io/ubuntu:20.04 | ||
FROM docker.io/ruby:2.5.7-slim-stretch | ||
MAINTAINER Overhang.io <[email protected]> | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
@@ -12,32 +12,27 @@ RUN wget -O /tmp/dockerize.tar.gz https://github.com/jwilder/dockerize/releases/ | |
&& tar -C /usr/local/bin -xzvf /tmp/dockerize.tar.gz \ | ||
&& rm /tmp/dockerize.tar.gz | ||
|
||
RUN mkdir /openedx | ||
# Create unprivileged "app" user | ||
RUN useradd --home-dir /app --create-home --shell /bin/bash --uid 1000 app | ||
|
||
# Install ruby-build for building specific version of ruby | ||
# The ruby-build version should be periodically updated to reflect the latest release | ||
ARG RUBY_BUILD_VERSION=v20200401 | ||
RUN git clone https://github.com/rbenv/ruby-build.git --branch $RUBY_BUILD_VERSION /openedx/ruby-build | ||
WORKDIR /openedx/ruby-build | ||
RUN PREFIX=/usr/local ./install.sh | ||
# Copy custom scripts | ||
COPY ./bin /app/bin | ||
RUN chmod a+x /app/bin/* | ||
ENV PATH :${PATH} | ||
|
||
# Install ruby and some specific dependencies | ||
ARG RUBY_VERSION=2.5.7 | ||
ARG BUNDLER_VERSION=1.17.3 | ||
ARG RAKE_VERSION=13.0.1 | ||
RUN ruby-build $RUBY_VERSION /openedx/ruby | ||
ENV PATH "/openedx/ruby/bin:$PATH" | ||
RUN gem install bundler -v $BUNDLER_VERSION | ||
RUN gem install rake -v $RAKE_VERSION | ||
# From then on, run as unprivileged app user | ||
USER app | ||
|
||
# Install rake and bundler | ||
ENV PATH "/app/bin:/app/.gem/ruby/2.5.0/bin:$PATH" | ||
RUN gem install --user-install bundler --version 1.17.3 | ||
RUN gem install --user-install rake --version 13.0.1 | ||
|
||
# Install forum | ||
RUN git clone https://github.com/edx/cs_comments_service.git --branch {{ OPENEDX_COMMON_VERSION }} --depth 1 /openedx/cs_comments_service | ||
WORKDIR /openedx/cs_comments_service | ||
RUN git clone https://github.com/edx/cs_comments_service.git --branch {{ OPENEDX_COMMON_VERSION }} --depth 1 /app/cs_comments_service | ||
WORKDIR /app/cs_comments_service | ||
RUN bundle install --deployment | ||
|
||
COPY ./bin /openedx/bin | ||
RUN chmod a+x /openedx/bin/* | ||
ENV PATH /openedx/bin:${PATH} | ||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
|
||
ENV SINATRA_ENV staging | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
tutor/templates/build/openedx-dev/bin/docker-entrypoint.sh
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from docker.io/alpine:3.13.6 | ||
MAINTAINER Overhang.io <[email protected]> | ||
|
||
COPY ./setowner.sh /usr/local/bin/setowner | ||
RUN chmod a+x /usr/local/bin/setowner | ||
|
||
ENTRYPOINT ["setowner"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#! /bin/sh | ||
set -e | ||
user_id="$1" | ||
shift | ||
for path in $@; do | ||
path_user_id="$(stat -c '%u' $path)" | ||
if [ "$path_user_id" != "$user_id" ] | ||
then | ||
echo "$path changing UID from $path_user_id to $user_id..." | ||
chown --recursive $user_id $path | ||
else | ||
echo "$path already owned by $user_id" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.