From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 8CPGEYEzNV8aRQAA0tVLHw (envelope-from ) for ; Thu, 13 Aug 2020 12:35:13 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 4IeyDYEzNV9jFAAA1q6Kng (envelope-from ) for ; Thu, 13 Aug 2020 12:35:13 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id BDF149400C7 for ; Thu, 13 Aug 2020 12:35:12 +0000 (UTC) Received: from localhost ([::1]:34440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6CRq-00076V-V0 for larch@yhetil.org; Thu, 13 Aug 2020 08:35:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6CRj-00075q-Ek for guix-patches@gnu.org; Thu, 13 Aug 2020 08:35:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:35815) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k6CRj-00046L-4h for guix-patches@gnu.org; Thu, 13 Aug 2020 08:35:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1k6CRj-0000zM-03 for guix-patches@gnu.org; Thu, 13 Aug 2020 08:35:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42849] [PATCH 2/3] linux-container: Add a jail? argument. Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 13 Aug 2020 12:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42849 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42849@debbugs.gnu.org Cc: Mathieu Othacehe Received: via spool by 42849-submit@debbugs.gnu.org id=B42849.15973220833755 (code B ref 42849); Thu, 13 Aug 2020 12:35:02 +0000 Received: (at 42849) by debbugs.gnu.org; 13 Aug 2020 12:34:43 +0000 Received: from localhost ([127.0.0.1]:47358 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k6CRO-0000yT-Me for submit@debbugs.gnu.org; Thu, 13 Aug 2020 08:34:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37066) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k6CRJ-0000xs-7w for 42849@debbugs.gnu.org; Thu, 13 Aug 2020 08:34:39 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:53338) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6CRE-000445-0h for 42849@debbugs.gnu.org; Thu, 13 Aug 2020 08:34:32 -0400 Received: from [2a01:e0a:19b:d9a0:3107:b202:556:bd51] (port=48336 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1k6CRC-0001L2-Ph; Thu, 13 Aug 2020 08:34:31 -0400 From: Mathieu Othacehe Date: Thu, 13 Aug 2020 14:34:18 +0200 Message-Id: <20200813123419.263639-2-othacehe@gnu.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200813123419.263639-1-othacehe@gnu.org> References: <20200813123419.263639-1-othacehe@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 3.99 X-TUID: 7BiKe5JcXcPy We may want to run a container inside the MNT namespace, without jailing the container. Add a "jail?" argument to "run-container" and "call-with-container" methods. * gnu/build/linux-container.scm (run-container): Add a "jail?" argument and honor it, (call-with-container): ditto, and pass the argument to "run-container". --- gnu/build/linux-container.scm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm index 87695c98fd..bb9fb0d799 100644 --- a/gnu/build/linux-container.scm +++ b/gnu/build/linux-container.scm @@ -218,12 +218,13 @@ corresponds to the symbols in NAMESPACES." namespaces))) (define* (run-container root mounts namespaces host-uids thunk - #:key (guest-uid 0) (guest-gid 0)) + #:key (guest-uid 0) (guest-gid 0) (jail? #t)) "Run THUNK in a new container process and return its PID. ROOT specifies the root directory for the container. MOUNTS is a list of objects that specify file systems to mount inside the container. NAMESPACES is a list of symbols that correspond to the possible Linux namespaces: mnt, -ipc, uts, user, and net. +ipc, uts, user, and net. If JAIL? is false, MOUNTS list is ignored and the +container is not jailed. HOST-UIDS specifies the number of host user identifiers to map into the user namespace. GUEST-UID and GUEST-GID specify the first UID (respectively GID) @@ -243,7 +244,7 @@ that host UIDs (respectively GIDs) map to in the namespace." (match (read child) ('ready (purify-environment) - (when (memq 'mnt namespaces) + (when (and jail? (memq 'mnt namespaces)) (catch #t (lambda () (mount-file-systems root mounts @@ -300,13 +301,15 @@ delete it when leaving the dynamic extent of this call." (define* (call-with-container mounts thunk #:key (namespaces %namespaces) (host-uids 1) (guest-uid 0) (guest-gid 0) - (process-spawned-hook (const #t))) + (process-spawned-hook (const #t)) + (jail? #f)) "Run THUNK in a new container process and return its exit status; call PROCESS-SPAWNED-HOOK with the PID of the new process that has been spawned. MOUNTS is a list of objects that specify file systems to mount -inside the container. NAMESPACES is a list of symbols corresponding to -the identifiers for Linux namespaces: mnt, ipc, uts, pid, user, and net. By -default, all namespaces are used. +inside the container. NAMESPACES is a list of symbols corresponding to the +identifiers for Linux namespaces: mnt, ipc, uts, pid, user, and net. By +default, all namespaces are used. If JAIL? is false, the MOUNTS list is +ignored and the container is not jailed. HOST-UIDS is the number of host user identifiers to map into the container's user namespace, if there is one. By default, only a single uid/gid, that of @@ -324,7 +327,8 @@ load path must be adjusted as needed." (lambda (root) (let ((pid (run-container root mounts namespaces host-uids thunk #:guest-uid guest-uid - #:guest-gid guest-gid))) + #:guest-gid guest-gid + #:jail? jail?))) ;; Catch SIGINT and kill the container process. (sigaction SIGINT (lambda (signum) -- 2.28.0