Skip to content

Commit

Permalink
Darwin sandbox: allow accessing entire Nix store
Browse files Browse the repository at this point in the history
Relaxes the sandbox profile on Darwin to allow access to the entire Nix
store instead of granting access to each (transitive) input dependency.

This approach is less hermetic and less restrictive (i.e., secure) but
prevents the following error without disabling sandboxing altogether:

```
sandbox-exec: pattern serialization length 67402 exceeds maximum (65535)
```
  • Loading branch information
Trundle committed Oct 20, 2024
1 parent 411ec33 commit e8b6626
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/libstore/unix/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2118,13 +2118,21 @@ void LocalDerivationGoal::runChild()
continue;
throw SysError("getting attributes of required path '%s", path);
}
if (S_ISDIR(optSt->st_mode))
sandboxProfile += fmt("\t(subpath \"%s\")\n", path);
else
sandboxProfile += fmt("\t(literal \"%s\")\n", path);
/* Allow paths which are not below the Nix store directory */
if (!path.starts_with(worker.store.storeDir)) {
if (S_ISDIR(optSt->st_mode))
sandboxProfile += fmt("\t(subpath \"%s\")\n", path);
else
sandboxProfile += fmt("\t(literal \"%s\")\n", path);
}
}
sandboxProfile += ")\n";

/* Allow accessing any path below the Nix store directory */
sandboxProfile += "(allow file-read* file-write* process-exec\n";
sandboxProfile += fmt("\t(regex #\"^%s/.*\")\n", worker.store.storeDir);
sandboxProfile += ")\n";

/* Allow file-read* on full directory hierarchy to self. Allows realpath() */
sandboxProfile += "(allow file-read*\n";
for (auto & i : ancestry) {
Expand Down

0 comments on commit e8b6626

Please sign in to comment.