From patchwork Fri Aug 25 14:48:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "ashish.is--- via Guix-patches\" via" X-Patchwork-Id: 53220 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 0AE5127BBE9; Fri, 25 Aug 2023 15:50:17 +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=0.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_PASS, URIBL_BLOCKED autolearn=no 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 9066227BBE2 for ; Fri, 25 Aug 2023 15:50:14 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qZY8O-0006bi-Et; Fri, 25 Aug 2023 10:50:00 -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 1qZY8M-0006bY-Ac for guix-patches@gnu.org; Fri, 25 Aug 2023 10:49:58 -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 1qZY8M-0000sv-2b for guix-patches@gnu.org; Fri, 25 Aug 2023 10:49:58 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qZY8Q-00067T-GG for guix-patches@gnu.org; Fri, 25 Aug 2023 10:50:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65538] [PATCH v2] services: greetd: Add pam-gnupg support. Resent-From: Carlos =?utf-8?b?RHVyw6FuIERvbcOtbmd1ZXo=?= Original-Sender: "Debbugs-submit" Resent-CC: , guix-patches@gnu.org Resent-Date: Fri, 25 Aug 2023 14:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65538 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 65538@debbugs.gnu.org Cc: Carlos =?utf-8?b?RHVyw6FuIERvbcOtbmd1ZXo=?= , ( , Christopher Baines , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Raghav Gururajan , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice , jgart X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: ( , Christopher Baines , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Raghav Gururajan , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice , jgart Received: via spool by submit@debbugs.gnu.org id=B.169297495923462 (code B ref -1); Fri, 25 Aug 2023 14:50:02 +0000 Received: (at submit) by debbugs.gnu.org; 25 Aug 2023 14:49:19 +0000 Received: from localhost ([127.0.0.1]:41039 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZY7i-00066L-D1 for submit@debbugs.gnu.org; Fri, 25 Aug 2023 10:49:19 -0400 Received: from lists.gnu.org ([2001:470:142::17]:47544) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZY7e-000667-PH for submit@debbugs.gnu.org; Fri, 25 Aug 2023 10:49:17 -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 1qZY7U-0006WN-OX for guix-patches@gnu.org; Fri, 25 Aug 2023 10:49:04 -0400 Received: from mail.wurtshell.com ([2001:41d0:304:200::95da] helo=wurtshell.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZY7R-0000pf-Dw for guix-patches@gnu.org; Fri, 25 Aug 2023 10:49:04 -0400 Received: from localhost.localdomain (unknown [IPv6:2a0c:5a80:8003:4600:e206:e6ff:fe9a:ab42]) by wurtshell.com (Postfix) with ESMTPSA id 51DD367173; Fri, 25 Aug 2023 14:48:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wurtshell.com; s=mail; t=1692974936; bh=9D0TlmMB/uWlTC1UsxbcRuyAWXb74PG+HchLl55b6f8=; h=From:To:Cc:Subject:Date:From; b=jNVJcDZ0WORHupiG7VQsuGBTVvJaSLJ/i9DJ3P+D+EWkJGut4AZFIMLIeaBa94OAf 5hCTkjIQSGCbEjYIYfVfYUMRGOgveDilz16I2/N92jcnSVBCtMPPYf4VhYTaoNO6wI M8di8Hxr84TZwgpBN2d7RdHWMNWzTHnNJs5XjfoEkFmgqmL4wrU6ZDA1fXv1kgI6ai 1vnukYcXFUPHJznvdVSJLnjYbv61ZqyyUDRTdYVMHlRM5qvNVGi83P4Vk3vZq/nq38 ithdmieYgokOhpCZy/qrqvrqrOuwutCX1EE7REPyvB3s9XFgJg3job0KAXxaVM1q9t nCxDgBxTOe3Dg== Date: Fri, 25 Aug 2023 16:48:03 +0200 Message-ID: <20230825144806.6315-1-wurt@wurtshell.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2001:41d0:304:200::95da; envelope-from=wurt@wurtshell.com; helo=wurtshell.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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: , Reply-to: Carlos =?utf-8?b?RHVyw6FuIERvbcOtbmd1ZXo=?= X-ACL-Warn: , =?utf-8?q?Carlos_Dur=C3=A1n_Dom=C3=ADnguez_via_Guix-patches?= X-Patchwork-Original-From: guix-patches--- via From: "ashish.is--- via Guix-patches\" via" 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 I retry to implement the pam-gnupg module for the greetd system service. It is A PAM module that hands over your login password to gpg-agent. I added de documentation and the insert-before procedure (maybe it needs a better name), to ensure that the pam-gnupg module will be loaded at the end. * doc/guix.texi: documentation about #:gnupg? option on (greetd-configuration). * gnu/services.scm (insert-before): new procedure. * gnu/services/base.scm (greetd-configuration): new option #:gnupg?. * gnu/services/pam-mount.scm: ensure that pam mount module goes before pam gnupg module. * gnu/system/pam.scm (pam-gnupg-module?): new procedure and ensure that pam gnupg module is at the end of (unix-pam-service). --- doc/guix.texi | 9 +++++++++ gnu/services.scm | 11 ++++++++++- gnu/services/base.scm | 28 ++++++++++++++++++---------- gnu/services/pam-mount.scm | 14 +++++++++----- gnu/system/pam.scm | 13 ++++++++++--- 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index e8c67b0cd8..1fe38bd971 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -119,6 +119,7 @@ Copyright @copyright{} 2023 Tanguy Le Carrour@* Copyright @copyright{} 2023 Zheng Junjie@* Copyright @copyright{} 2023 Brian Cully@* Copyright @copyright{} 2023 Felix Lechner@* +Copyright @copyright{} 2023 Carlos Durán Domínguez@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -19666,6 +19667,14 @@ A file-like object containing the ``message of the day''. Allow empty passwords by default so that first-time users can log in when the 'root' account has just been created. +@item @code{gnupg?} (default: @code{#f}) +If enabled, @code{pam-gnupg} will attempt to automatically unlock the +user's GPG keys with the login password via @code{gpg-agent}. The +keygrips of all keys to be unlocked should be written to +@file{~/.pam-gnupg}, and can be queried with @code{gpg -K +--with-keygrip}. Presetting passphrases must be enabled by adding +@code{allow-preset-passphrase} in @file{~/.gnupg/gpg-agent.conf}. + @item @code{terminals} (default: @code{'()}) List of @code{greetd-terminal-configuration} per terminal for which @code{greetd} should be started. diff --git a/gnu/services.scm b/gnu/services.scm index eb9258977e..118b8973ff 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -129,7 +129,8 @@ (define-module (gnu services) %boot-service %activation-service - etc-service) ; deprecated + etc-service ; deprecated + insert-before) #:re-export (;; Note: Re-export 'delete' to allow for proper syntax matching ;; in 'modify-services' forms. See ;; . @@ -1248,4 +1249,12 @@ (define-syntax-rule (for-home exp ...) (syntax-parameterize ((for-home? (identifier-syntax #t))) exp ...)) +(define (insert-before pred lst1 lst2) + "Return a list appending LST2 just before the first element on LST1 that + satisfy the predicate PRED." + (cond + ((null? lst1) lst2) + ((pred (car lst1)) (append lst2 lst1)) + (else (cons (car lst1) (insert-before pred (cdr lst1) lst2))))) + ;;; services.scm ends here. diff --git a/gnu/services/base.scm b/gnu/services/base.scm index b3f2d2e8b8..34aeb4f7d2 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -21,6 +21,7 @@ ;;; Copyright © 2022 Justin Veilleux ;;; Copyright © 2022 ( ;;; Copyright © 2023 Bruno Victal +;;; Copyright © 2023 Carlos Durán Domínguez ;;; ;;; This file is part of GNU Guix. ;;; @@ -3227,6 +3228,7 @@ (define-record-type* greetd-configuration? (motd greetd-motd (default %default-motd)) (allow-empty-passwords? greetd-allow-empty-passwords? (default #t)) + (gnupg? greetd-gnupg? (default #f)) (terminals greetd-terminals (default '())) (greeter-supplementary-groups greetd-greeter-supplementary-groups (default '()))) @@ -3266,25 +3268,31 @@ (define optional-pam-mount (module (file-append greetd-pam-mount "/lib/security/pam_mount.so")) (arguments '("disable_interactive")))) + (define (optional-pam-mount-transformer pam) + (if (member (pam-service-name pam) + '("login" "greetd" "su" "slim" "gdm-password")) + (pam-service + (inherit pam) + ;; SLiM could have pam-gnupg module, and pam-mount must be before it. + (auth (insert-before pam-gnupg-module? + (pam-service-auth pam) + (list optional-pam-mount))) + (session (insert-before pam-gnupg-module? + (pam-service-session pam) + (list optional-pam-mount)))) + pam)) (list (unix-pam-service "greetd" #:login-uid? #t #:allow-empty-passwords? (greetd-allow-empty-passwords? config) + #:gnupg? + (greetd-gnupg? config) #:motd (greetd-motd config)) (pam-extension (transformer - (lambda (pam) - (if (member (pam-service-name pam) - '("login" "greetd" "su" "slim" "gdm-password")) - (pam-service - (inherit pam) - (auth (append (pam-service-auth pam) - (list optional-pam-mount))) - (session (append (pam-service-session pam) - (list optional-pam-mount)))) - pam)))))) + optional-pam-mount-transformer)))) (define (greetd-shepherd-services config) (map diff --git a/gnu/services/pam-mount.scm b/gnu/services/pam-mount.scm index b3a02e82e9..a7470e1fcb 100644 --- a/gnu/services/pam-mount.scm +++ b/gnu/services/pam-mount.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2019 Guillaume Le Vaillant ;;; Copyright © 2023 Brian Cully +;;; Copyright © 2023 Carlos Durán Domínguez ;;; ;;; This file is part of GNU Guix. ;;; @@ -94,7 +95,8 @@ (define (pam-mount-pam-service config) (define optional-pam-mount (pam-entry (control "optional") - (module (file-append pam-mount "/lib/security/pam_mount.so")))) + (module #~(string-append #$pam-mount "/lib/security/pam_mount.so")))) + (list (pam-extension (transformer @@ -103,10 +105,12 @@ (module (file-append pam-mount "/lib/security/pam_mount.so")))) '("login" "greetd" "su" "slim" "gdm-password" "sddm")) (pam-service (inherit pam) - (auth (append (pam-service-auth pam) - (list optional-pam-mount))) - (session (append (pam-service-session pam) - (list optional-pam-mount)))) + (auth (insert-before pam-gnupg-module? + (pam-service-auth pam) + (list optional-pam-mount))) + (session (insert-before pam-gnupg-module? + (pam-service-session pam) + (list optional-pam-mount)))) pam)))))) (define (extend-pam-mount-configuration initial extensions) diff --git a/gnu/system/pam.scm b/gnu/system/pam.scm index a035a92e25..445e45c5ef 100644 --- a/gnu/system/pam.scm +++ b/gnu/system/pam.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013-2017, 2019-2021 Ludovic Courtès ;;; Copyright © 2023 Josselin Poiret +;;; Copyright © 2023 Carlos Durán Domínguez ;;; ;;; This file is part of GNU Guix. ;;; @@ -64,7 +65,9 @@ (define-module (gnu system pam) pam-extension-shepherd-requirements pam-root-service-type - pam-root-service)) + pam-root-service + + pam-gnupg-module?)) ;;; Commentary: ;;; @@ -264,12 +267,12 @@ (module "pam_motd.so") (control "required") (module "pam_loginuid.so"))) '()) + ,env ,unix ,@(if gnupg? (list (pam-entry (control "required") (module (file-append pam-gnupg "/lib/security/pam_gnupg.so")))) - '()) - ,env ,unix)))))) + '()))))))) (define (rootok-pam-service command) "Return a PAM service for COMMAND such that 'root' does not need to @@ -454,4 +457,8 @@ (define* (pam-root-service base #:key (transformers '()) (shepherd-requirements (transformers transformers) (shepherd-requirements shepherd-requirements)))) +(define (pam-gnupg-module? name) + "Return `#t' if NAME is the path to the pam-gnupg module, `#f' otherwise." + (equal? (pam-entry-module name) + (file-append pam-gnupg "/lib/security/pam_gnupg.so")))