Skip to content

Commit

Permalink
nix run: Set a reasonable uid/gid
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Jun 2, 2016
1 parent d64e0c1 commit f8a8b4d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/nix/run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ struct CmdRun : StoreCommand, MixInstallables

if (store2 && store->storeDir != store2->realStoreDir) {
#if __linux__
uid_t uid = getuid();
uid_t gid = getgid();

if (unshare(CLONE_NEWUSER | CLONE_NEWNS) == -1)
throw SysError("setting up a private mount namespace");

Expand Down Expand Up @@ -91,6 +94,10 @@ struct CmdRun : StoreCommand, MixInstallables
} else
if (mount(store2->realStoreDir.c_str(), store->storeDir.c_str(), "", MS_BIND, 0) == -1)
throw SysError(format("mounting ‘%s’ on ‘%s’") % store2->realStoreDir % store->storeDir);

writeFile("/proc/self/setgroups", "deny");
writeFile("/proc/self/uid_map", (format("%d %d %d") % uid % uid % 1).str());
writeFile("/proc/self/gid_map", (format("%d %d %d") % gid % gid % 1).str());
#else
throw Error(format("mounting the Nix store on ‘%s’ is not supported on this platform") % store->storeDir);
#endif
Expand Down

0 comments on commit f8a8b4d

Please sign in to comment.