-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add passwd/group file entries when running images as assigned user ID not in passwd file. #553
Changes from all commits
cb9aeae
fe721bf
0caa751
836c318
4b6de74
02187ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
# Add entries to /etc/passwd and /etc/group if being run as user ID | ||
# other than which the image has specified by the USER statement. | ||
|
||
fix-passwd-entry | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible for this logic to live in the Simply looking to keep the number of separate workflow scripts we need to maintain low. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason for adding it in an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will depend on the Spawner. It is true of KubeSpawner, but isn't true of DockerSpawner in general (deployments may override CMD, but it is not overridden by default). Doing this as an entrypoint makes sense to me. I think the same might be said for much of what's in start.sh, though. Effectively, putting this and only this in entrypoint is saying that the passwd entry is more important than and should be harder to opt-out of than anything in start.sh. That may be right, but I think we should think carefully about this in the future. |
||
|
||
# Run 'tini' as a mini supervisor. This will manage the actual | ||
# application process, passing on signals received by the container, and | ||
# also reaping zombie processes. Must use 'exec' so that it inherits | ||
# process ID 1 of the container. | ||
|
||
exec tini -- "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
# By default the image would run as user ID 1000. If the user is run as | ||
# an arbitrarily assigned user ID by the container platform it will be | ||
# much higher and the lack of entries in /etc/passwd and /etc/group can | ||
# cause failure of any Python code which doesn't tolerate having no | ||
# entries for uid/gid. Assume that if running with larger uid that we | ||
# need to add entries into the respective files for that user. Have the | ||
# check be greater than 100000 to allow room in case custom images | ||
# derived from this image were adding additional explict users/groups of | ||
# their own. | ||
|
||
NB_UID=`id -u` | ||
NB_GID=`id -g` | ||
|
||
if [ $NB_GID -eq 0 -a $NB_UID -ge 100000 ]; then | ||
cat /etc/passwd | sed -e "s/^jovyan:/nayvoj:/" > /tmp/passwd | ||
echo "jovyan:x:$NB_UID:$NB_GID:,,,:/home/jovyan:/bin/bash" >> /tmp/passwd | ||
cat /tmp/passwd > /etc/passwd | ||
rm /tmp/passwd | ||
|
||
id -G | grep -q -w $NB_UID; STATUS=$? | ||
if [ $STATUS -eq 0 ]; then | ||
echo "jovyan:x:$NB_UID:" >> /etc/group | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have similar logic to this in start.sh, and it currently enables:
The start.sh logic requires launching the image as the root user rather than the root group. Effectively, we have a fork of two different behaviors with the same goal - one dedicated for openshift/some kubernetes deployments (this one) and one for most others (in start.sh). They accomplish the same thing in different ways and in different code paths. Perhaps we should reconcile them. It would probably be nice if we could accomplish the existing root-requiring logic in start.sh via root group rather than root user. Would you like to take a stab at that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem still gets back to fact that JupyterHub only runs I can't see that this will change the need to make Even if make |
||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes it trivial for any user to become root in their container:
Now the user can
su root
with the password 'root'I think we need another solution that doesn't grant universal
su root
access.This does only affect putting users into the root group, so not the default case, but it does mean that putting users into the root group is equivalent to letting the users run as root. Is that the intended effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check, but I don't believe that will work in secure environments like Kubernetes/OpenShift where you are blocked from running setuid executables and various related system calls behind the ability to change real user/group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this is restricted in Kubernetes/OpenShift.
This is because secure container environments will drop capabilities.