Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 95fbc18

Browse files
committed
Refactor passwd/group related processes in theia-endpoint-runtime.
Signed-off-by: Masaki Muranaka <monaka@monami-ya.com>
1 parent 6e2d592 commit 95fbc18

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

dockerfiles/theia-endpoint-runtime/Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ COPY --from=builder /home/workspace/node_modules /home/theia/node_modules
5656
RUN rm -rf /home/theia/node_modules/@eclipse-che/theia-plugin-ext /home/theia/node_modules/@eclipse-che/theia-remote
5757
COPY --from=builder /home/workspace/packages/theia-plugin-ext /home/theia/node_modules/@eclipse-che/theia-plugin-ext
5858
COPY --from=builder /home/workspace/packages/theia-remote/lib /home/theia/lib
59+
COPY --from=builder /.passwd.template /.passwd.template
60+
COPY --from=builder /.group.template /.group.template
61+
COPY --from=builder /etc/sudoers /etc/sudoers
62+
5963
RUN mkdir /projects \
6064
# Store passwd/group as template files
61-
&& cat /etc/passwd | sed s#root:x.*#root:x:\${USER_ID}:\${GROUP_ID}::\${HOME}:/bin/sh#g > ${HOME}/passwd.template \
62-
&& cat /etc/group | sed s#root:x:0:#root:x:0:0,\${USER_ID}:#g > ${HOME}/group.template \
6365
# Change permissions to let any arbitrary user
64-
&& for f in "${HOME}" "/etc/passwd" "/etc/group" "/projects"; do \
65-
echo "Changing permissions on ${f}" && chgrp -R 0 ${f} && \
66+
&& sed -i -e 's/theia-dev/theia/g' /.passwd.template /.group.template \
67+
&& for f in "${HOME}" /etc/passwd /etc/group /projects; do \
68+
echo "Changing permissions on ${f}" && \
69+
chgrp -R 0 ${f} && \
6670
chmod -R g+rwX ${f}; \
6771
done
6872
ADD etc/entrypoint.sh /entrypoint.sh

dockerfiles/theia-endpoint-runtime/etc/entrypoint.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@ if ! grep -Fq "${USER_ID}" /etc/passwd; then
1818
# current user is an arbitrary
1919
# user (its uid is not in the
2020
# container /etc/passwd). Let's fix that
21-
cat ${HOME}/passwd.template | \
22-
sed "s/\${USER_ID}/${USER_ID}/g" | \
23-
sed "s/\${GROUP_ID}/${GROUP_ID}/g" | \
24-
sed "s/\${HOME}/\/home\/theia/g" > /etc/passwd
21+
sed -e "s/\${USER_ID}/${USER_ID}/g" \
22+
-e "s/\${GROUP_ID}/${GROUP_ID}/g" \
23+
-e "s/\${HOME}/\/home\/theia/g" \
24+
/.passwd.template > /etc/passwd
2525

26-
cat ${HOME}/group.template | \
27-
sed "s/\${USER_ID}/${USER_ID}/g" | \
28-
sed "s/\${GROUP_ID}/${GROUP_ID}/g" | \
29-
sed "s/\${HOME}/\/home\/theia/g" > /etc/group
26+
sed -e "s/\${USER_ID}/${USER_ID}/g" \
27+
-e "s/\${GROUP_ID}/${GROUP_ID}/g" \
28+
-e "s/\${HOME}/\/home\/theia/g"
29+
/.group.template > /etc/group
3030
fi
3131

3232
# Grant access to projects volume in case of non root user with sudo rights
3333
if [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1 && sudo -n true > /dev/null 2>&1; then
34-
sudo chown ${USER_ID}:${GROUP_ID} /projects
34+
sudo chmod 644 /etc/passwd /etc/group
35+
sudo chown root:root /etc/passwd /etc/group
36+
37+
sudo chown ${USER_ID}:${GROUP_ID} /projects "${HOME}"
3538
fi
3639

3740
# SITTERM / SIGINT

0 commit comments

Comments
 (0)