From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id qPyNO223v2CEWQEAgWs5BA (envelope-from ) for ; Tue, 08 Jun 2021 20:31:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id WAHeNm23v2CjDQAAbx9fmQ (envelope-from ) for ; Tue, 08 Jun 2021 18:31:09 +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 21EE81EA6C for ; Tue, 8 Jun 2021 20:31:09 +0200 (CEST) Received: from localhost ([::1]:37130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqgVI-00037H-2a for larch@yhetil.org; Tue, 08 Jun 2021 14:31:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqgVD-00033f-6W for guix-patches@gnu.org; Tue, 08 Jun 2021 14:31:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:48237) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqgVC-0002gh-OI for guix-patches@gnu.org; Tue, 08 Jun 2021 14:31:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lqgVC-0002s0-MF for guix-patches@gnu.org; Tue, 08 Jun 2021 14:31:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48923] [PATCH v2] activation: Add =?UTF-8?Q?=E2=80=98call-with-output-file*=E2=80=99?= procedure. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 08 Jun 2021 18:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48923 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48923@debbugs.gnu.org Cc: Maxime Devos Received: via spool by 48923-submit@debbugs.gnu.org id=B48923.162317702710969 (code B ref 48923); Tue, 08 Jun 2021 18:31:02 +0000 Received: (at 48923) by debbugs.gnu.org; 8 Jun 2021 18:30:27 +0000 Received: from localhost ([127.0.0.1]:59781 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lqgUc-0002qq-NP for submit@debbugs.gnu.org; Tue, 08 Jun 2021 14:30:27 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:37574 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lqgUY-0002qY-Bb for 48923@debbugs.gnu.org; Tue, 08 Jun 2021 14:30:25 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1623177014; bh=915n3rghIFKNR72xC75ghfOJjwcE+tnDEMvdJxYZvNk=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=QCWscX/i4wUnCfgCt62AARjsM84PrAXemOJonkG+/fYvoHOxqe4DVc8BnpFACsJm3 1Fay8hISSKJjt1po3ZocpdQZDzxden19HiTneBpx9/C5+tr+9aJXeILX/m7+KlV7Z9 DtkCsL79/+QObsEh7BtQijZap6AxYBckSmFM4zKY= In-Reply-To: <23ac66d29119c5395fee0e993ea0fe811beefd91.1623166798.git.public@yoctocell.xyz> References: <23ac66d29119c5395fee0e993ea0fe811beefd91.1623166798.git.public@yoctocell.xyz> Message-Id: <7500e1ba2d55d397d4c105ca189746f78de02d35.1623176839.git.public@yoctocell.xyz> Date: Tue, 08 Jun 2021 20:30:13 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1623177069; h=from:from:sender:sender: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=2SbYVrPt/Ojva3NQM9BSP/FUl8cLdRDfWg9rZIQw22o=; b=PVj51Jqnrb74ueQvtw4TaXqNo3wNlg1SsLO0CVZXJzoLOgzNIgDeMlfErMTd0gtX831uL8 IWDdACJ82WIArlFDiKeOLxF36N479nVsfZ1Q3bfOhXu3lfZzoE+ofcgtsvmN37uc8oSoDa lbOl3FjcwdgGc47vye8xbOVEjEFYlLx+nQgm4qvGFpZFPwDf0g561fobtnC/MkxQn2/xmN 7mImK8hAWToPhTU3dcwndIzHO9nu4AUkCbypjum0b0CJshjB0QsXBE1sLrZQ8qYoQNMlVl dW/cqt542pBQVILF7Arb9Dh65R7Km+P+wEF+28+5FHblq9ufuAXWFYRT+vgUqA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1623177069; a=rsa-sha256; cv=none; b=oi/wIAHym5uzb2/qG6/5p3IqIZY9fiacZLDDL7iH3taVj+S6L4Icy1PuupXJrycwzBGVdw AYJ6+YVSfsBt7eI+vRCmRxlrD8cumBHNV939nF95taY40x/GSN8dZVxQyu+a2I0q+Toags T+sdfy2Nn3YToLwMkBXhWN+OOkkILBZSuCs08vQ3Zzkb6L/HHQER7BIsxPXXwP9tT/BHGr 8oEDJ9XoT6cNnaqpU5BiR+OV/rY0DqXgpwtJYta/P6ttO+7iGvEehckEzqle6ZglCdKhVk cyf/yTtLX9BHCtyB5jp6jZ4obhtkXPHs1YI+oSrT3UmXhD0+mKrDvvtRlopqbw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b="QCWscX/i"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=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-Migadu-Spam-Score: -0.32 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b="QCWscX/i"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=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-Migadu-Queue-Id: 21EE81EA6C X-Spam-Score: -0.32 X-Migadu-Scanner: scn0.migadu.com X-TUID: jTWpraFlFIe6 Using =E2=80=98call-with-output-file*=E2=80=99 instead of =E2=80=98call-wit= h-output-file=E2=80=99 and =E2=80=98chmod=E2=80=99 will prevent secrets from being leaked. See . * guix/build/activation.scm (call-with-output-file*): New procedure. * doc/guix.texi (Activation): New section; document =E2=80=98call-with-outp= ut-file*=E2=80=99. --- Changes since v1: * Moved =E2=80=98call-with-output-file*=E2=80=99 from (gnu build utils) to = (gnu build activation). * Added a =E2=80=9CActivation=E2=80=9D section in the manual to document th= e new procedure. doc/guix.texi | 31 +++++++++++++++++++++++++++++++ gnu/build/activation.scm | 13 ++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 59b4ac11b4..643c7ff126 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -321,6 +321,7 @@ System Configuration * Invoking guix deploy:: Deploying a system configuration to a remo= te host. * Running Guix in a VM:: How to run Guix System in a virtual machin= e. * Defining Services:: Adding new service definitions. +* Activation:: Setting up system-wide files and directori= es. =20 Services =20 @@ -13386,6 +13387,7 @@ instance to support new system services. * Invoking guix deploy:: Deploying a system configuration to a remo= te host. * Running Guix in a VM:: How to run Guix System in a virtual machin= e. * Defining Services:: Adding new service definitions. +* Activation:: Setting up system-wide files and directori= es. @end menu =20 @node Using the Configuration System @@ -34633,6 +34635,35 @@ system: This service represents PID@tie{}1. @end defvr =20 +@node Activation +@section Activation + +@dfn{Activation} is the process that sets up system-wide files and +directories so that an @code{operating-system} (@pxref{operating-system +Reference}) configuration becomes active. This will happen when +invoking commands like @command{guix system reconfigure} or +@command{guix system switch-generation}, but not when invoking +@command{guix system build} (@pxref{Invoking guix system}). + +@deffn {Scheme Procedure} call-with-output-file* @var{file} @var{proc} @ + [#:perms #o666] +Open FILE for output, set the file permission bits to @var{perms}, and +call @code{(PROC port)} with the resulting port. + +The advantage of using this procedure compared to something like this + +@lisp +(call-with-output-file "FILE" + (lambda (port) + (display "top secret" port))) +(chmod "FILE" #o400) +@end lisp + +is that, with the latter, an unpriviliged user could open @var{file} +before the permission was changed to @code{#o400}, thus making it +possible to leak sensitive information. +@end deffn + =20 @node Documentation @chapter Documentation diff --git a/gnu/build/activation.scm b/gnu/build/activation.scm index 2af1d44b5f..0054079cb6 100644 --- a/gnu/build/activation.scm +++ b/gnu/build/activation.scm @@ -6,6 +6,7 @@ ;;; Copyright =C2=A9 2018 Arun Isaac ;;; Copyright =C2=A9 2018, 2019 Ricardo Wurmus ;;; Copyright =C2=A9 2021 Maxime Devos +;;; Copyright =C2=A9 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -34,6 +35,7 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-60) #:export (activate-users+groups activate-user-home activate-etc @@ -43,7 +45,8 @@ activate-firmware activate-ptrace-attach activate-current-system - mkdir-p/perms)) + mkdir-p/perms + call-with-output-file*)) =20 ;;; Commentary: ;;; @@ -102,6 +105,14 @@ Warning: this is currently suspect to a TOCTTOU race!" (chown directory (passwd:uid owner) (passwd:gid owner)) (chmod directory bits)) =20 +;; Prevent secrets from leaking, see +(define* (call-with-output-file* file proc #:key (perms #o666)) + "FILE should be string containg the path to a file, PROC should be a pro= cedure +that accepts the port as an argument, and PERMS should be the permission b= its +of the file, the default is 666." + (let ((port (open file (bitwise-ior O_WRONLY O_CREAT) perms))) + (call-with-port port proc))) + (define* (copy-account-skeletons home #:key (directory %skeleton-directory) base-commit: 503c2039a280dd52a751a6852b4157fccd1b4195 --=20 2.32.0