From patchwork Sun Mar 30 12:26:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Scherer X-Patchwork-Id: 41000 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 3696D27BBE9; Sun, 30 Mar 2025 13:28:31 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id BF67D27BBE2 for ; Sun, 30 Mar 2025 13:28:29 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tyrll-0002Hn-5n; Sun, 30 Mar 2025 08:28:05 -0400 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 1tyrlj-0002HS-Ce for guix-patches@gnu.org; Sun, 30 Mar 2025 08:28:03 -0400 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 1tyrli-0008JI-Ai; Sun, 30 Mar 2025 08:28:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=YOZ1Pr+qRQBa9Cmuy2UYdUzVQRyMxN1u0q/KafwPcbU=; b=RLpl80Po/tvPehwQQmhSMLQKrqgVgTa/3HotR4RGgTnK7LFGTrOVDDipsmojyqC76rqf5WlmyJi973rM8YLjh5aMqholvLFtHP1LJOpfqsmLPo7g6c1+Futwir1o0qaFwKtpEvDsi9HY/+rOSehFDKK+3yXKCJsYuRmxD+KsRr5+HusC1r/HY0qcTZUojY7GE14blJ1P57bunRM/l4yDDumuhiFH+bJZ7XBdpM+vrYFfDZ87fNU5Q7B2SKDIwUucx0XDy7TlLyrTPyZHJpTr93XDngEflm2nDr+3wWVYMC1hZijIGvUK9Nc8aSyOvhuYW+GPIMzdR61h/+aUH/e5eg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tyrli-0005XZ-5B; Sun, 30 Mar 2025 08:28:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77383] [PATCH 2/2] gnu: speakersafetyd: Run as unprivileged user. Resent-From: Roman Scherer Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sun, 30 Mar 2025 12:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77383 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77383@debbugs.gnu.org Cc: Roman Scherer , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 77383-submit@debbugs.gnu.org id=B77383.174333763921225 (code B ref 77383); Sun, 30 Mar 2025 12:28:02 +0000 Received: (at 77383) by debbugs.gnu.org; 30 Mar 2025 12:27:19 +0000 Received: from localhost ([127.0.0.1]:35157 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tyrl0-0005WG-CY for submit@debbugs.gnu.org; Sun, 30 Mar 2025 08:27:18 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]:52549) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1tyrkt-0005Vf-K9 for 77383@debbugs.gnu.org; Sun, 30 Mar 2025 08:27:12 -0400 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5e5e8274a74so5797576a12.1 for <77383@debbugs.gnu.org>; Sun, 30 Mar 2025 05:27:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=burningswell-com.20230601.gappssmtp.com; s=20230601; t=1743337625; x=1743942425; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YOZ1Pr+qRQBa9Cmuy2UYdUzVQRyMxN1u0q/KafwPcbU=; b=WOFpER31+iCc2gVHXlgZOqf9j0lVr+H4Ep9AlgUxyjSEBkz1nKfcZX08/jiqsBL28j NuTStWKYktgDVUuCgBbYs38n5uaaCBh/T0b5fn42Cm/kIOm2l+De4jEurpKIPXEe9SEp Vl3b6pk6tOPL7xMjO51M+1A2zSxVh+CdI77p3eE4SyuNzPiZ+gPyRTYlNevLElyA/Hgc 5noMXf9mcjU03qMWfQtqN5ywrgXcJ2nqGS6rA27/wWAVFKS4R+Nbfx1JQaRevA5Z8Hyt R6lzLcfgCO2YKDP+en7+LRrHuz8jLGHN+OeR4ckGmK7z8wGfcRcuyCkrdx73YI8t3SYx g1Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743337625; x=1743942425; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y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5edfdd21affmr4286271a12.28.1743337624700; Sun, 30 Mar 2025 05:27:04 -0700 (PDT) Received: from localhost.localdomain ([2a01:599:107:ea74:97c3:d481:d15d:ea6d]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5edc17b1ffcsm4229334a12.50.2025.03.30.05.27.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Mar 2025 05:27:04 -0700 (PDT) From: Roman Scherer Date: Sun, 30 Mar 2025 14:26:56 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/sound.scm (speakersafetyd): Run as unprivileged user. Change-Id: I870bc7bfd69249da3a9c981f627e751395386bd2 --- doc/guix.texi | 9 +++++++ gnu/services/sound.scm | 57 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index f6d774fd13..9a6084e994 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -27268,12 +27268,21 @@ Sound Services The base directory as a G-expression (@pxref{G-Expressions}) that contains the configuration files of the speaker models. +@item @code{group} (default: @code{"speakersafetyd"}) (type: string) +The group to run the Speaker Safety Daemon as. + +@item @code{log-file} (default: @code{"/var/log/speakersafetyd.log"}) (type: string) +The path to the Speaker Safety Daemon log file. + @item @code{maximum-gain-reduction} (default: @code{7}) (type: integer) Maximum gain reduction before panicking, useful for debugging. @item @code{speakersafetyd} (default: @code{speakersafetyd}) (type: file-like) The Speaker Safety Daemon package to use. +@item @code{user} (default: @code{"speakersafetyd"}) (type: string) +The user to run the Speaker Safety Daemon as. + @end table @end deftp @c %end of fragment diff --git a/gnu/services/sound.scm b/gnu/services/sound.scm index fbaa55c553..ac87551a18 100644 --- a/gnu/services/sound.scm +++ b/gnu/services/sound.scm @@ -29,10 +29,12 @@ (define-module (gnu services sound) #:use-module (gnu system shadow) #:use-module (guix diagnostics) #:use-module (guix gexp) + #:use-module (guix modules) #:use-module (guix packages) #:use-module (guix records) #:use-module (guix store) #:use-module (guix ui) + #:use-module (gnu packages admin) #:use-module (gnu packages audio) #:use-module (gnu packages linux) #:use-module (gnu packages pulseaudio) @@ -288,16 +290,53 @@ (define-configuration/no-serialization speakersafetyd-configuration (file-like (file-append speakersafetyd "/share/speakersafetyd")) "The base directory as a G-expression (@pxref{G-Expressions}) that contains the configuration files of the speaker models.") + (group + (string "speakersafetyd") + "The group to run the Speaker Safety Daemon as.") + (log-file + (string "/var/log/speakersafetyd.log") + "The path to the Speaker Safety Daemon log file.") (maximum-gain-reduction (integer 7) "Maximum gain reduction before panicking, useful for debugging.") (speakersafetyd (file-like speakersafetyd) - "The Speaker Safety Daemon package to use.")) + "The Speaker Safety Daemon package to use.") + (user + (string "speakersafetyd") + "The user to run the Speaker Safety Daemon as.")) + +(define speakersafetyd-accounts + (match-record-lambda + (blackbox-directory configuration-directory group log-file maximum-gain-reduction speakersafetyd user) + (list (user-group + (name group) + (system? #t)) + (user-account + (name user) + (group group) + (system? #t) + (home-directory "/var/empty") + (shell (file-append shadow "/sbin/nologin")) + (supplementary-groups '("audio")))))) + +(define speakersafetyd-activation + (match-record-lambda + (blackbox-directory configuration-directory group log-file maximum-gain-reduction speakersafetyd user) + (with-imported-modules (source-module-closure + '((gnu build activation) + (guix build utils))) + #~(begin + (use-modules (gnu build activation)) + (let ((user (getpwnam #$user))) + (mkdir-p/perms "/run/speakersafetyd" user #o755) + (mkdir-p/perms "/var/lib/speakersafetyd" user #o755) + ;; Blackbox files contain audio recordings and might be sensitive information + (mkdir-p/perms #$blackbox-directory user #o700)))))) (define speakersafetyd-shepherd-service (match-record-lambda - (blackbox-directory configuration-directory maximum-gain-reduction speakersafetyd) + (blackbox-directory configuration-directory group log-file maximum-gain-reduction speakersafetyd user) (shepherd-service (documentation "Run the speaker safety daemon") (provision '(speakersafetyd)) @@ -306,7 +345,11 @@ (define speakersafetyd-shepherd-service (list #$(file-append speakersafetyd "/bin/speakersafetyd") "--config-path" #$configuration-directory "--blackbox-path" #$blackbox-directory - "--max-reduction" (number->string #$maximum-gain-reduction)))) + "--max-reduction" (number->string #$maximum-gain-reduction)) + #:group #$group + #:log-file #$log-file + #:supplementary-groups '("audio") + #:user #$user)) (stop #~(make-kill-destructor))))) (define speakersafetyd-service-type @@ -324,7 +367,13 @@ (define speakersafetyd-service-type (compose list speakersafetyd-configuration-speakersafetyd)) (service-extension profile-service-type - (compose list speakersafetyd-configuration-speakersafetyd)))) + (compose list speakersafetyd-configuration-speakersafetyd)) + (service-extension + account-service-type + speakersafetyd-accounts) + (service-extension + activation-service-type + speakersafetyd-activation))) (default-value (speakersafetyd-configuration)))) ;;; sound.scm ends here