Commit Graph

56 Commits

Author SHA1 Message Date
Greg
e95f3c5e86 add -f option with groupadd
Signed-off-by: Greg <werner.greg@gmail.com>
2020-08-20 20:19:39 -04:00
Harry Weppner
2dd822dd6f suppress "id: jovyan: no such user" message during start 2020-07-06 18:14:04 -07:00
Carsten Pohl
0710677ce2 Changed the regular expression in start.sh that reads the /etc/sudoers file and
adds the conda path as a secure path to sudo.

The regular expression expects that the equals sign has no leading and trailing
spaces after the parameter secure_path. Furthermore it expects that the value
is enclosed in double quotes.

This is the case for the sudoers file in debian based distributions, but the
in centos / redhat based distributions this is not the case. The default value
of the secure_path in centos / redhat based distributions has no double quotes
and leading and trailing spaces.

This change adds optional spaces before and after the space, and makes the
double quotes optional.
2020-04-17 16:10:38 +02:00
stevenstetzler
56e54a7320 Fall back on symlink if mv fails 2020-01-19 23:00:24 -08:00
Adrien Delsalle
d66e26cb21 updates on start.sh file
typo correction on env variable: replacing $USER with $NB_USER since $USER is not set
test if group exists before trying to add a new group
2019-08-09 13:20:16 +02:00
Adrien Delsalle
be4674ffdc Modify the way to change user uid/gid
Workaround of a Docker bad handling of sparse files
Fixes #923
2019-08-09 10:53:10 +02:00
Brett Randall
2d9aa71f69 Added logging of CHOWN_HOME_OPTS and CHOWN_EXTRA_OPTS.
Signed-off-by: Brett Randall <javabrett@gmail.com>
2019-03-20 15:10:04 +11:00
Brett Randall
7dc56ab821 Added logging of chown of CHOWN_EXTRA directories.
Signed-off-by: Brett Randall <javabrett@gmail.com>
2019-03-20 15:09:54 +11:00
Brett Randall
475ab49f82 Made variable reference PYTHONPATH safe in case of set -eu.
Signed-off-by: Brett Randall <javabrett@gmail.com>
2019-02-20 14:46:51 +11:00
Peter Parente
a95cb64dfe Merge pull request #791 from rkdarst/run-hooks-loop-bugfix
Fix logging bug in run-hooks (order of logging statement)
2019-01-01 19:08:45 -05:00
Richard Darst
6e104c95b1 Fix logging bug in run-hooks (order of logging statement)
- The "done running loop" log message was inside the loop, causing it
  to appear over and over again, making log quite confusing.
2019-01-01 23:37:23 +02:00
Peter Parente
e2d4d3b40b Set STATUS=0 by default
Addresses code review by @GrahamDumpleton
2018-12-29 18:15:40 -05:00
Peter Parente
9b9c3c7d99 Fix bug where container user is "nayvoj"
whoami &> /dev/null || STATUS=$? && true
causes STATUS to be set to an empty string
when the container starts with option --add-group="root"
resulting in both nayvoj and jovyan having uid=1000
and gid=100. The first match in /etc/password wins
and so the container user ends up being "nayvoj"
accidentally.

Avoid this by checking that whoami STATUS is neither blank nor 0
before adding a new /etc/passwd entry
2018-12-29 15:06:42 -05:00
Đặng Minh Dũng
0329eecec8 fixing inline script problem 2018-11-12 01:45:05 +07:00
Richard Darst
6fa9a4a1f0 Create run-hooks function and switch pre-start hook to that
- This is initial prototype of a more flexible hooks system.
- Add /usr/local/bin/before-notebook.d hooks which is run right before
  the notebook runs.
2018-08-22 01:32:13 +03:00
Richard Darst
a73212ea35 Add a posibliity for a pre-start hook
- The start.sh script does different operations on users, and
  sometimes one may need to do operations *after* that is done (as
  opposed to /usr/local/bin/start-notebook.d/ which is run before).
  This provides that possibility.  (One use case is hooks which must
  be run after the users are set up.)
- To be technically perfect, one might want to use something similar
  to /usr/local/bin/pre-start-notebook.d/.  But let's start with the
  simplest thing possible for now - the expected use of this command
  is only if people use NB_USER, etc in a way that requires small
  follow up commands to be run.
- If notebook is running as root, this allows users to run arbitrary
  commands pre-sudo.  Consider security model.
2018-08-22 01:32:13 +03:00
Richard Darst
fc72be36ad Update group handling: set primary gid, leave suplemental with group users
- If NB_GID is set, it is likely that files created should have NB_GID
  as their gid (if it doesn't matter, then this change is irrelevant.
  If it does matter, the liklihood that 100 matches with what the user
  wants is low).
- When NB_GID is set, create a new group with that gid.  Then, set
  this as the primary gid of the user.  Set the user's supplemental
  gids to NB_GID,100.
2018-08-02 10:27:29 +03:00
Nils Werner
6281d3d89c Change XDG_CACHE_HOME when using NB_USER 2018-07-20 12:18:14 +02:00
Peter Parente
da11c31576 Fix #492: NB_GID adds a supplemental group, leaves primary untouched 2018-06-24 16:10:10 -07:00
Graham Dumpleton
fce599596e Remove writable group file due to issues with being able to give su access when shouldn't be allowed. 2018-06-06 14:21:03 +10:00
Peter Parente
b62c7170c6 Fix some whitespace and quoting 2018-06-02 16:55:29 -04:00
Christian Mesh
e10d80d9cf Add the ability to specify chown arguments for both home and extra
If people have a use case for recursive chowns that's fine.  I think it's dangerous for people to use, but that's tailored to my use case.
2018-05-16 15:45:51 -04:00
Christian Mesh
dee887e6f9 Add CHOWN_EXTRA support
CHOWN_EXTRA is a comma separated list of directories to chown.
2018-05-15 11:13:55 -04:00
Christian Mesh
62360a7eff Don't chown -R a user's home directory
Only the top level permissions are set wrong due to kubernetes not being able to do this automatically.

This hits significant problems when the chown takes more than 30s and the pod fails to start
2018-05-07 14:46:18 -04:00
Chris Ottinger
44d010e929 in start.sh ensure usename jovyan exists before attempting usermod 2018-04-13 15:56:46 +10:00
Chia-liang Kao
632ce8c2d2 Run additional scripts in /usr/local/bin/start-notebook.d/ 2018-03-29 16:26:20 +08:00
Joachim Jablon
3c61b079c2 Chown of home dir needs to be recursive 2018-03-09 19:01:41 +01:00
Graham Dumpleton
c545886d76 Add entries to passwd/group if running as user not in passwd file. 2018-02-20 19:17:55 +11:00
Aaron Vinson
ead1caecfa improve secure_path modification by storing in sudoers.d 2018-02-17 00:15:06 -08:00
Bidek56
d28657d7b9 Added PYTHONPATH to sudo 2018-02-03 16:43:16 -05:00
Christian Mesh
272476e2d7 Gate chown /home/$NB_USER behind $CHOWN_HOME 2018-01-31 09:05:01 -05:00
Christian Mesh
b4d2d6f583 Support provisioned storage with incorrect permissions
I ran into an issue when trying to get this to work with a NFS server which I did not have direct control over (EFS).  As part of the PersistentVolumeClaim, there is no easy way to set the UID and GID of the created directory.on the networked FS.

My only concern with this chown is that some user out there might be running jupyterhub in an odd configuration where $NB_USER is not supposed to have these exact permissions on the storage.  I think this is quite unlikely, but it is worth mentioning. 

I chronicled my experiences with working around this issue and setting up z2jh on EFS in https://github.com/jupyterhub/zero-to-jupyterhub-k8s/issues/421 with @yuvipanda.
2018-01-31 08:51:52 -05:00
Bonnotte, Nicolas
c6c6819a6e Add /bin to sudo secure_path 2018-01-18 17:51:06 +01:00
Peter Parente
6fa67cc500 Append $CONDA_DIR/bin to sudo secure_path
Retain behavior when su was used instead
2018-01-04 00:09:07 -05:00
Peter Parente
c560907ea3 Fix missing env vars (inc. PATH) in some cases
* Refactor to use sudo to become jovyna when the
  container starts as root
* Retain all environment variables when becoming
  jovyan
* Handle start.sh without additional commands when
  launching a container as NB_USER too
2017-12-29 19:22:42 -05:00
Troels Schwarz-Linnet
0766b5f005 This is to fix running SUDO as eihter the jovyan user or root.
Please refer to alias, in bottom of commit.

> dbn
Execute the command: jupyter notebook

> dbn bash
jovyan@eedcc93a837d:~$

> dbn start.sh
Execute the command:
exit

> dbnr
Set username to: jovyan
usermod: no changes
Set jovyan GID to: 100
Execute the command: jupyter notebook
Running as root is not recommended. Use --allow-root to bypass.
exit

> dbnr bash
root@893cb78b8c9c:~#

> dbnr start.sh
Set username to: jovyan
usermod: no changes
Set jovyan GID to: 100
Execute the command:
No arguments supplied
HOSTNAME=d45c52e788b7
TERM=xterm
SHELL=/bin/bash
NB_USER=jovyan
LC_ALL=en_US.UTF-8
PATH=/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
MINICONDA_VERSION=4.3.30
PWD=/home/jovyan
LANG=en_US.UTF-8
HOME=/home/jovyan
SHLVL=2
LANGUAGE=en_US.UTF-8
no_proxy=*.local, 169.254/16
DEBIAN_FRONTEND=noninteractive
CONDA_DIR=/opt/conda
NB_GID=100
NB_UID=1000
root@d45c52e788b7:~#

> dbnrs
Set username to: jovyan
usermod: no changes
Set jovyan GID to: 100
Granting jovyan sudo access
Execute the command: jupyter notebook
Copy/paste this URL into your browser when you connect for the first time, ....

> dbnrs bash
root@f293dce949db:~#

> dbnrs start.sh
Set username to: jovyan
usermod: no changes
Set jovyan GID to: 100
Granting jovyan sudo access
Execute the command:
No arguments supplied
HOSTNAME=d0cd57ea32e2
SHELL=/bin/bash
TERM=xterm
LC_ALL=en_US.UTF-8
USER=jovyan
SUDO_USER=root
SUDO_UID=0
USERNAME=jovyan
MAIL=/var/mail/jovyan
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
PWD=/home/jovyan
LANG=en_US.UTF-8
SHLVL=1
SUDO_COMMAND=/bin/bash -c env; PATH=$PATH; bash
HOME=/home/jovyan
LANGUAGE=en_US.UTF-8
LOGNAME=jovyan
SUDO_GID=0
_=/usr/bin/env
jovyan@d0cd57ea32e2:~$

> dbns
Container must be run as root to grant sudo permissions
Execute the command: jupyter notebook
Copy/paste this URL in..

> dbns bash
jovyan@ce5c2491fa32:~$

> dbns start.sh
Container must be run as root to grant sudo permissions
Execute the command:
exit

###### Build user setup
docker build -t $USER/base-notebook -f Dockerfile .

# Normal, dbn: docker-base-notebook
alias dbn='docker run -ti --rm -p 8888:8888 -v "$PWD":/home/jovyan/work --name base-notebook $USER/base-notebook'
# Root, dbnr: dbn with root
alias dbnr='docker run -ti --rm -p 8888:8888 --user root -v "$PWD":/home/jovyan/work --name base-notebook $USER/base-notebook'
# Jovyan SUDO, dbnr: dbn with SUDO for jovyan
alias dbnrs='docker run -ti --rm -p 8888:8888 --user root -e GRANT_SUDO=yes -v "$PWD":/home/jovyan/work --name base-notebook $USER/base-notebook'
# Root, fail to sudo for jovyan.
alias dbns='docker run -ti --rm -p 8888:8888 -e GRANT_SUDO=yes -v "$PWD":/home/jovyan/work --name base-notebook $USER/base-notebook'
2017-12-29 11:38:53 -05:00
Troels Schwarz-Linnet
412a17b884 Fix for granting SUDO to jovyan user and run bash commands.
Test image builded with:
> docker build -t $USER/base-notebook -f Dockerfile .

> docker run -ti --rm -p 8888:8888 -e GRANT_SUDO=yes --user root jupyter/base-notebook:033056e6d164 bash
root@84db8819258d:~#

docker run -ti --rm -p 8888:8888 -e GRANT_SUDO=yes --user root $USER/base-notebook bash
> root@c23f1fd7d279:~#

> docker run -ti --rm -p 8888:8888 -e GRANT_SUDO=yes --user root jupyter/base-notebook:033056e6d164 start.sh
Set username to: jovyan
usermod: no changes
Set jovyan GID to: 100
Granting jovyan sudo access
Execute the command:
HOSTNAME=a231202e6d1a
TERM=xterm
SHELL=/bin/bash
NB_USER=jovyan
LC_ALL=en_US.UTF-8
USER=jovyan
MAIL=/var/mail/jovyan
PATH=/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MINICONDA_VERSION=4.3.30
PWD=/home/jovyan
LANG=en_US.UTF-8
GRANT_SUDO=yes
HOME=/home/jovyan
SHLVL=1
LANGUAGE=en_US.UTF-8
no_proxy=*.local, 169.254/16
LOGNAME=jovyan
DEBIAN_FRONTEND=noninteractive
CONDA_DIR=/opt/conda
NB_GID=100
NB_UID=1000
_=/usr/bin/env
tlinnet@linmac:base-notebook$

> docker run -ti --rm -p 8888:8888 -e GRANT_SUDO=yes --user root $USER/base-notebook start.sh
Set username to: jovyan
usermod: no changes
Set jovyan GID to: 100
Granting jovyan sudo access
Execute the command:
No arguments supplied
HOSTNAME=364e5fc77224
SHELL=/bin/bash
TERM=xterm
LC_ALL=en_US.UTF-8
USER=jovyan
SUDO_USER=root
SUDO_UID=0
USERNAME=jovyan
MAIL=/var/mail/jovyan
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
PWD=/home/jovyan
LANG=en_US.UTF-8
SHLVL=1
SUDO_COMMAND=/bin/bash -c env; PATH=$PATH; bash
HOME=/home/jovyan
LANGUAGE=en_US.UTF-8
LOGNAME=jovyan
SUDO_GID=0
_=/usr/bin/env
jovyan@364e5fc77224:~$

> docker run -ti --rm -p 8888:8888 -e GRANT_SUDO=yes --user root jupyter/base-notebook:033056e6d164 start.sh echo hello
tlinnet@linmac:base-notebook$ docker run -ti --rm -p 8888:8888 -e GRANT_SUDO=yes --user root jupyter/base-notebook:033056e6d164 start.sh echo hello
Set username to: jovyan
usermod: no changes
Set jovyan GID to: 100
Granting jovyan sudo access
Execute the command: echo hello
hello
tlinnet@linmac:base-notebook$

> docker run -ti --rm -p 8888:8888 -e GRANT_SUDO=yes --user root $USER/base-notebook start.sh echo hello
Set username to: jovyan
usermod: no changes
Set jovyan GID to: 100
Granting jovyan sudo access
Execute the command: echo hello
hello
tlinnet@linmac:base-notebook$
2017-12-29 11:38:53 -05:00
Peter Parente
b9139131da Tests for NB_UID, NB_GID, GRANT_SUDO options
* Improve test container teardown
* Fix needless groupmod when NB_GID is unchanged
2017-11-30 00:15:17 -05:00
Min RK
38710f5819 homedir fixes
- don't relocate home if home exists (e.g. mounted volume)
- respect workdir, only cd to new home if we were in /home/jovyan/
2017-09-07 21:34:42 +02:00
Peter Parente
c138070427 Fix working directory problems with custom NB_USER
Improve start.sh logging along the way
2017-09-04 21:10:15 -04:00
Min RK
c6c1ce4cb0 use groups for managing write-access to files
- any files the user should be able to write should have group `user-permissions` with `g+rwX`
- remove `chown` from start.sh because it is no longer needed
- add `fix-permissions` script for setting the user-writable permissions on a path
- user-permissions group as GID 10000 (is there a reason for it to have a different value?)
- containers can set group with `--group-add user-writable` if they want to run with a different uid/gid
  (without -u root -e NB_UID -e NB_GID, which make this unnecessary)
2017-08-26 09:50:56 -04:00
fouding
75742278ce fix condition-testing syntax bugs 2017-08-16 17:17:09 +08:00
Peter Parente
0c68990e93 Merge pull request #425 from minrk/warn-ignored-config
warn about unused config
2017-08-09 16:39:44 -04:00
Min RK
e91827d358 keep accepting 'yes' for GRANT_SUDO 2017-08-09 10:23:01 +02:00
Min RK
489bc324e2 warn about unused config
if some env vars are set that aren't used,
complain about it so behaviour is a bit less surprising
2017-08-07 16:07:53 +02:00
Anton Akhmerov
599bb5a3e3 update home folder and username on startup
closes #414
2017-08-03 18:08:35 +07:00
Min RK
9e6b4a5345 start.sh: fix check for if we are root
UID env is not set when launching as root, use `id -u` check instead
2017-07-21 14:33:44 +02:00
Peter Parente
19b9d93305 Revert "Fix sudoers.d inclusion on debian img (fix #394)"
This reverts commit 4b3b6697e7.
2017-06-21 07:07:13 -05:00
Peter Parente
df7a34bebe Merge pull request #397 from Stibbons/start_logs_pr
Add logs to start.sh
2017-06-09 22:50:34 -04:00
Gaetan Semet
7dc0fc86ec Add logs to start.sh
Signed-off-by: Gaetan Semet <gaetan@xeberon.net>
2017-06-08 15:13:24 +02:00