Skip to content

Commit 8d6bcd2

Browse files
authored
drop permissions of container to match host system (#8021)
* drop permissions of container to match host system * try conditional if * [ci lang-only Pascal]: revert test change * [ci lang-only Pascal]: Update Dockerfile * [ci lang-only Pascal]: use gosu to drop permissions
1 parent 15a641c commit 8d6bcd2

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142
if: ${{ env.RUN_TESTS }}
143143
uses: mattes/cached-docker-build-action@v1
144144
with:
145-
args: " --file ./Dockerfile --tag techempower/tfb ."
145+
args: " --file ./Dockerfile --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) --tag techempower/tfb ."
146146
cache_key: "${{ hashFiles('./Dockerfile') }}"
147147
- name: Stop services
148148
# Stop services that would claim ports we may need
@@ -155,7 +155,7 @@ jobs:
155155
# run-ci.py runs the diffing to see if github actions needs to test this framework. Ideally/eventually,
156156
# we'd like to try and do the diffing before github_actions_clean & setup.
157157
# This will run the tests exactly as you would in your own vm:
158-
docker network create tfb > /dev/null 2>&1 && docker run --network=tfb -v /var/run/docker.sock:/var/run/docker.sock --mount type=bind,source=`pwd`,target=/FrameworkBenchmarks techempower/tfb --mode verify --test-dir $RUN_TESTS --results-environment Github-Actions;
158+
docker network create tfb > /dev/null 2>&1 && docker run --network=tfb -e USER_ID=$(id -u) -v /var/run/docker.sock:/var/run/docker.sock --mount type=bind,source=`pwd`,target=/FrameworkBenchmarks techempower/tfb --mode verify --test-dir $RUN_TESTS --results-environment Github-Actions;
159159
dependabot:
160160
needs: verify
161161
runs-on: ubuntu-latest

Dockerfile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM ubuntu:22.04
22

3+
ARG USER_ID
4+
ARG GROUP_ID
35
ARG DEBIAN_FRONTEND=noninteractive
46

57
#RUN add-apt-repository universe
@@ -13,6 +15,7 @@ RUN apt-get -yqq update && apt-get -yqq install \
1315
dstat `# Collect resource usage statistics` \
1416
gcc \
1517
git-core \
18+
gosu \
1619
libmysqlclient-dev `# Needed for MySQL-python` \
1720
libpq-dev \
1821
python2 \
@@ -39,4 +42,17 @@ RUN pip install \
3942

4043
ENV FWROOT=/FrameworkBenchmarks PYTHONPATH=/FrameworkBenchmarks
4144

42-
ENTRYPOINT ["python2", "/FrameworkBenchmarks/toolset/run-tests.py"]
45+
# Check if Group is already created
46+
RUN if ! getent group $GROUP_ID; then \
47+
addgroup --gid $GROUP_ID user; \
48+
fi
49+
50+
# Drop permissions of user to match those of the host system
51+
# Check if the User ID is already created
52+
RUN if ! getent passwd $USER_ID; then \
53+
adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID user; \
54+
fi
55+
56+
ENV USER_ID=$USER_ID
57+
58+
ENTRYPOINT ["/bin/bash", "FrameworkBenchmarks/entrypoint.sh" ]

entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -euox pipefail
3+
4+
chown -R $USER_ID /var/run/
5+
6+
gosu $USER_ID python2 /FrameworkBenchmarks/toolset/run-tests.py "$@"

tfb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,5 @@ if ! docker network inspect tfb >/dev/null 2>&1; then
102102
fi
103103

104104
test -t 1 && USE_TTY="-t"
105-
docker build -t techempower/tfb - < ${SCRIPT_ROOT}/Dockerfile
106-
exec docker run -i ${USE_TTY} ${EXTRA_DOCKER_ARGS} --rm --network tfb -v /var/run/docker.sock:/var/run/docker.sock -v ${SCRIPT_ROOT}:/FrameworkBenchmarks techempower/tfb "${@}"
105+
docker build -t techempower/tfb --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) - < ${SCRIPT_ROOT}/Dockerfile
106+
exec docker run -i ${USE_TTY} ${EXTRA_DOCKER_ARGS} --rm --network tfb -e USER_ID=$(id -u) -v /var/run/docker.sock:/var/run/docker.sock -v ${SCRIPT_ROOT}:/FrameworkBenchmarks techempower/tfb "${@}"

0 commit comments

Comments
 (0)