Skip to content

Commit e834dd5

Browse files
authored
Remove NONROOT_USER, add /usr/bin/cc symlink (#16)
1 parent 7cb60cf commit e834dd5

File tree

12 files changed

+45
-63
lines changed

12 files changed

+45
-63
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: 4 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
@@ -176,6 +170,8 @@ rm -rf /var/lib/apt/lists/*
176170
EOF
177171
ENV CC=/usr/bin/clang-${CLANG_VERSION}
178172
ENV CXX=/usr/bin/clang++-${CLANG_VERSION}
173+
# This is required by some build dependencies
174+
RUN update-alternatives --install /usr/bin/cc cc $CC 999
179175

180176
# Check that the installed Clang version matches the expected version.
181177
RUN <<EOF
@@ -193,9 +189,7 @@ if [[ "${CXX_VER}" != "${CLANG_VERSION}" ]]; then
193189
fi
194190
EOF
195191

196-
# Switch to the non-root user.
197-
USER ${NONROOT_USER}
198-
ENV HOME=/home/${NONROOT_USER}
192+
ENV HOME=/root
199193
WORKDIR ${HOME}
200194

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

docker/debian/README.md

Lines changed: 10 additions & 6 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,9 +86,18 @@ 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

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)**.
94+
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 securing the container from other users on the same host.
100+
96101
Once inside the container you can run the following commands to build `rippled`:
97102

98103
```shell
@@ -113,7 +118,6 @@ PARALLELISM=2
113118
cmake --build . -j ${PARALLELISM}
114119
./rippled --unittest --unittest-jobs ${PARALLELISM}
115120
```
116-
```
117121

118122
#### Pushing the Docker image to the GitHub registry
119123

docker/rhel/Dockerfile

Lines changed: 5 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

@@ -56,6 +52,7 @@ dnf remove -y gcc gcc-c++
5652
dnf install -y --setopt=tsflags=nodocs gcc-toolset-${GCC_VERSION}-gcc gcc-toolset-${GCC_VERSION}-gcc-c++
5753
dnf clean -y all
5854
rm -rf /var/cache/dnf/*
55+
update-alternatives --install /usr/bin/cc cc /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc 999
5956
update-alternatives \
6057
--install /usr/bin/gcc gcc /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/gcc ${GCC_VERSION} \
6158
--slave /usr/bin/g++ g++ /opt/rh/gcc-toolset-${GCC_VERSION}/root/usr/bin/g++ \
@@ -83,9 +80,7 @@ if [[ "${CXX_VER}" != "${GCC_VERSION}" ]]; then
8380
fi
8481
EOF
8582

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

9186
# Set Conan home directory, so the users of this image can find default profile
@@ -147,6 +142,8 @@ rm -rf /var/cache/dnf/*
147142
EOF
148143
ENV CC=/usr/bin/clang
149144
ENV CXX=/usr/bin/clang++
145+
# This is required by some build dependencies
146+
RUN update-alternatives --install /usr/bin/cc cc $CC 999
150147

151148
# Check that the installed Clang version is not older than the minimum required.
152149
ARG MINIMUM_CLANG_VERSION=16
@@ -165,9 +162,7 @@ if [[ ${CXX_VER} -lt ${MINIMUM_CLANG_VERSION} ]]; then
165162
fi
166163
EOF
167164

168-
# Switch to the non-root user.
169-
USER ${NONROOT_USER}
170-
ENV HOME=/home/${NONROOT_USER}
165+
ENV HOME=/root
171166
WORKDIR ${HOME}
172167

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

docker/rhel/README.md

Lines changed: 10 additions & 5 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,9 +103,18 @@ 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

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)**.
111+
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 securing the container from other users on the same host.
117+
113118
Once inside the container you can run the following commands to build `rippled`:
114119

115120
```shell

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)