From patchwork Fri Oct 6 00:53:21 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: 54523 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 B817C27BBEA; Fri, 6 Oct 2023 01:55:05 +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=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,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 BC9A627BBE2 for ; Fri, 6 Oct 2023 01:55:01 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qoZ78-00009c-Tl; Thu, 05 Oct 2023 20:54:46 -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 1qoZ76-00009S-Jv for guix-patches@gnu.org; Thu, 05 Oct 2023 20:54:44 -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 1qoZ76-0004TX-BY for guix-patches@gnu.org; Thu, 05 Oct 2023 20:54:44 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qoZ7O-0002Sy-Hp for guix-patches@gnu.org; Thu, 05 Oct 2023 20:55:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65538] [PATCH v3] 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, 06 Oct 2023 00:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65538 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 65538@debbugs.gnu.org Cc: Carlos =?utf-8?b?RHVyw6FuIERvbcOtbmd1ZXo=?= Received: via spool by 65538-submit@debbugs.gnu.org id=B65538.16965536649426 (code B ref 65538); Fri, 06 Oct 2023 00:55:02 +0000 Received: (at 65538) by debbugs.gnu.org; 6 Oct 2023 00:54:24 +0000 Received: from localhost ([127.0.0.1]:48949 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qoZ6l-0002Rx-0v for submit@debbugs.gnu.org; Thu, 05 Oct 2023 20:54:24 -0400 Received: from mail.wurtshell.com ([141.94.77.195]:53084 helo=wurtshell.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qoZ6f-0002Re-PC for 65538@debbugs.gnu.org; Thu, 05 Oct 2023 20:54:21 -0400 Received: from localhost.localdomain (unknown [IPv6:2a0c:5a80:8203:9d00:e206:e6ff:fe9a:ab42]) by wurtshell.com (Postfix) with ESMTPSA id 3081660FB1; Fri, 6 Oct 2023 00:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wurtshell.com; s=mail; t=1696553632; bh=N7a+sLD2x6mOZ9aYmRvjhQvw9Dfcusy1E/YIfsGTZh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sr9R4A3WXOhp27pgmysYoewyIRXWv4Rl1bEmiJy79KiYE+ZK66D1DsOGJjOtZysDa 1g/yiRkWjky6N6g+La+nZ6ejKh9wo2iuFn+qswPAUaomLJVxHNlsTU8wRM08l55Ljn lNbTobha35ynf1XbCi7Z2DkQrBjFxvRJoNNiEBzRBHbScUidJoJip4tEHUAmSRWfnq RUr2w3GKtY0qfOgceBDHDzDHKdPMyRwkEXSNPBAk6o9oOIlXlty2WS0rmdMggXefLb WrUjXd37iDkc2pSdz/SYcCpVplBF0vAzamyibHW16vOVZuNG4sgeCNxowNAUT8ZZYU 7Pe6Pa8//qUhA== Date: Fri, 6 Oct 2023 02:53:21 +0200 Message-ID: <20231006005327.13903-1-wurt@wurtshell.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <65538@debbugs.gnu.org> References: <65538@debbugs.gnu.org> 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: , 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 Hi Ludo, I appreciate your corrections and your kind words. I hope that my changes solve these problems, although I have a few doubts. My main concern is that the new 'pam-gnupg-module?' procedure could be wrong, but I did not find any other solution. I also think that using 'insert-before' in gnu/services/pam-mount.scm could be a problem. If other PAM modules needs to be on certain positions, it could be an “if mess” or maybe not, I do not know much about PAM modules. Thanks, * guix/utils.scm (insert-before): New procedure. It is needed to sort PAM modules. * gnu/system/pam.scm (unix-pam-service): Change pam-gnupg module position. pam-gnupg needs to be the latest loaded module. * gnu/system/pam.scm (pam-gnupg-module?): New procedure. Checks if a uses the library */etc/security/pam_gnupg.so. * gnu/services/pam-mount.scm (pam-mount-pam-service): Modify pam-mount module. pam_mount.so must be loaded before pam_gnupg.so. * gnu/services/base.scm (greetd-configuration): Add gnupg? slot. This slot enable the pam-gnupg PAM module. * doc/guix.texi: Add gnupg? option to greetd service. --- doc/guix.texi | 19 ++++++++++++++++--- gnu/services/base.scm | 29 +++++++++++++++++++---------- gnu/services/pam-mount.scm | 15 +++++++++++---- gnu/system/pam.scm | 15 ++++++++++++--- guix/utils.scm | 24 ++++++++++++++++++++---- 5 files changed, 78 insertions(+), 24 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 8c5697589f..cc63d6d48d 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 @@ -19742,6 +19743,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. @@ -22495,9 +22504,13 @@ Whether to allow logins with empty passwords. 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}. +@file{~/.pam-gnupg} (see +@url{https://github.com/cruegge/pam-gnupg#setup-guide, pam-gnupg setup +guide}), and can be queried with @code{gpg -K --with-keygrip} +(@pxref{Commands to select the type of operation,,,gnupg}). Presetting +passphrases must be enabled by adding @code{allow-preset-passphrase} in +@file{~/.gnupg/gpg-agent.conf} (@pxref{Put a passphrase into the +cache,,,gnupg}). @item @code{auto-login?} (default: @code{#f}) @itemx @code{default-user} (default: @code{""}) diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 98d59fd36d..800ffe9306 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. ;;; @@ -85,6 +86,7 @@ (define-module (gnu services base) #:use-module (guix records) #:use-module (guix modules) #:use-module (guix pki) + #:use-module (guix utils) #:use-module ((guix self) #:select (make-config.scm)) #:use-module (guix diagnostics) #:use-module (guix i18n) @@ -3277,6 +3279,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 '()))) @@ -3316,25 +3319,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..ecd56cd5c3 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. ;;; @@ -24,6 +25,7 @@ (define-module (gnu services pam-mount) #:use-module (gnu system pam) #:use-module (guix gexp) #:use-module (guix records) + #:use-module (guix utils) #:use-module (ice-9 match) #:use-module (srfi srfi-1) #:export (pam-mount-configuration @@ -95,6 +97,7 @@ (define optional-pam-mount (pam-entry (control "optional") (module (file-append pam-mount "/lib/security/pam_mount.so")))) + (list (pam-extension (transformer @@ -102,11 +105,15 @@ (module (file-append pam-mount "/lib/security/pam_mount.so")))) (if (member (pam-service-name pam) '("login" "greetd" "su" "slim" "gdm-password" "sddm")) (pam-service + ;; pam-mount module must be before pam-gnupg, because the later + ;; needs to be at the end (See pam-gnupg README.md) (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..193243a588 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,10 @@ (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." + (let ((module (pam-entry-module name))) + (and (file-append? module) + (equal? (first (file-append-suffix module)) + "/lib/security/pam_gnupg.so")))) diff --git a/guix/utils.scm b/guix/utils.scm index e9af33bdeb..de43945278 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -18,6 +18,7 @@ ;;; Copyright © 2022 Antero Mejr ;;; Copyright © 2023 Philip McGrath ;;; Copyright © 2023 Janneke Nieuwenhuizen +;;; Copyright © 2023 Carlos Durán Domínguez ;;; ;;; This file is part of GNU Guix. ;;; @@ -40,15 +41,15 @@ (define-module (guix utils) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) #:use-module (srfi srfi-71) - #:use-module (rnrs io ports) ;need 'port-position' etc. + #:use-module (rnrs io ports) ;need 'port-position' etc. #:use-module ((rnrs bytevectors) #:select (bytevector-u8-set!)) #:use-module (guix memoization) #:use-module ((guix build utils) #:select (dump-port mkdir-p delete-file-recursively - call-with-temporary-output-file %xz-parallel-args)) + call-with-temporary-output-file %xz-parallel-args)) #:use-module ((guix build syscalls) #:select (mkdtemp! fdatasync)) #:use-module ((guix combinators) #:select (fold2)) - #:use-module (guix diagnostics) ;, &error-location, etc. + #:use-module (guix diagnostics) ;, &error-location, etc. #:use-module (ice-9 format) #:use-module ((ice-9 iconv) #:prefix iconv:) #:use-module (ice-9 match) @@ -57,7 +58,7 @@ (define-module (guix utils) #:use-module (ice-9 vlist) #:autoload (zlib) (make-zlib-input-port make-zlib-output-port) #:use-module (system foreign) - #:re-export ( ;for backwards compatibility + #:re-export ( ;for backwards compatibility location location? location-file @@ -80,6 +81,8 @@ (define-module (guix utils) substitute-keyword-arguments ensure-keyword-arguments + insert-before + %guix-source-root-directory current-source-directory @@ -598,6 +601,19 @@ (define (ensure-keyword-arguments args kw/values) (#f (loop rest kw/values (cons* value kw result)))))))) + +;;; +;;; Lists. +;;; + +(define (insert-before pred lst1 lst2) + "Return a list appending LST2 just before the first element on LST1 that + satisfy the predicate PRED." + (match lst1 + (() lst2) + (((? pred x) . rest) (append lst2 lst1)) + ((first . rest) (cons first (insert-before pred rest lst2))))) + ;;; ;;; System strings.