From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:700:3204::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id GIDpFJFSoGUaPgEAkFu2QA (envelope-from ) for ; Thu, 11 Jan 2024 21:41:53 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id IB29D5FSoGVSgAEAe85BDQ (envelope-from ) for ; Thu, 11 Jan 2024 21:41:53 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=autistici.org header.s=stigmate header.b=jklp8Kjo; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1705005713; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=mOOk2Rl7z1ZR1MtttF94Yl37JZ7ppTLvHQS+nvfnC40=; b=igBgVAFJADHuo3lJp3kt4vct8K1gcUvPODEl8mbMYTvIjMwTy6aC4f9coiwuy54M0O5oPA vCnmEitCdULNnsMPQnct5lzY2TxegOrw5RsFD5Ldm+ZOT6R0nMaAyrmV6pNKOPTjkWPdVX TYWh+29dkmP7Ys+Jn0DsgfC46ehVJRDdGAwhWzipQLyvaoI2YS8Xc/XTVuXp1d1F6xCod9 Ggpq14vzao9TAtcFVeBtw8nUEE9KTzvR/5OI9kWFZGj5tLCUv/GOZUwRyobS8uNHqp5gmD 6rxo/Mu6LE5EIJqjnaQdyvUttNBFb54rs2W3fAIuQWXm8h4Lw1YHfUP7Bh4dhQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=autistici.org header.s=stigmate header.b=jklp8Kjo; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1705005713; a=rsa-sha256; cv=none; b=a1Z5NEnctheNJfP0dSA4gSTbM1b6PUfxgBWiTJr0nR6tWRNlgOxbLqMlLBFAr7pBX4/4aI bbVydlk3oC6gH1FZJHGFYMqZPc9vrxTVnh8sSyyZsg+Q6Q2ZR/A/abtGhNnok89JfbXLOD lBMiZvz4zbYN6UXadKlzzMkYkm5oiHMQBBNevmA0rSReZO3bkk63P4HcH8/Kz3bEt767is aLfmUuKK97hBdI07tJAWNq7g2e8xSuEWP2UbPWJX0aFYOI+/mFqzZWz1OdSIWCkYdTkgwj GnMDjT6LywQjo4KLT9b56bTbUaQctR95b3VY0mm52X2Mc8QDDeLhug2sH2aq6Q== 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 E795736DC3 for ; Thu, 11 Jan 2024 21:41:52 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rO1re-0004ts-Jc; Thu, 11 Jan 2024 15:41:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rO1rO-0004qB-BZ for guix-patches@gnu.org; Thu, 11 Jan 2024 15:41:08 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rO1rN-0006Cb-7m for guix-patches@gnu.org; Thu, 11 Jan 2024 15:41:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rO1rK-0002lf-Pf for guix-patches@gnu.org; Thu, 11 Jan 2024 15:41:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#67613] [PATCH v2 2/5] gnu: docker: Allow setting host environment variables in oci-container-configuration. Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 11 Jan 2024 20:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67613 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 67613@debbugs.gnu.org Cc: Giacomo Leidi Received: via spool by 67613-submit@debbugs.gnu.org id=B67613.170500561610524 (code B ref 67613); Thu, 11 Jan 2024 20:41:02 +0000 Received: (at 67613) by debbugs.gnu.org; 11 Jan 2024 20:40:16 +0000 Received: from localhost ([127.0.0.1]:34042 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rO1qZ-0002jX-MV for submit@debbugs.gnu.org; Thu, 11 Jan 2024 15:40:16 -0500 Received: from confino.investici.org ([2a11:7980:1::2:0]:54837) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rO1qX-0002j2-4L for 67613@debbugs.gnu.org; Thu, 11 Jan 2024 15:40:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1705005614; bh=mOOk2Rl7z1ZR1MtttF94Yl37JZ7ppTLvHQS+nvfnC40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jklp8KjoINmvUElFMxOgyVt8NLknAkXMIZQkbWAozs2HP8+oy/PIbycg8PDhvacRS 7SOlkjwqNlH8GNemvFaddewxEPxSBWbX0aQZOaM2G74U1pe2lP8VYrelT+deqG3U10 y/JgQlEVXgxC3bgShcfViLo5Ticuh1htXh0wVIvc= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4T9xPV6Z7Bz112y; Thu, 11 Jan 2024 20:40:14 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4T9xPV5kPXz10w5; Thu, 11 Jan 2024 20:40:14 +0000 (UTC) Date: Thu, 11 Jan 2024 21:39:50 +0100 Message-ID: <20240111203954.29335-2-goodoldpaul@autistici.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240111203954.29335-1-goodoldpaul@autistici.org> References: <20240111203954.29335-1-goodoldpaul@autistici.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: , Reply-to: Giacomo Leidi X-ACL-Warn: , Giacomo Leidi via Guix-patches From: Giacomo Leidi via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx12.migadu.com X-Migadu-Queue-Id: E795736DC3 X-Migadu-Spam-Score: -7.31 X-Spam-Score: -7.31 X-TUID: Ukh3zmay6VtP * gnu/services/docker.scm (oci-container-configuration) [host-environment]: New field; (oci-sanitize-host-environment): sanitize it; (oci-container-shepherd-service): use it. Change-Id: I4d54d37736cf09f042a71cb0b6e673abc0948d9c --- gnu/services/docker.scm | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/gnu/services/docker.scm b/gnu/services/docker.scm index b4fd94d1fd..7706b4a29a 100644 --- a/gnu/services/docker.scm +++ b/gnu/services/docker.scm @@ -5,7 +5,7 @@ ;;; Copyright © 2020 Efraim Flashner ;;; Copyright © 2020 Jesse Dowell ;;; Copyright © 2021 Brice Waegeneire -;;; Copyright © 2023 Giacomo Leidi +;;; Copyright © 2023, 2024 Giacomo Leidi ;;; ;;; This file is part of GNU Guix. ;;; @@ -285,6 +285,11 @@ (define (oci-sanitize-mixed-list name value delimiter) name el))))) value)) +(define (oci-sanitize-host-environment value) + ;; Expected spec format: + ;; '(("HOME" . "/home/nobody") "JAVA_HOME=/java") + (oci-sanitize-mixed-list "host-environment" value "=")) + (define (oci-sanitize-environment value) ;; Expected spec format: ;; '(("HOME" . "/home/nobody") "JAVA_HOME=/java") @@ -330,6 +335,24 @@ (define-configuration/no-serialization oci-container-configuration (entrypoint (maybe-string) "Overwrite the default entrypoint (@code{ENTRYPOINT}) of the image.") + (host-environment + (list '()) + "Set environment variables in the host environment where @command{docker run} +is invoked. This is especially useful to pass secrets from the host to the +container without having them on the @command{docker run}'s command line: by +setting the @{MYSQL_PASSWORD} on the host and by passing +@code{--env MYSQL_PASSWORD} through the @code{extra-arguments} field, it is +possible to securely set values in the container environment. This field's +value can be a list of pairs or strings, even mixed: + +@lisp +(list '(\"LANGUAGE\" . \"eo:ca:eu\") + \"JAVA_HOME=/opt/java\") +@end lisp + +Pair members can be strings, gexps or file-like objects. Strings are passed +directly to @code{make-forkexec-constructor}." + (sanitizer oci-sanitize-host-environment)) (environment (list '()) "Set environment variables. This can be a list of pairs or strings, even @@ -450,6 +473,8 @@ (define (guess-name name image) (let* ((docker-command (file-append docker-cli "/bin/docker")) (user (oci-container-configuration-user config)) (group (oci-container-configuration-group config)) + (host-environment + (oci-container-configuration-host-environment config)) (command (oci-container-configuration-command config)) (provision (oci-container-configuration-provision config)) (image (oci-container-configuration-image config)) @@ -471,7 +496,9 @@ (define (guess-name name image) "--name" #$name #$@options #$@extra-arguments #$image #$@command) #:user #$user - #:group #$group)) + #:group #$group + #:environment-variables + (list #$@host-environment))) (stop #~(lambda _ (invoke #$docker-command "rm" "-f" #$name))) -- 2.41.0