all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: 18994@debbugs.gnu.org, Eelco Dolstra <eelco.dolstra@logicblox.com>
Cc: nix-dev@lists.science.uu.nl
Subject: bug#18994: [PATCH] Preserve supplementary groups of build users
Date: Wed, 01 Jul 2015 11:12:51 +0200	[thread overview]
Message-ID: <87vbe4w8a4.fsf__10253.2928729945$1435742125$gmane$org@gnu.org> (raw)
In-Reply-To: <87ppcxsse0.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sat, 08 Nov 2014 15:01:43 +0100")

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

ludo@gnu.org (Ludovic Courtès) skribis:

> Currently, the build environment made by the daemon does not preserve
> supplementary groups of the build users.
>
> Thus, even though the standalone Guix system sets /dev/kvm 660, owned by
> root:kvm, and adds the build users to the kvm group, build users are
> unable to access it.

The following patch is an attempt to address this bug (see
<http://bugs.gnu.org/18994>) by preserving the supplementary groups of
build users in the build environment.

In practice, I would expect that supplementary groups would contain only
one or two groups: the build users group, and possibly the “kvm” group.

WDYT?

Thanks,
Ludo’.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 2004 bytes --]

diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 85a818b..4644810 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -447,6 +447,7 @@ private:
     string user;
     uid_t uid;
     gid_t gid;
+    std::vector<gid_t> supplementaryGIDs;
 
 public:
     UserLock();
@@ -460,6 +461,7 @@ public:
     string getUser() { return user; }
     uid_t getUID() { return uid; }
     uid_t getGID() { return gid; }
+    std::vector<gid_t> getSupplementaryGIDs() { return supplementaryGIDs; }
 
     bool enabled() { return uid != 0; }
 
@@ -539,6 +541,18 @@ void UserLock::acquire()
                 throw Error(format("the Nix user should not be a member of `%1%'")
                     % settings.buildUsersGroup);
 
+	    /* Get the list of supplementary groups of this build user.  This
+	       is usually either empty or contains a group such as "kvm".  */
+	    supplementaryGIDs.resize(10);
+	    int ngroups = supplementaryGIDs.size();
+	    int err = getgrouplist(pw->pw_name, pw->pw_gid,
+				   &supplementaryGIDs.at(0), &ngroups);
+	    if (err == -1)
+		throw Error(format("failed to get list of supplementary groups for `%1'")
+			    % pw->pw_name);
+
+	    supplementaryGIDs.resize(ngroups);
+
             return;
         }
     }
@@ -2179,8 +2193,11 @@ void DerivationGoal::runChild()
         if (buildUser.enabled()) {
             printMsg(lvlChatty, format("switching to user `%1%'") % buildUser.getUser());
 
-            if (setgroups(0, 0) == -1)
-                throw SysError("cannot clear the set of supplementary groups");
+	    /* Preserve supplementary groups of the build user, to allow
+	       admins to specify groups such as "kvm".  */
+            if (setgroups(buildUser.getSupplementaryGIDs().size(),
+			  &buildUser.getSupplementaryGIDs().at(0)) == -1)
+                throw SysError("cannot set supplementary groups of build user");
 
             if (setgid(buildUser.getGID()) == -1 ||
                 getgid() != buildUser.getGID() ||

  reply	other threads:[~2015-07-01  9:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-08 14:01 bug#18994: Daemon does not preserve supplementary groups of build users Ludovic Courtès
2015-07-01  9:12 ` Ludovic Courtès [this message]
     [not found] ` <87vbe4w8a4.fsf@gnu.org>
2015-07-01 12:59   ` bug#18994: [PATCH] Preserve " Eelco Dolstra
     [not found]   ` <5593E431.70200@logicblox.com>
2015-07-01 14:54     ` Ludovic Courtès

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='87vbe4w8a4.fsf__10253.2928729945$1435742125$gmane$org@gnu.org' \
    --to=ludo@gnu.org \
    --cc=18994@debbugs.gnu.org \
    --cc=eelco.dolstra@logicblox.com \
    --cc=nix-dev@lists.science.uu.nl \
    /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.