From: Xinglu Chen <public@yoctocell.xyz>
To: 48923@debbugs.gnu.org
Cc: Maxime Devos <maximedevos@telenet.be>
Subject: [bug#48923] [PATCH v2] activation: Add ‘call-with-output-file*’ procedure.
Date: Tue, 08 Jun 2021 20:30:13 +0200 [thread overview]
Message-ID: <7500e1ba2d55d397d4c105ca189746f78de02d35.1623176839.git.public@yoctocell.xyz> (raw)
In-Reply-To: <23ac66d29119c5395fee0e993ea0fe811beefd91.1623166798.git.public@yoctocell.xyz>
Using ‘call-with-output-file*’ instead of ‘call-with-output-file’ and ‘chmod’
will prevent secrets from being leaked. See
<https://issues.guix.gnu.org/48872>.
* guix/build/activation.scm (call-with-output-file*): New procedure.
* doc/guix.texi (Activation): New section; document ‘call-with-output-file*’.
---
Changes since v1:
* Moved ‘call-with-output-file*’ from (gnu build utils) to (gnu build
activation).
* Added a “Activation” section in the manual to document the 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 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.
Services
@@ -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.
@end menu
@node Using the Configuration System
@@ -34633,6 +34635,35 @@ system:
This service represents PID@tie{}1.
@end defvr
+@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
+
@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 © 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.
;;;
@@ -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*))
;;; 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))
+;; 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
#:key
(directory %skeleton-directory)
base-commit: 503c2039a280dd52a751a6852b4157fccd1b4195
--
2.32.0
next prev parent reply other threads:[~2021-06-08 18:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-08 15:40 [bug#48923] [PATCH] build: utils: Add ‘call-with-outp Xinglu Chen
2021-06-08 16:04 ` Maxime Devos
2021-06-08 17:36 ` Xinglu Chen
2021-06-08 17:45 ` Maxime Devos
2021-06-08 18:04 ` Xinglu Chen
2021-06-08 18:30 ` Xinglu Chen [this message]
2021-08-04 8:25 ` [bug#48923] [PATCH v2] activation: Add ‘call-with-output-file*’ procedure Xinglu Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7500e1ba2d55d397d4c105ca189746f78de02d35.1623176839.git.public@yoctocell.xyz \
--to=public@yoctocell.xyz \
--cc=48923@debbugs.gnu.org \
--cc=maximedevos@telenet.be \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).