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

Commit

Permalink
Refactor passwd/group related processes in theia-endpoint-runtime.
Browse files Browse the repository at this point in the history
Signed-off-by: Masaki Muranaka <[email protected]>
  • Loading branch information
monaka committed Jun 21, 2019
1 parent 061c0a0 commit e9e8144
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
12 changes: 8 additions & 4 deletions dockerfiles/theia-endpoint-runtime/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ COPY --from=builder /home/workspace/node_modules /home/theia/node_modules
RUN rm -rf /home/theia/node_modules/@eclipse-che/theia-plugin-ext /home/theia/node_modules/@eclipse-che/theia-remote
COPY --from=builder /home/workspace/packages/theia-plugin-ext /home/theia/node_modules/@eclipse-che/theia-plugin-ext
COPY --from=builder /home/workspace/packages/theia-remote/lib /home/theia/lib
COPY --from=builder /.passwd.template /.passwd.template
COPY --from=builder /.group.template /.group.template
COPY --from=builder /etc/sudoers /etc/sudoers

RUN mkdir /projects \
# Store passwd/group as template files
&& cat /etc/passwd | sed s#root:x.*#root:x:\${USER_ID}:\${GROUP_ID}::\${HOME}:/bin/sh#g > ${HOME}/passwd.template \
&& cat /etc/group | sed s#root:x:0:#root:x:0:0,\${USER_ID}:#g > ${HOME}/group.template \
# Change permissions to let any arbitrary user
&& for f in "${HOME}" "/etc/passwd" "/etc/group" "/projects"; do \
echo "Changing permissions on ${f}" && chgrp -R 0 ${f} && \
&& sed -i -e 's/theia-dev/theia/g' /.passwd.template /.group.template
&& for f in "${HOME}" /etc/passwd /etc/group /projects; do \
echo "Changing permissions on ${f}" && \
chgrp -R 0 ${f} && \
chmod -R g+rwX ${f}; \
done
ADD etc/entrypoint.sh /entrypoint.sh
Expand Down
21 changes: 12 additions & 9 deletions dockerfiles/theia-endpoint-runtime/etc/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ if ! grep -Fq "${USER_ID}" /etc/passwd; then
# current user is an arbitrary
# user (its uid is not in the
# container /etc/passwd). Let's fix that
cat ${HOME}/passwd.template | \
sed "s/\${USER_ID}/${USER_ID}/g" | \
sed "s/\${GROUP_ID}/${GROUP_ID}/g" | \
sed "s/\${HOME}/\/home\/theia/g" > /etc/passwd
sed -e "s/\${USER_ID}/${USER_ID}/g" \
-e "s/\${GROUP_ID}/${GROUP_ID}/g" \
-e "s/\${HOME}/\/home\/theia/g" \
/.passwd.template > /etc/passwd

cat ${HOME}/group.template | \
sed "s/\${USER_ID}/${USER_ID}/g" | \
sed "s/\${GROUP_ID}/${GROUP_ID}/g" | \
sed "s/\${HOME}/\/home\/theia/g" > /etc/group
sed -e "s/\${USER_ID}/${USER_ID}/g" \
-e "s/\${GROUP_ID}/${GROUP_ID}/g" \
-e "s/\${HOME}/\/home\/theia/g"
/.group.template > /etc/group
fi

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

sudo chown ${USER_ID}:${GROUP_ID} /projects "${HOME}"
fi

# SITTERM / SIGINT
Expand Down

0 comments on commit e9e8144

Please sign in to comment.