diff options
| -rw-r--r-- | doc/guix.texi | 13 | ||||
| -rw-r--r-- | guix/scripts/environment.scm | 8 | ||||
| -rw-r--r-- | tests/guix-environment-container.sh | 15 |
3 files changed, 28 insertions, 8 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 616970b5052..616c2ef3053 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -4557,9 +4557,11 @@ Run @var{command} within an isolated container. The current working | |||
| 4557 | directory outside the container is mapped inside the container. | 4557 | directory outside the container is mapped inside the container. |
| 4558 | Additionally, unless overridden with @code{--user}, a dummy home | 4558 | Additionally, unless overridden with @code{--user}, a dummy home |
| 4559 | directory is created that matches the current user's home directory, and | 4559 | directory is created that matches the current user's home directory, and |
| 4560 | @file{/etc/passwd} is configured accordingly. The spawned process runs | 4560 | @file{/etc/passwd} is configured accordingly. |
| 4561 | as the current user outside the container, but has root privileges in | 4561 | |
| 4562 | the context of the container. | 4562 | The spawned process runs as the current user outside the container. Inside |
| 4563 | the container, it has the same UID and GID as the current user, unless | ||
| 4564 | @option{--user} is passed (see below.) | ||
| 4563 | 4565 | ||
| 4564 | @item --network | 4566 | @item --network |
| 4565 | @itemx -N | 4567 | @itemx -N |
| @@ -4587,8 +4589,9 @@ the environment. | |||
| 4587 | @itemx -u @var{user} | 4589 | @itemx -u @var{user} |
| 4588 | For containers, use the username @var{user} in place of the current | 4590 | For containers, use the username @var{user} in place of the current |
| 4589 | user. The generated @file{/etc/passwd} entry within the container will | 4591 | user. The generated @file{/etc/passwd} entry within the container will |
| 4590 | contain the name @var{user}; the home directory will be | 4592 | contain the name @var{user}, the home directory will be |
| 4591 | @file{/home/USER}; and no user GECOS data will be copied. @var{user} | 4593 | @file{/home/@var{user}}, and no user GECOS data will be copied. Furthermore, |
| 4594 | the UID and GID inside the container are 1000. @var{user} | ||
| 4592 | need not exist on the system. | 4595 | need not exist on the system. |
| 4593 | 4596 | ||
| 4594 | Additionally, any shared or exposed path (see @code{--share} and | 4597 | Additionally, any shared or exposed path (see @code{--share} and |
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index c27edc7982d..2d1ba4c9386 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm | |||
| @@ -459,17 +459,19 @@ will be used for the passwd entry. LINK-PROFILE? creates a symbolic link from | |||
| 459 | (return | 459 | (return |
| 460 | (let* ((cwd (getcwd)) | 460 | (let* ((cwd (getcwd)) |
| 461 | (home (getenv "HOME")) | 461 | (home (getenv "HOME")) |
| 462 | (uid (if user 1000 (getuid))) | ||
| 463 | (gid (if user 1000 (getgid))) | ||
| 462 | (passwd (let ((pwd (getpwuid (getuid)))) | 464 | (passwd (let ((pwd (getpwuid (getuid)))) |
| 463 | (password-entry | 465 | (password-entry |
| 464 | (name (or user (passwd:name pwd))) | 466 | (name (or user (passwd:name pwd))) |
| 465 | (real-name (if user | 467 | (real-name (if user |
| 466 | "" | 468 | "" |
| 467 | (passwd:gecos pwd))) | 469 | (passwd:gecos pwd))) |
| 468 | (uid 0) (gid 0) (shell bash) | 470 | (uid uid) (gid gid) (shell bash) |
| 469 | (directory (if user | 471 | (directory (if user |
| 470 | (string-append "/home/" user) | 472 | (string-append "/home/" user) |
| 471 | (passwd:dir pwd)))))) | 473 | (passwd:dir pwd)))))) |
| 472 | (groups (list (group-entry (name "users") (gid 0)) | 474 | (groups (list (group-entry (name "users") (gid gid)) |
| 473 | (group-entry (gid 65534) ;the overflow GID | 475 | (group-entry (gid 65534) ;the overflow GID |
| 474 | (name "overflow")))) | 476 | (name "overflow")))) |
| 475 | (home-dir (password-entry-directory passwd)) | 477 | (home-dir (password-entry-directory passwd)) |
| @@ -541,6 +543,8 @@ will be used for the passwd entry. LINK-PROFILE? creates a symbolic link from | |||
| 541 | ;; A container's environment is already purified, so no need to | 543 | ;; A container's environment is already purified, so no need to |
| 542 | ;; request it be purified again. | 544 | ;; request it be purified again. |
| 543 | (launch-environment command profile manifest #:pure? #f))) | 545 | (launch-environment command profile manifest #:pure? #f))) |
| 546 | #:guest-uid uid | ||
| 547 | #:guest-gid gid | ||
| 544 | #:namespaces (if network? | 548 | #:namespaces (if network? |
| 545 | (delq 'net %namespaces) ; share host network | 549 | (delq 'net %namespaces) ; share host network |
| 546 | %namespaces))))))) | 550 | %namespaces))))))) |
diff --git a/tests/guix-environment-container.sh b/tests/guix-environment-container.sh index f2221af95bb..78507f76c04 100644 --- a/tests/guix-environment-container.sh +++ b/tests/guix-environment-container.sh | |||
| @@ -44,6 +44,19 @@ else | |||
| 44 | test $? = 42 | 44 | test $? = 42 |
| 45 | fi | 45 | fi |
| 46 | 46 | ||
| 47 | # By default, the UID inside the container should be the same as outside. | ||
| 48 | uid="`id -u`" | ||
| 49 | inner_uid="`guix environment -C --ad-hoc --bootstrap guile-bootstrap \ | ||
| 50 | -- guile -c '(display (getuid))'`" | ||
| 51 | test $inner_uid = $uid | ||
| 52 | |||
| 53 | # When '--user' is passed, the UID should be 1000. (Note: Use a separate HOME | ||
| 54 | # so that we don't run into problems when the test directory is under /home.) | ||
| 55 | export tmpdir | ||
| 56 | inner_uid="`HOME=$tmpdir guix environment -C --ad-hoc --bootstrap guile-bootstrap \ | ||
| 57 | --user=gnu-guix -- guile -c '(display (getuid))'`" | ||
| 58 | test $inner_uid = 1000 | ||
| 59 | |||
| 47 | if test "x$USER" = "x"; then USER="`id -un`"; fi | 60 | if test "x$USER" = "x"; then USER="`id -un`"; fi |
| 48 | 61 | ||
| 49 | # Check whether /etc/passwd and /etc/group are valid. | 62 | # Check whether /etc/passwd and /etc/group are valid. |
| @@ -123,7 +136,7 @@ rm $tmpdir/mounts | |||
| 123 | 136 | ||
| 124 | # Test that user can be mocked. | 137 | # Test that user can be mocked. |
| 125 | usertest='(exit (and (string=? (getenv "HOME") "/home/foognu") | 138 | usertest='(exit (and (string=? (getenv "HOME") "/home/foognu") |
| 126 | (string=? (passwd:name (getpwuid 0)) "foognu") | 139 | (string=? (passwd:name (getpwuid 1000)) "foognu") |
| 127 | (file-exists? "/home/foognu/umock")))' | 140 | (file-exists? "/home/foognu/umock")))' |
| 128 | touch "$tmpdir/umock" | 141 | touch "$tmpdir/umock" |
| 129 | HOME="$tmpdir" guix environment --bootstrap --container --user=foognu \ | 142 | HOME="$tmpdir" guix environment --bootstrap --container --user=foognu \ |
