Using ‘call-with-output-file*’ instead of ‘call-with-output-file’ and ‘chmod’
will prevent secrets from being leaked. See
* guix/build/activation.scm (call-with-output-file*): New procedure.
* doc/guix.texi (Activation): New section; document ‘call-with-output-file*’.
* Moved ‘call-with-output-file*’ from (gnu build utils) to (gnu build
* Added a “Activation” section in the manual to document the new
doc/guix.texi | 31 +++++++++++++++++++++++++++++++
gnu/build/activation.scm | 13 ++++++++++++-
2 files changed, 43 insertions(+), 1 deletion(-)
Toggle diff (105 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 59b4ac11b4..643c7ff126 100644
@@ -321,6 +321,7 @@ System Configuration
* Invoking guix deploy:: Deploying a system configuration to a remote host.
* Running Guix in a VM:: How to run Guix System in a virtual machine.
* Defining Services:: Adding new service definitions.
+* Activation:: Setting up system-wide files and directories.
@@ -13386,6 +13387,7 @@ instance to support new system services.
* Invoking guix deploy:: Deploying a system configuration to a remote host.
* Running Guix in a VM:: How to run Guix System in a virtual machine.
* Defining Services:: Adding new service definitions.
+* Activation:: Setting up system-wide files and directories.
@node Using the Configuration System
@@ -34633,6 +34635,35 @@ system:
This service represents PID@tie{}1.
+@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} @
+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
+(call-with-output-file "FILE"
+ (display "top secret" port)))
+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.
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
;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
+;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;; This file is part of GNU Guix.
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-11)
#:use-module (srfi srfi-26)
+ #:use-module (srfi srfi-60)
#:export (activate-users+groups
+ call-with-output-file*))
@@ -102,6 +105,14 @@ Warning: this is currently suspect to a TOCTTOU race!"
(chown directory (passwd:uid owner) (passwd:gid owner))
+;; Prevent secrets from leaking, see <https://issues.guix.gnu.org/48872>
+(define* (call-with-output-file* file proc #:key (perms #o666))
+ "FILE should be string containg the path to a file, PROC should be a procedure
+that accepts the port as an argument, and PERMS should be the permission bits
+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
(directory %skeleton-directory)
base-commit: 503c2039a280dd52a751a6852b4157fccd1b4195