From: David Thompson <dthompson2@worcester.edu>
To: guix-devel@gnu.org
Subject: [PATCH] environment: container: Create dummy home directory and /etc/passwd.
Date: Fri, 18 Mar 2016 08:41:01 -0400 [thread overview]
Message-ID: <87wpp0hsbm.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> (raw)
[-- 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
next reply other threads:[~2016-03-18 12:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-18 12:41 David Thompson [this message]
2016-03-18 21:16 ` [PATCH] environment: container: Create dummy home directory and /etc/passwd Ludovic Courtès
2016-03-26 13:44 ` Thompson, David
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wpp0hsbm.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me \
--to=dthompson2@worcester.edu \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.