Skip to content

Commit 8252c7f

Browse files
committed
Remove NONROOT_USER, better support for rootless environment
1 parent 7a3764a commit 8252c7f

File tree

12 files changed

+31
-120
lines changed

12 files changed

+31
-120
lines changed

.github/workflows/debian.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ env:
1212
BUILDKIT_PROGRESS: plain
1313
CONAN_VERSION: 2.18.0
1414
GCOVR_VERSION: 8.3
15-
NONROOT_USER: ci
1615
FALLBACK_GCC: 12
1716
FALLBACK_CLANG: 16
1817

@@ -103,7 +102,6 @@ jobs:
103102
CONAN_VERSION=${{ env.CONAN_VERSION }}
104103
GCC_VERSION=${{ matrix.os.compiler_name == 'gcc' && matrix.os.compiler_version || env.FALLBACK_GCC }}
105104
GCOVR_VERSION=${{ env.GCOVR_VERSION }}
106-
NONROOT_USER=${{ env.NONROOT_USER }}
107105
DEBIAN_VERSION=${{ matrix.os.release }}
108106
context: .
109107
file: docker/debian/Dockerfile

.github/workflows/rhel.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ env:
1313
BUILDKIT_PROGRESS: plain
1414
CONAN_VERSION: 2.18.0
1515
GCOVR_VERSION: 8.3
16-
NONROOT_USER: ci
1716

1817
jobs:
1918
# Build the Docker image for Red Hat Enterprise Linux using different versions
@@ -93,7 +92,6 @@ jobs:
9392
CONAN_VERSION=${{ env.CONAN_VERSION }}
9493
GCC_VERSION=${{ matrix.os.compiler_version }}
9594
GCOVR_VERSION=${{ env.GCOVR_VERSION }}
96-
NONROOT_USER=${{ env.NONROOT_USER }}
9795
RHEL_VERSION=${{ matrix.os.release }}
9896
context: .
9997
file: docker/rhel/Dockerfile

.github/workflows/tools-rippled.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ env:
1111
BUILDKIT_PROGRESS: plain
1212
CLANG_FORMAT_VERSION: 18.1.8
1313
PRE_COMMIT_VERSION: 4.2.0
14-
NONROOT_USER: ci
1514
UBUNTU_VERSION: noble
1615

1716
jobs:
@@ -72,7 +71,6 @@ jobs:
7271
build-args: |
7372
BUILDKIT_DOCKERFILE_CHECK=skip=InvalidDefaultArgInFrom
7473
BUILDKIT_INLINE_CACHE=1
75-
NONROOT_USER=${{ env.NONROOT_USER }}
7674
UBUNTU_VERSION=${{ env.UBUNTU_VERSION }}
7775
CLANG_FORMAT_VERSION=${{ env.CLANG_FORMAT_VERSION }}
7876
PRE_COMMIT_VERSION=${{ env.PRE_COMMIT_VERSION }}

.github/workflows/ubuntu.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ env:
1212
BUILDKIT_PROGRESS: plain
1313
CONAN_VERSION: 2.18.0
1414
GCOVR_VERSION: 8.3
15-
NONROOT_USER: ci
1615
FALLBACK_GCC: 12
1716
FALLBACK_CLANG: 16
1817

@@ -101,7 +100,6 @@ jobs:
101100
CONAN_VERSION=${{ env.CONAN_VERSION }}
102101
GCC_VERSION=${{ matrix.os.compiler_name == 'gcc' && matrix.os.compiler_version || env.FALLBACK_GCC }}
103102
GCOVR_VERSION=${{ env.GCOVR_VERSION }}
104-
NONROOT_USER=${{ env.NONROOT_USER }}
105103
UBUNTU_VERSION=${{ matrix.os.release }}
106104
context: .
107105
file: docker/ubuntu/Dockerfile

docker/debian/Dockerfile

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ ENV PIPX_HOME=/opt/pipx \
6565
RUN pipx install --pip-args='--no-cache' conan==${CONAN_VERSION} && \
6666
pipx install --pip-args='--no-cache' gcovr==${GCOVR_VERSION}
6767

68-
# Create the user to switch to, once all packages have been installed.
69-
ARG NONROOT_USER
70-
RUN useradd -ms /bin/bash ${NONROOT_USER}
71-
7268
# ====================== GCC IMAGE ======================
7369
FROM base AS gcc
7470

@@ -120,9 +116,7 @@ if [[ "${CXX_VER}" != "${GCC_VERSION}" ]]; then
120116
fi
121117
EOF
122118

123-
# Switch to the non-root user.
124-
USER ${NONROOT_USER}
125-
ENV HOME=/home/${NONROOT_USER}
119+
ENV HOME=/root
126120
WORKDIR ${HOME}
127121

128122
# Set Conan home directory, so the users of this image can find default profile
@@ -195,9 +189,7 @@ if [[ "${CXX_VER}" != "${CLANG_VERSION}" ]]; then
195189
fi
196190
EOF
197191

198-
# Switch to the non-root user.
199-
USER ${NONROOT_USER}
200-
ENV HOME=/home/${NONROOT_USER}
192+
ENV HOME=/root
201193
WORKDIR ${HOME}
202194

203195
# Set Conan home directory, so the users of this image can find default profile

docker/debian/README.md

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ Ensure you've run the login command above to authenticate with the Docker
3737
registry.
3838

3939
```shell
40-
NONROOT_USER=${USER}
4140
DEBIAN_VERSION=bookworm
4241
GCC_VERSION=12
4342
CONAN_VERSION=2.18.0
@@ -53,7 +52,6 @@ docker buildx build . \
5352
--build-arg DEBIAN_VERSION=${DEBIAN_VERSION} \
5453
--build-arg GCC_VERSION=${GCC_VERSION} \
5554
--build-arg GCOVR_VERSION=${GCOVR_VERSION} \
56-
--build-arg NONROOT_USER=${NONROOT_USER} \
5755
--tag ${CONTAINER_REGISTRY}/${CONTAINER_IMAGE}
5856
```
5957

@@ -63,7 +61,6 @@ Ensure you've run the login command above to authenticate with the Docker
6361
registry.
6462

6563
```shell
66-
NONROOT_USER=${USER}
6764
DEBIAN_VERSION=bookworm
6865
CLANG_VERSION=17
6966
CONAN_VERSION=2.18.0
@@ -79,7 +76,6 @@ docker buildx build . \
7976
--build-arg CONAN_VERSION=${CONAN_VERSION} \
8077
--build-arg DEBIAN_VERSION=${DEBIAN_VERSION} \
8178
--build-arg GCOVR_VERSION=${GCOVR_VERSION} \
82-
--build-arg NONROOT_USER=${NONROOT_USER} \
8379
--tag ${CONTAINER_REGISTRY}/${CONTAINER_IMAGE}
8480
```
8581

@@ -90,30 +86,17 @@ can do so with the following command:
9086

9187
```shell
9288
CODEBASE=<path to the rippled repository>
93-
docker run --rm -it -v ${CODEBASE}:/rippled ${CONTAINER_REGISTRY}/${CONTAINER_IMAGE}
89+
docker run --user $(id -u):$(id -g) --rm -it -v ${CODEBASE}:/rippled ${CONTAINER_REGISTRY}/${CONTAINER_IMAGE}
9490
```
9591

96-
Once inside the container you can run the following commands to build `rippled`:
92+
Note, the above command will assume the identity of the current user in the newly created Docker container.
93+
**This might be exploited by other users with access to the same host (docker instance)**.
9794

98-
```shell
99-
BUILD_TYPE=Debug
100-
cd /rippled
101-
# Remove any existing data from previous builds on the host machine.
102-
rm -rf CMakeCache.txt CMakeFiles build || true
103-
# Install dependencies via Conan.
104-
conan install . --build missing --settings build_type=${BUILD_TYPE} \
105-
-o xrpld=True -o tests=True -o unity=True
106-
# Configure the build with CMake.
107-
cd build
108-
cmake -DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \
109-
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} ..
110-
# Build and test rippled. Setting the parallelism too high, e.g. to $(nproc),
111-
# can result in an error like "gmake[2]: ...... Killed".
112-
PARALLELISM=2
113-
cmake --build . -j ${PARALLELISM}
114-
./rippled --unittest --unittest-jobs ${PARALLELISM}
115-
```
116-
```
95+
The recommended practice is to run Docker in [rootless mode](https://docs.docker.com/engine/security/rootless/),
96+
or use alternative container runtime such as [podman](https://docs.podman.io/en/latest/) which
97+
support [rootless environment](https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md).
98+
This will have similar effect as `--user $(id -u):$(id -g)` (making this option redundant and invalid),
99+
while also securiting the container from other users on the same host.
117100

118101
#### Pushing the Docker image to the GitHub registry
119102

docker/rhel/Dockerfile

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ ARG CONAN_VERSION
3838
ARG GCOVR_VERSION
3939
RUN pip install --no-cache conan==${CONAN_VERSION} gcovr==${GCOVR_VERSION}
4040

41-
# Create the user to switch to, once all packages have been installed.
42-
ARG NONROOT_USER
43-
RUN useradd -ms /bin/bash ${NONROOT_USER}
44-
4541
# ====================== GCC IMAGE ======================
4642
FROM base AS gcc
4743

@@ -83,9 +79,7 @@ if [[ "${CXX_VER}" != "${GCC_VERSION}" ]]; then
8379
fi
8480
EOF
8581

86-
# Switch to the non-root user.
87-
USER ${NONROOT_USER}
88-
ENV HOME=/home/${NONROOT_USER}
82+
ENV HOME=/root
8983
WORKDIR ${HOME}
9084

9185
# Set Conan home directory, so the users of this image can find default profile
@@ -166,9 +160,7 @@ if [[ ${CXX_VER} -lt ${MINIMUM_CLANG_VERSION} ]]; then
166160
fi
167161
EOF
168162

169-
# Switch to the non-root user.
170-
USER ${NONROOT_USER}
171-
ENV HOME=/home/${NONROOT_USER}
163+
ENV HOME=/root
172164
WORKDIR ${HOME}
173165

174166
# Set Conan home directory, so the users of this image can find default profile

docker/rhel/README.md

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Ensure you've run the login command above to authenticate with the Docker
5656
registry.
5757

5858
```shell
59-
NONROOT_USER=${USER}
6059
RHEL_VERSION=9.6
6160
GCC_VERSION=13
6261
CONAN_VERSION=2.18.0
@@ -71,7 +70,6 @@ docker buildx build . \
7170
--build-arg CONAN_VERSION=${CONAN_VERSION} \
7271
--build-arg GCC_VERSION=${GCC_VERSION} \
7372
--build-arg GCOVR_VERSION=${GCOVR_VERSION} \
74-
--build-arg NONROOT_USER=${NONROOT_USER} \
7573
--build-arg RHEL_VERSION=${RHEL_VERSION} \
7674
--tag ${CONTAINER_REGISTRY}/${CONTAINER_IMAGE}
7775
```
@@ -82,7 +80,6 @@ Ensure you've run the login command above to authenticate with the Docker
8280
registry.
8381

8482
```shell
85-
NONROOT_USER=${USER}
8683
RHEL_VERSION=9.6
8784
CONAN_VERSION=2.18.0
8885
GCOVR_VERSION=8.3
@@ -95,7 +92,6 @@ docker buildx build . \
9592
--build-arg BUILDKIT_INLINE_CACHE=1 \
9693
--build-arg CONAN_VERSION=${CONAN_VERSION} \
9794
--build-arg GCOVR_VERSION=${GCOVR_VERSION} \
98-
--build-arg NONROOT_USER=${NONROOT_USER} \
9995
--build-arg RHEL_VERSION=${RHEL_VERSION} \
10096
--tag ${CONTAINER_REGISTRY}/${CONTAINER_IMAGE}
10197
```
@@ -107,29 +103,17 @@ can do so with the following command:
107103

108104
```shell
109105
CODEBASE=<path to the rippled repository>
110-
docker run --rm -it -v ${CODEBASE}:/rippled ${CONTAINER_REGISTRY}/${CONTAINER_IMAGE}
106+
docker run --user $(id -u):$(id -g) --rm -it -v ${CODEBASE}:/rippled ${CONTAINER_REGISTRY}/${CONTAINER_IMAGE}
111107
```
112108

113-
Once inside the container you can run the following commands to build `rippled`:
109+
Note, the above command will assume the identity of the current user in the newly created Docker container.
110+
**This might be exploited by other users with access to the same host (docker instance)**.
114111

115-
```shell
116-
BUILD_TYPE=Debug
117-
cd /rippled
118-
# Remove any existing data from previous builds on the host machine.
119-
rm -rf CMakeCache.txt CMakeFiles build || true
120-
# Install dependencies via Conan.
121-
conan install . --build missing --settings build_type=${BUILD_TYPE} \
122-
-o xrpld=True -o tests=True -o unity=True
123-
# Configure the build with CMake.
124-
cd build
125-
cmake -DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \
126-
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} ..
127-
# Build and test rippled. Setting the parallelism too high, e.g. to $(nproc),
128-
# can result in an error like "gmake[2]: ...... Killed".
129-
PARALLELISM=2
130-
cmake --build . -j ${PARALLELISM}
131-
./rippled --unittest --unittest-jobs ${PARALLELISM}
132-
```
112+
The recommended practice is to run Docker in [rootless mode](https://docs.docker.com/engine/security/rootless/),
113+
or use alternative container runtime such as [podman](https://docs.podman.io/en/latest/) which
114+
support [rootless environment](https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md).
115+
This will have similar effect as `--user $(id -u):$(id -g)` (making this option redundant and invalid),
116+
while also securiting the container from other users on the same host.
133117

134118
#### Pushing the Docker image to the GitHub registry
135119

docker/tools-rippled/Dockerfile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ ENV PIPX_HOME=/opt/pipx \
4242
PIPX_BIN_DIR=/usr/bin \
4343
PIPX_MAN_DIR=/usr/share/man
4444

45-
# Create the user to switch to, once all packages have been installed.
46-
ARG NONROOT_USER
47-
RUN useradd -ms /bin/bash ${NONROOT_USER}
48-
4945
# ====================== clang-format IMAGE ======================
5046
# Note, we do not install a compiler here.
5147

@@ -57,7 +53,5 @@ ARG PRE_COMMIT_VERSION
5753
RUN pipx install --pip-args='--no-cache' clang-format==${CLANG_FORMAT_VERSION} && \
5854
pipx install --pip-args='--no-cache' pre-commit==${PRE_COMMIT_VERSION}
5955

60-
# Switch to the non-root user.
61-
USER ${NONROOT_USER}
62-
ENV HOME=/home/${NONROOT_USER}
56+
ENV HOME=/root
6357
WORKDIR ${HOME}

docker/tools-rippled/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ Ensure you've run the login command above to authenticate with the Docker
3939
registry.
4040

4141
```shell
42-
NONROOT_USER=${USER}
4342
UBUNTU_VERSION=noble
4443
CLANG_FORMAT_VERSION=18.1.8
4544
PRE_COMMIT_VERSION=4.2.0
@@ -51,7 +50,6 @@ docker buildx build . \
5150
--build-arg BUILDKIT_INLINE_CACHE=1 \
5251
--build-arg CLANG_FORMAT_VERSION=${CLANG_FORMAT_VERSION} \
5352
--build-arg PRE_COMMIT_VERSION=${PRE_COMMIT_VERSION} \
54-
--build-arg NONROOT_USER=${NONROOT_USER} \
5553
--build-arg UBUNTU_VERSION=${UBUNTU_VERSION} \
5654
--tag ${CONTAINER_REGISTRY}/${CONTAINER_IMAGE}
5755
```

0 commit comments

Comments
 (0)