[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] environment: container: Create dummy home directory and /etc/pas
From: |
David Thompson |
Subject: |
[PATCH] environment: container: Create dummy home directory and /etc/passwd. |
Date: |
Fri, 18 Mar 2016 08:41:01 -0400 |
User-agent: |
Notmuch/0.21 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-unknown-linux-gnu) |
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
>From 5985be7a5b3b6a5d5a5d3eb3e95983ad96909f2e Mon Sep 17 00:00:00 2001
From: David Thompson <address@hidden>
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
- [PATCH] environment: container: Create dummy home directory and /etc/passwd.,
David Thompson <=