From patchwork Wed Apr 9 17:26:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Scherer X-Patchwork-Id: 41506 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 A92D727BC4A; Wed, 9 Apr 2025 18:27:42 +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.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham 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 4000927BC49 for ; Wed, 9 Apr 2025 18:27:40 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u2ZCn-0001J3-EK; Wed, 09 Apr 2025 13:27:18 -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 1u2ZCa-0001IF-95 for guix-patches@gnu.org; Wed, 09 Apr 2025 13:27:06 -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 1u2ZCZ-00088S-8M; Wed, 09 Apr 2025 13:27:04 -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=T0RTWC32aPTxZ72IdASJX40IWx8tXoDAno/OPyl839Q=; b=LJDZbWFxedyLKEeeQWfwcREMBnTwAh/86xTU5qJHdmfWAG2B7gsMevxoWfE0mFCiSmZlT45nPq+yT8JCmO7auQPRj5NGv5DiLNARfGfk3wPQEzEcTpYk3UPmE6A/kUrkwkT6a3vgJ/XsjoYzxJ6bz3sMEENK1kRZL51PFbldhynX4KIagFfWYor2g8Yp5vbMMCRpFC6zHYQEZvv0x9RLSd+UhgQ4NTmeQsgBdjZbilkJDu42e4fw6Vjh6rr+o8yIbH305+9/0u8p/BUNEXILD9R5rV5wa0Q6HoShkXe3rEBlFauTdiDdgwbKK1etSjG9fe4oKtOGaCR7AR6/iojCzw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1u2ZCZ-0004sT-3Z; Wed, 09 Apr 2025 13:27:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77383] [PATCH v3 2/3] 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: Wed, 09 Apr 2025 17:27:03 +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.174421958718660 (code B ref 77383); Wed, 09 Apr 2025 17:27:03 +0000 Received: (at 77383) by debbugs.gnu.org; 9 Apr 2025 17:26:27 +0000 Received: from localhost ([127.0.0.1]:41503 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u2ZBz-0004qp-0I for submit@debbugs.gnu.org; Wed, 09 Apr 2025 13:26:27 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:51326) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1u2ZBw-0004qK-3L for 77383@debbugs.gnu.org; Wed, 09 Apr 2025 13:26:24 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3913b539aabso4393667f8f.2 for <77383@debbugs.gnu.org>; Wed, 09 Apr 2025 10:26:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=burningswell-com.20230601.gappssmtp.com; s=20230601; t=1744219578; x=1744824378; 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=T0RTWC32aPTxZ72IdASJX40IWx8tXoDAno/OPyl839Q=; b=P+7fGmILONTfBGcZELo/QiS4Ycy7wHoXmpl5uko7Ori4q/qOI0XwmmiAInr7TXLd0Y yEKdSUM1ma6TI9BPxay0UWXLs+/s3QU1q1TPj2yO+MUUsj3qOANVmh4m50FJ9EUU1YZL xTBMIhNXCgRvW2/qJgwVtBPV4/CgY4cyXIWx1sWsdyXQ/QxvTemLfsiWFp95dPUCo+H/ cdH99aY9ZTSdJ355ROPFCAge0be+4j9c+kjRG2EMzx6+LZ0GHs9vwO8jTum0atnbWtK4 /ixVqq9//lvL/0nPBP66ITOMsaXX23Z/dM3/kIXMThfQSha6G9G9xp/QVnicVHjG3TEI kstw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744219578; x=1744824378; 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=T0RTWC32aPTxZ72IdASJX40IWx8tXoDAno/OPyl839Q=; b=hSOuYqjPIDEdjYBvkSxI8gIsDS6DG3cUC7xGnNp2DF2x8CSOkYLD+GMK6gPMRjhuzI tf8NCWaCKG8rOk7AuMHmOf33A79RxK875MV983tf6S3foJhukWWvrGnhacmjnzK2FSrZ h203+NDJFm94bIuQhx7A2KeL80JvSAN0/yBOC9C0zKYrBH5xvvpGq+tT3vbjlNkMMNPZ jL5d64x9312P8poqVxI7gH0A/5kFpfgCie+m7U3ywKo7ZNuA0kNVx16mMfPM9EfWpQDI l2yrunAgEjotIel1aa91Lkk4wsu+EOdJGtQNKMVEqMwW28ZsgCH3RcATKi731ifNnMZs 6PQw== X-Gm-Message-State: AOJu0YwtU6bgDWcqIjYcB9rfhmbrYlDaMQwSVzK4ZKENPG+7PygAAdfu mpfoToQs9hxbdBoxA07wIxkLyeCBcYoKFiv43S2h+q3TbU5Ni9NibeWrsV8zxQ7DOK0PTiQlyy3 6AewuPA== X-Gm-Gg: ASbGncuJwX2erPuTUzkrfy8JQF1Wrgs7PwxiDPXHdSIMYe0yyKRmBYq0yiBLa2C3E/M MRJLVPvTPkcLYxpCrX98gR3xINWe8pG4GOTevgc5HQJPmk1RUjPt72xp3JprMYwtOm+TF/0Cr3r 2ZJn2UUvz5Xt08FnEGyVoFVVM3GPdU/TpHyOgbXDDtD74RKmkqNXlkmxi27+S1N832Caf44VhSC l45AfcHlJtkGk8kW5iv+KUNUwP+4qBveCC5ZeZrCp+VTtvnBBQqTSdM4cdQsXd7Wv1IZhP2Sm+q wddFJSObmWGWrxYK6PVeTF6va1MQv1zBhBj21jCEcKbxRwh45ukaERkB8U8= X-Google-Smtp-Source: AGHT+IE9eoh6sDyt1vcxzRcVw7QgQYNr9UxsuNV0QmaLA6R0B5cgPDaPpQ/K47nKxYVs1Xpi6RJLVA== X-Received: by 2002:a05:6000:4308:b0:39d:6f2b:e74d with SMTP id ffacd0b85a97d-39d88564b64mr3156323f8f.39.1744219577662; Wed, 09 Apr 2025 10:26:17 -0700 (PDT) Received: from localhost.localdomain ([2a01:599:107:ea74:97c3:d481:d15d:ea6d]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39d8938b5f7sm2208918f8f.57.2025.04.09.10.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Apr 2025 10:26:17 -0700 (PDT) From: Roman Scherer Date: Wed, 9 Apr 2025 19:26:10 +0200 Message-ID: <140f135aa4f94ad69765f7c2a7b38684342ca382.1744217514.git.roman@burningswell.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <58e6296eb44b3e82e5d6367ae85b681463a38613.1744217514.git.roman@burningswell.com> References: <58e6296eb44b3e82e5d6367ae85b681463a38613.1744217514.git.roman@burningswell.com> 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 | 6 +++++ gnu/services/sound.scm | 51 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index bee80cd4e2..6acbf1ba55 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -27267,12 +27267,18 @@ 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{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..0558d4fce8 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,50 @@ (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.") (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 + (group 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 group user) + (with-imported-modules (source-module-closure '((gnu build activation))) + #~(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 + maximum-gain-reduction speakersafetyd user) (shepherd-service (documentation "Run the speaker safety daemon") (provision '(speakersafetyd)) @@ -306,7 +342,10 @@ (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 + #:supplementary-groups '("audio") + #:user #$user)) (stop #~(make-kill-destructor))))) (define speakersafetyd-service-type @@ -324,7 +363,11 @@ (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