all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] environment: container: Create dummy home directory and /etc/passwd.
@ 2016-03-18 12:41 David Thompson
  2016-03-18 21:16 ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: David Thompson @ 2016-03-18 12:41 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 585 bytes --]

In my recent adventures using 'guix environment --container --network',
I noticed that certain tools *really* want to read user information out
of /etc/passwd, such as 'git clone' over SSH.  I initially hacked around
this by adding code to create a dummy home directory and /etc/passwd in
the Bash script I was running inside the container.  After a little
thought, I came to the conclusion that 'guix environment --container'
should just do this automatically so that the container more closely
resembles a real GNU/Linux system.

WDYT?

Thanks,

-- 
David Thompson
GPG Key: 0FF1D807

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-environment-container-Create-dummy-home-directory-an.patch --]
[-- Type: text/x-patch, Size: 3138 bytes --]

From 5985be7a5b3b6a5d5a5d3eb3e95983ad96909f2e Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Thu, 17 Mar 2016 23:19:25 -0400
Subject: [PATCH] environment: container: Create dummy home directory and
 /etc/passwd.

* guix/scripts/environment.scm (launch-environment/container): Change
$HOME to the current user's home directory instead of
/homeless-shelter.  Create a dummy /etc/passwd with a single entry for
the current user.
---
 guix/scripts/environment.scm | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index b122b4c..ee8f6b1 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -373,6 +373,7 @@ host file systems to mount inside the container."
                              (list (direct-store-path bash) profile))))
     (return
      (let* ((cwd (getcwd))
+            (passwd (getpwuid (getuid)))
             ;; Bind-mount all requisite store items, user-specified mappings,
             ;; /bin/sh, the current working directory, and possibly networking
             ;; configuration files within the container.
@@ -417,16 +418,26 @@ host file systems to mount inside the container."
                       ;; The same variables as in Nix's 'build.cc'.
                       '("TMPDIR" "TEMPDIR" "TMP" "TEMP"))
 
-            ;; From Nix build.cc:
-            ;;
-            ;; Set HOME to a non-existing path to prevent certain
-            ;; programs from using /etc/passwd (or NIS, or whatever)
-            ;; to locate the home directory (for example, wget looks
-            ;; for ~/.wgetrc).  I.e., these tools use /etc/passwd if
-            ;; HOME is not set, but they will just assume that the
-            ;; settings file they are looking for does not exist if
-            ;; HOME is set but points to some non-existing path.
-            (setenv "HOME" "/homeless-shelter")
+            ;; Create a dummy home directory with the same path as on the
+            ;; host.
+            (mkdir-p (passwd:dir passwd))
+            (setenv "HOME" (passwd:dir passwd))
+
+            ;; Create a dummy /etc/passwd to satisfy applications that demand
+            ;; to read it, such as 'git clone' over SSH, a valid use-case when
+            ;; sharing the host's network namespace.
+            (mkdir-p "/etc")
+            (call-with-output-file "/etc/passwd"
+              (lambda (port)
+                (display (string-join (list (passwd:name passwd)
+                                            "x" ; but there is no shadow
+                                            "0" "0" ; user is now root
+                                            (passwd:gecos passwd)
+                                            (passwd:dir passwd)
+                                            bash)
+                                      ":")
+                         port)
+                (newline port)))
 
             ;; For convenience, start in the user's current working
             ;; directory rather than the root directory.
-- 
2.6.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] environment: container: Create dummy home directory and /etc/passwd.
  2016-03-18 12:41 [PATCH] environment: container: Create dummy home directory and /etc/passwd David Thompson
@ 2016-03-18 21:16 ` Ludovic Courtès
  2016-03-26 13:44   ` Thompson, David
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2016-03-18 21:16 UTC (permalink / raw)
  To: David Thompson; +Cc: guix-devel

David Thompson <dthompson2@worcester.edu> skribis:

> In my recent adventures using 'guix environment --container --network',
> I noticed that certain tools *really* want to read user information out
> of /etc/passwd, such as 'git clone' over SSH.  I initially hacked around
> this by adding code to create a dummy home directory and /etc/passwd in
> the Bash script I was running inside the container.  After a little
> thought, I came to the conclusion that 'guix environment --container'
> should just do this automatically so that the container more closely
> resembles a real GNU/Linux system.

Yeah, I grumble when I pass --expose=$HOME/.gdbinit and then notice that
I also have to “export HOME=/home/foo” inside the subshell, for
instance.

> From 5985be7a5b3b6a5d5a5d3eb3e95983ad96909f2e Mon Sep 17 00:00:00 2001
> From: David Thompson <dthompson2@worcester.edu>
> Date: Thu, 17 Mar 2016 23:19:25 -0400
> Subject: [PATCH] environment: container: Create dummy home directory and
>  /etc/passwd.
>
> * guix/scripts/environment.scm (launch-environment/container): Change
> $HOME to the current user's home directory instead of
> /homeless-shelter.  Create a dummy /etc/passwd with a single entry for
> the current user.

[...]

> +            ;; Create a dummy home directory with the same path as on the
> +            ;; host.

s/with the same path/under the same name/  :-)

Perhaps we should add a sentence in the manual about this dummy $HOME?

Otherwise LGTM, thanks!

Ludo’.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] environment: container: Create dummy home directory and /etc/passwd.
  2016-03-18 21:16 ` Ludovic Courtès
@ 2016-03-26 13:44   ` Thompson, David
  0 siblings, 0 replies; 3+ messages in thread
From: Thompson, David @ 2016-03-26 13:44 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

On Fri, Mar 18, 2016 at 5:16 PM, Ludovic Courtès <ludo@gnu.org> wrote:
> David Thompson <dthompson2@worcester.edu> skribis:
>
>> In my recent adventures using 'guix environment --container --network',
>> I noticed that certain tools *really* want to read user information out
>> of /etc/passwd, such as 'git clone' over SSH.  I initially hacked around
>> this by adding code to create a dummy home directory and /etc/passwd in
>> the Bash script I was running inside the container.  After a little
>> thought, I came to the conclusion that 'guix environment --container'
>> should just do this automatically so that the container more closely
>> resembles a real GNU/Linux system.
>
> Yeah, I grumble when I pass --expose=$HOME/.gdbinit and then notice that
> I also have to “export HOME=/home/foo” inside the subshell, for
> instance.
>
>> From 5985be7a5b3b6a5d5a5d3eb3e95983ad96909f2e Mon Sep 17 00:00:00 2001
>> From: David Thompson <dthompson2@worcester.edu>
>> Date: Thu, 17 Mar 2016 23:19:25 -0400
>> Subject: [PATCH] environment: container: Create dummy home directory and
>>  /etc/passwd.
>>
>> * guix/scripts/environment.scm (launch-environment/container): Change
>> $HOME to the current user's home directory instead of
>> /homeless-shelter.  Create a dummy /etc/passwd with a single entry for
>> the current user.
>
> [...]
>
>> +            ;; Create a dummy home directory with the same path as on the
>> +            ;; host.
>
> s/with the same path/under the same name/  :-)
>
> Perhaps we should add a sentence in the manual about this dummy $HOME?

Done and pushed.  Thanks!

- Dave

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-26 13:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-18 12:41 [PATCH] environment: container: Create dummy home directory and /etc/passwd David Thompson
2016-03-18 21:16 ` Ludovic Courtès
2016-03-26 13:44   ` Thompson, David

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.