Skip to content

Commit abc4a5f

Browse files
authored
CRW-9383: only root perms for /etc/passwd (#578)
* CRW-9383: only root.root perms for /etc/passwd * remove boilderplate that already exists on the DockerFile Signed-off-by: Stephane Bouchet <sbouchet@redhat.com> --------- Signed-off-by: Stephane Bouchet <sbouchet@redhat.com>
1 parent b117e25 commit abc4a5f

3 files changed

Lines changed: 2 additions & 24 deletions

File tree

build/dockerfiles/assembly.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ COPY --from=linux-libc-ubi9-content --chown=0:0 /checode-linux-libc/ubi9 /mnt/ro
2929
RUN mkdir -p /mnt/rootfs/projects && mkdir -p /mnt/rootfs/home/che && mkdir -p /mnt/rootfs/bin/
3030
RUN cat /mnt/rootfs/etc/passwd | sed s#root:x.*#root:x:\${USER_ID}:\${GROUP_ID}::\${HOME}:/bin/bash#g > /mnt/rootfs/home/che/.passwd.template \
3131
&& cat /mnt/rootfs/etc/group | sed s#root:x:0:#root:x:0:0,\${USER_ID}:#g > /mnt/rootfs/home/che/.group.template
32-
RUN for f in "/mnt/rootfs/bin/" "/mnt/rootfs/home/che" "/mnt/rootfs/etc/passwd" "/mnt/rootfs/etc/group" "/mnt/rootfs/projects" ; do\
32+
RUN for f in "/mnt/rootfs/bin/" "/mnt/rootfs/home/che" "/mnt/rootfs/etc/group" "/mnt/rootfs/projects" ; do\
3333
chgrp -R 0 ${f} && \
3434
chmod -R g+rwX ${f}; \
3535
done
36+
RUN chmod -R g-w /mnt/rootfs/etc/passwd
3637

3738
COPY --from=machine-exec --chown=0:0 /go/bin/che-machine-exec /mnt/rootfs/bin/machine-exec
3839
COPY --chmod=755 /build/scripts/*.sh /mnt/rootfs/

build/scripts/entrypoint-volume.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ get_openssl_version() {
5858
fi
5959
}
6060

61-
# Boilerplate code for arbitrary user support
62-
if ! whoami >/dev/null 2>&1; then
63-
if [ -w /etc/passwd ]; then
64-
echo "${USER_NAME:-user}:x:$(id -u):0:${USER_NAME:-user} user:${HOME}:/bin/bash" >> /etc/passwd
65-
echo "${USER_NAME:-user}:x:$(id -u):" >> /etc/group
66-
fi
67-
fi
68-
6961
# list checode
7062
ls -la /checode/
7163

build/scripts/entrypoint.sh

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@
1313
export USER_ID=$(id -u)
1414
export GROUP_ID=$(id -g)
1515

16-
if ! grep -Fq "${USER_ID}" /etc/passwd; then
17-
# current user is an arbitrary
18-
# user (its uid is not in the
19-
# container /etc/passwd). Let's fix that
20-
cat ${HOME}/.passwd.template | \
21-
sed "s/\${USER_ID}/${USER_ID}/g" | \
22-
sed "s/\${GROUP_ID}/${GROUP_ID}/g" | \
23-
sed "s/\${HOME}/\/che-vscode/g" > /etc/passwd
24-
25-
cat ${HOME}/.group.template | \
26-
sed "s/\${USER_ID}/${USER_ID}/g" | \
27-
sed "s/\${GROUP_ID}/${GROUP_ID}/g" | \
28-
sed "s/\${HOME}/\/che-vscode/g" > /etc/group
29-
fi
30-
3116
if [ -z "$CODE_HOST" ]; then
3217
CODE_HOST="127.0.0.1"
3318
fi

0 commit comments

Comments
 (0)