From patchwork Thu Aug 13 12:34:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Othacehe X-Patchwork-Id: 23605 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 9FF6527BBE5; Thu, 13 Aug 2020 13:35:14 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id E91A827BBE3 for ; Thu, 13 Aug 2020 13:35:13 +0100 (BST) Received: from localhost ([::1]:34440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6CRt-00076V-Bb for patchwork@mira.cbaines.net; Thu, 13 Aug 2020 08:35:13 -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 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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)