From patchwork Sun Mar 26 14:07:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 48708 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 42FC116F60; Sun, 26 Mar 2023 15:08:13 +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.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS 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 6190D16F60 for ; Sun, 26 Mar 2023 15:08:12 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pgR2S-0005wu-V6; Sun, 26 Mar 2023 10:08:04 -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 1pgR2Q-0005wG-TJ for guix-patches@gnu.org; Sun, 26 Mar 2023 10:08:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pgR2Q-0001SS-0R for guix-patches@gnu.org; Sun, 26 Mar 2023 10:08:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pgR2P-0004Y3-JC for guix-patches@gnu.org; Sun, 26 Mar 2023 10:08:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62461] [PATCH 1/3] gnu: home-openssh-configuration: Add field add-keys-to-agent. References: <87bkkfaa2x.fsf@ngraves.fr> In-Reply-To: <87bkkfaa2x.fsf@ngraves.fr> Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 26 Mar 2023 14:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62461 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 62461@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 62461-submit@debbugs.gnu.org id=B62461.167983963217392 (code B ref 62461); Sun, 26 Mar 2023 14:08:01 +0000 Received: (at 62461) by debbugs.gnu.org; 26 Mar 2023 14:07:12 +0000 Received: from localhost ([127.0.0.1]:45613 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pgR1c-0004WS-6i for submit@debbugs.gnu.org; Sun, 26 Mar 2023 10:07:12 -0400 Received: from 4.mo576.mail-out.ovh.net ([46.105.42.102]:35073) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pgR1a-0004WH-1s for 62461@debbugs.gnu.org; Sun, 26 Mar 2023 10:07:11 -0400 Received: from director1.ghost.mail-out.ovh.net (unknown [10.108.4.4]) by mo576.mail-out.ovh.net (Postfix) with ESMTP id D777723E1D for <62461@debbugs.gnu.org>; Sun, 26 Mar 2023 14:07:08 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-ml9bn (unknown [10.110.103.209]) by director1.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 6B48C1FD62; Sun, 26 Mar 2023 14:07:08 +0000 (UTC) Received: from ngraves.fr ([37.59.142.95]) by ghost-submission-6684bf9d7b-ml9bn with ESMTPSA id mqStFoxRIGQmtREAKXspMQ (envelope-from ); Sun, 26 Mar 2023 14:07:08 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-95G001e2e1b5e8-c84e-411c-8e90-70cb9c88def7, 7E234574D634A6AB9E7E21F50CF4BBEA9FF18F38) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 90.45.24.108 Date: Sun, 26 Mar 2023 16:07:04 +0200 Message-Id: <20230326140706.32412-1-ngraves@ngraves.fr> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Ovh-Tracer-Id: 5876071615968895714 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehtddgjeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffogggtgfesthekredtredtjeenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpeetveehffevvdfgtddthedvhfeguefggeffteetueeliedvhffhjeegudehleegheenucfkphepuddvjedrtddrtddruddpfeejrdehledrudegvddrleehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpeeonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeeivdegieduseguvggssghughhsrdhgnhhurdhorhhgpdfovfetjfhoshhtpehmohehjeeipdhmohguvgepshhmthhpohhuth 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: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves 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/home/services/ssh.scm | 44 +++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/gnu/home/services/ssh.scm b/gnu/home/services/ssh.scm index 01917a29cd..4ab2adb292 100644 --- a/gnu/home/services/ssh.scm +++ b/gnu/home/services/ssh.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2022 Ludovic Courtès ;;; Copyright © 2023 Janneke Nieuwenhuizen +;;; Copyright © 2023 Nicolas Graves ;;; ;;; This file is part of GNU Guix. ;;; @@ -39,6 +40,7 @@ (define-module (gnu home services ssh) home-openssh-configuration-authorized-keys home-openssh-configuration-known-hosts home-openssh-configuration-hosts + home-openssh-configuration-add-keys-to-agent home-ssh-agent-configuration openssh-host @@ -185,17 +187,41 @@ (define (openssh-host-name-field? field) (define-record-type* home-openssh-configuration make-home-openssh-configuration home-openssh-configuration? - (authorized-keys home-openssh-configuration-authorized-keys ;list of file-like - (default '())) - (known-hosts home-openssh-configuration-known-hosts ;unspec | list of file-like - (default *unspecified*)) - (hosts home-openssh-configuration-hosts ;list of - (default '()))) + (authorized-keys home-openssh-configuration-authorized-keys ;list of file-like + (default '())) + (known-hosts home-openssh-configuration-known-hosts ;unspec | list of file-like + (default *unspecified*)) + (hosts home-openssh-configuration-hosts ;list of + (default '())) + (add-keys-to-agent home-openssh-configuration-add-keys-to-agent ;string with limited values + (default "no"))) + +(define (serialize-add-keys-to-agent value) + (define (is-valid-time-string? str) + (and (> (string-length str) 0) + (eq? + (cdr (vector-ref + (string-match "\ +[0-9]+|([0-9]+[Ww])?([0-9]+[Dd])?([0-9]+[Hh])?([0-9]+[Mm])?([0-9]+[Ss])?" str) + 1)) + (string-length str)))) + + (string-append "AddKeysToAgent " + (cond ((member value '("yes" "no" "confirm" "ask")) value) + ((is-valid-time-string? value) value) + ((and (string-prefix? "confirm" value) + (is-valid-time-string? + (cdr (string-split value #\ )))) value) + ;; The 'else' branch is unreachable. + (else (raise (condition (&error))))))) (define (openssh-configuration->string config) - (string-join (map serialize-openssh-host - (home-openssh-configuration-hosts config)) - "\n")) + (string-join + (cons* (serialize-add-keys-to-agent + (home-openssh-configuration-add-keys-to-agent config)) + (map serialize-openssh-host + (home-openssh-configuration-hosts config))) + "\n")) (define* (file-join name files #:optional (delimiter " ")) "Return a file in the store called @var{name} that is the concatenation