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
Kacper Kowalik (Xarthisius) 2019-06-28 11:46:01 -05:00
rodzic 2cded9b4ec
commit f80fb4b39b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 5D21B852895192F9
3 zmienionych plików z 17 dodań i 13 usunięć

Wyświetl plik

@ -303,6 +303,16 @@ def make_r2d(argv=None):
r2d.user_id = args.user_id
if 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 the string only contains numerals we assume it should be an int

Wyświetl plik

@ -7,7 +7,6 @@ Usage:
python -m repo2docker https://github.com/you/your-repo
"""
import errno
import json
import sys
import logging
@ -670,17 +669,9 @@ class Repo2Docker(Application):
if not self.dry_run:
if self.user_id == 0:
self.log.error(
"Root as the primary user in the image is not permitted.\n"
raise ValueError(
"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 = {
"NB_USER": self.user_name,

Wyświetl plik

@ -110,10 +110,13 @@ def test_root_not_allowed():
with TemporaryDirectory() as src, patch("os.geteuid") as geteuid:
geteuid.return_value = 0
argv = [src]
app = make_r2d(argv)
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()
assert exc.code == errno.EPERM
app = Repo2Docker(repo=src, user_id=1000, user_name="jovyan", run=False)
app.initialize()