kopia lustrzana https://github.com/jupyterhub/repo2docker
Handle root user case more gracefully. Fixes #696
If user_id is root, exit only from cmdline. Raise exception if r2d was invoked as a library.pull/723/head
rodzic
2cded9b4ec
commit
f80fb4b39b
|
@ -303,6 +303,16 @@ def make_r2d(argv=None):
|
||||||
r2d.user_id = args.user_id
|
r2d.user_id = args.user_id
|
||||||
if args.user_name:
|
if args.user_name:
|
||||||
r2d.user_name = args.user_name
|
r2d.user_name = args.user_name
|
||||||
|
if r2d.user_id == 0 and not r2d.dry_run:
|
||||||
|
print("Root as the primary user in the image is not permitted.")
|
||||||
|
print(
|
||||||
|
"The uid and the username of the user invoking repo2docker "
|
||||||
|
"is used to create a mirror account in the image by default. "
|
||||||
|
"To override that behavior pass --user-id <numeric_id> and "
|
||||||
|
" --user-name <string> to repo2docker.\n"
|
||||||
|
"Please see repo2docker --help for more details.\n"
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if args.build_memory_limit:
|
if args.build_memory_limit:
|
||||||
# if the string only contains numerals we assume it should be an int
|
# if the string only contains numerals we assume it should be an int
|
||||||
|
|
|
@ -7,7 +7,6 @@ Usage:
|
||||||
|
|
||||||
python -m repo2docker https://github.com/you/your-repo
|
python -m repo2docker https://github.com/you/your-repo
|
||||||
"""
|
"""
|
||||||
import errno
|
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
@ -670,17 +669,9 @@ class Repo2Docker(Application):
|
||||||
|
|
||||||
if not self.dry_run:
|
if not self.dry_run:
|
||||||
if self.user_id == 0:
|
if self.user_id == 0:
|
||||||
self.log.error(
|
raise ValueError(
|
||||||
"Root as the primary user in the image is not permitted.\n"
|
"Root as the primary user in the image is not permitted."
|
||||||
)
|
)
|
||||||
self.log.info(
|
|
||||||
"The uid and the username of the user invoking repo2docker "
|
|
||||||
"is used to create a mirror account in the image by default. "
|
|
||||||
"To override that behavior pass --user-id <numeric_id> and "
|
|
||||||
" --user-name <string> to repo2docker.\n"
|
|
||||||
"Please see repo2docker --help for more details.\n"
|
|
||||||
)
|
|
||||||
sys.exit(errno.EPERM)
|
|
||||||
|
|
||||||
build_args = {
|
build_args = {
|
||||||
"NB_USER": self.user_name,
|
"NB_USER": self.user_name,
|
||||||
|
|
|
@ -110,10 +110,13 @@ def test_root_not_allowed():
|
||||||
with TemporaryDirectory() as src, patch("os.geteuid") as geteuid:
|
with TemporaryDirectory() as src, patch("os.geteuid") as geteuid:
|
||||||
geteuid.return_value = 0
|
geteuid.return_value = 0
|
||||||
argv = [src]
|
argv = [src]
|
||||||
app = make_r2d(argv)
|
|
||||||
with pytest.raises(SystemExit) as exc:
|
with pytest.raises(SystemExit) as exc:
|
||||||
|
app = make_r2d(argv)
|
||||||
|
assert exc.code == 1
|
||||||
|
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
app = Repo2Docker(repo=src, run=False)
|
||||||
app.build()
|
app.build()
|
||||||
assert exc.code == errno.EPERM
|
|
||||||
|
|
||||||
app = Repo2Docker(repo=src, user_id=1000, user_name="jovyan", run=False)
|
app = Repo2Docker(repo=src, user_id=1000, user_name="jovyan", run=False)
|
||||||
app.initialize()
|
app.initialize()
|
||||||
|
|
Ładowanie…
Reference in New Issue