Skip to content

Commit 311c1d0

Browse files
Revert "CRW-9383: only root perms for /etc/passwd (#578)"
This reverts commit abc4a5f.
1 parent 4def135 commit 311c1d0

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

build/dockerfiles/assembly.Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ 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/group" "/mnt/rootfs/projects" ; do\
32+
RUN for f in "/mnt/rootfs/bin/" "/mnt/rootfs/home/che" "/mnt/rootfs/etc/passwd" "/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
3736

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

build/scripts/entrypoint-volume.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ 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+
6169
# list checode
6270
ls -la /checode/
6371

build/scripts/entrypoint.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
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+
1631
if [ -z "$CODE_HOST" ]; then
1732
CODE_HOST="127.0.0.1"
1833
fi

0 commit comments

Comments
 (0)