summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorReepca Russelstein <reepca@russelstein.xyz>2025-04-18 01:35:31 -0500
committerJohn Kehayias <john.kehayias@protonmail.com>2025-06-24 10:07:57 -0400
commitfb42611b8f27960304db5a1c0d33b8371dcde2a8 (patch)
treee4331b4b340c3304684914044d543ecd0e653fb7 /tests
parentbe8aca065118aa4485c02f991c51bea89034defa (diff)
daemon: Use slirp4netns to provide networking to fixed-output derivations.
Previously, the builder of a fixed-output derivation could communicate with an external process via an abstract Unix-domain socket. In particular, it could send an open file descriptor to the store, granting write access to some of its output files in the store provided the derivation build fails—the fix for CVE-2024-27297 did not address this specific case. It could also send an open file descriptor to a setuid program, which could then be executed using execveat to gain the privileges of the build user. With this change, fixed-output derivations other than “builtin:download” and “builtin:git-download” always run in a separate network namespace and have network access provided by a TAP device backed by slirp4netns, thereby closing the abstract Unix-domain socket channel. * nix/libstore/globals.hh (Settings)[useHostLoopback, slirp4netns]: new fields. * config-daemon.ac (SLIRP4NETNS): new C preprocessor definition. * nix/libstore/globals.cc (Settings::Settings): initialize them to defaults. * nix/nix-daemon/guix-daemon.cc (options): add --isolate-host-loopback option. * doc/guix.texi: document it. * nix/libstore/build.cc (DerivationGoal)[slirp]: New field. (setupTap, setupTapAction, waitForSlirpReadyAction, enableRouteLocalnetAction, prepareSlirpChrootAction, spawnSlirp4netns, haveGlobalIPv6Address, remapIdsTo0Action): New functions. (initializeUserNamespace): allow the guest UID and GID to be specified. (DerivationGoal::killChild): When ‘slirp’ is not -1, call ‘kill’. (DerivationGoal::startBuilder): Unconditionally add CLONE_NEWNET to FLAGS. When ‘fixedOutput’ is true, spawn ‘slirp4netns’. When ‘fixedOutput’ and ‘useChroot’ are true, add setupTapAction, waitForSlirpReadyAction, and enableRouteLocalnetAction to builder setup phases. Create a /etc/resolv.conf for fixed-output derivations that directs them to slirp4netns's dns address. When settings.useHostLoopback is true, supply fixed-output derivations with a /etc/hosts that resolves "localhost" to slirp4netns's address for accessing the host loopback. * nix/libutil/util.cc (keepOnExec, decodeOctalEscaped, sendFD, receiveFD, findProgram): New functions. * nix/libutil/util.hh (keepOnExec, decodeOctalEscaped, sendFD, receiveFD, findProgram): New declarations. * gnu/packages/package-management.scm (guix): add slirp4netns input for linux targets. * tests/derivations.scm (builder-network-isolated?): new variable. ("fixed-output derivation, network access, localhost", "fixed-output derivation, network access, external host"): skip test case if fixed output derivations are isolated from the network. Change-Id: Ia3fea2ab7add56df66800071cf15cdafe7bfab96 Signed-off-by: John Kehayias <john.kehayias@protonmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/derivations.scm17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/derivations.scm b/tests/derivations.scm
index 996e5ac504..077aee0909 100644
--- a/tests/derivations.scm
+++ b/tests/derivations.scm
@@ -25,12 +25,15 @@
#:use-module ((gcrypt hash) #:prefix gcrypt:)
#:use-module (guix base32)
#:use-module ((guix git) #:select (with-repository))
+ #:use-module (guix config)
#:use-module (guix tests)
#:use-module (guix tests git)
#:use-module (guix tests http)
#:use-module ((guix packages) #:select (package-derivation base32))
#:use-module ((guix build utils)
- #:select (executable-file? strip-store-file-name))
+ #:select (executable-file? strip-store-file-name which))
+ #:use-module ((gnu build linux-container)
+ #:select (unprivileged-user-namespace-supported?))
#:use-module ((guix hash) #:select (file-hash*))
#:use-module ((git oid) #:select (oid->string))
#:use-module ((git reference) #:select (reference-name->oid))
@@ -55,6 +58,14 @@
;; Globally disable grafts because they can trigger early builds.
(%graft? #f)
+;; This can happen when someone is running tests without --disable-chroot and
+;; with either slirp4netns or /dev/net/tun unavailable.
+(define builder-network-isolated?
+ (and (target-linux? %system)
+ (unprivileged-user-namespace-supported?)
+ (or (not (which "slirp4netns"))
+ (not (file-exists? "/dev/net/tun")))))
+
(define (bootstrap-binary name)
(let ((bin (search-bootstrap-binary name (%current-system))))
(and %store
@@ -502,6 +513,7 @@
#:hash #vu8(1 2 3))
#f))
+(unless (not builder-network-isolated?) (test-skip 1))
(test-assert "fixed-output derivation, network access, localhost"
;; Test a fixed-output derivation connecting to "localhost".
(let ((text (random-text)))
@@ -534,7 +546,8 @@
get-string-all)
text))))))
-(unless (network-reachable?) (test-skip 1))
+(unless (and (network-reachable?) (not builder-network-isolated?))
+ (test-skip 1))
(test-assert "fixed-output derivation, network access, external host"
;; Test a fixed-output derivation connecting to an external server.
(let* ((drv (build-expression->derivation