From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id CDwZNGn4QGRS9QAASxT56A (envelope-from ) for ; Thu, 20 Apr 2023 10:31:37 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id sCUtNGn4QGSKkwAA9RJhRA (envelope-from ) for ; Thu, 20 Apr 2023 10:31:37 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6A280EFF8 for ; Thu, 20 Apr 2023 10:31:37 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppPh3-00042D-7i; Thu, 20 Apr 2023 04:31: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 1ppPh1-0003zL-Mg for guix-patches@gnu.org; Thu, 20 Apr 2023 04:31:03 -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 1ppPh1-0008HY-8c for guix-patches@gnu.org; Thu, 20 Apr 2023 04:31:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ppPh0-00020t-TL for guix-patches@gnu.org; Thu, 20 Apr 2023 04:31:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62461] [PATCH v2 2/4] gnu: openssh-host: Add option match-criteria. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 20 Apr 2023 08:31:02 +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: patch To: 62461@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 62461-submit@debbugs.gnu.org id=B62461.16819794247650 (code B ref 62461); Thu, 20 Apr 2023 08:31:02 +0000 Received: (at 62461) by debbugs.gnu.org; 20 Apr 2023 08:30:24 +0000 Received: from localhost ([127.0.0.1]:36473 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ppPgN-0001zE-JX for submit@debbugs.gnu.org; Thu, 20 Apr 2023 04:30:24 -0400 Received: from 13.mo584.mail-out.ovh.net ([178.33.251.8]:36009) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ppPgK-0001yv-Ny for 62461@debbugs.gnu.org; Thu, 20 Apr 2023 04:30:22 -0400 Received: from director5.ghost.mail-out.ovh.net (unknown [10.108.16.108]) by mo584.mail-out.ovh.net (Postfix) with ESMTP id 27C2727456 for <62461@debbugs.gnu.org>; Thu, 20 Apr 2023 08:30:18 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-5cqj5 (unknown [10.110.208.116]) by director5.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 8DD701FE6D; Thu, 20 Apr 2023 08:30:18 +0000 (UTC) Received: from ngraves.fr ([37.59.142.95]) by ghost-submission-6684bf9d7b-5cqj5 with ESMTPSA id XDI0Gxr4QGScJgEAt7iN6g (envelope-from ); Thu, 20 Apr 2023 08:30:18 +0000 X-OVh-ClientIp: 81.67.140.142 Date: Thu, 20 Apr 2023 10:30:08 +0200 Message-Id: <20230420083010.12285-2-ngraves@ngraves.fr> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230420083010.12285-1-ngraves@ngraves.fr> References: <20230420083010.12285-1-ngraves@ngraves.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Ovh-Tracer-Id: 17877601672975278818 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrfedtvddgtddvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepiedtteetteekfeetheethfduvedvgeevkeeljedvleeigeeuuedtgedvheetieejnecuffhomhgrihhnpegvgigrmhhplhgvrdhorhhgnecukfhppeduvdejrddtrddtrddupdekuddrieejrddugedtrddugedvpdefjedrheelrddugedvrdelheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqpdhnsggprhgtphhtthhopedupdhrtghpthhtohepiedvgeeiudesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheekgedpmhhouggvpehsmhhtphhouhht 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 From: Nicolas Graves via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1681979497; a=rsa-sha256; cv=none; b=D2wSZ9XX9BlR7J4Dza3IQmDdy5ZmgNkV7JoEoKaCxTv+1EG1tQIhNSrz7L5pWy369Lv1tv KdTvxZlckBf0snjT36v2TqYcyvx3TaTukNfXqeV6bwxBMYKJb5/lgoaX7Dzl3ph786JJUP yeSr1Zkh/q0YLEVPJua+o6HcGYWIeQ3k5gE+Xhxt2WVoEqPUJoF/cY3hfQPd64IDUnNdeR nzzrxo4IIlTxpp1tiDU95B98GUVaPXk1uxfT0Y9Y7EzXTl1f/n7NcG5cIejbtj++k5njz8 bjs+4FhVHlcw1rBVjPBchfGlEiW5hH4EbcftPfXVT3wEW7dR9ylaiEc7FIL/WQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1681979497; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=BmQa3kKrtz8r35jfktqUVo5O5pvox7OM3OA5Am0ug5Q=; b=h4NS3raM87h/fcerkS0riIKQw3nUIOh3iiaIErJTQSm1DNbkgsEEN6zUKyBWopytHzKf+l EW2rrKL8kUkYn9kiaz+4Wz+1lHt87vxc35z6AIpPuROe2MiLDBGFbtEexA7Lt4v1mWic6H 4yyI/mBojGtut38YrWzJrsBWKiiZE83Jqw9q0910VGjcxQXLqXn1K/BwtWZ+kIz9uB0y4R 1Ra6x+7i5iH1J180ekjPVye3IDpb45QPVpKPY0/XKecmD0+EqKFEiduW88WEjTB/aXOtqr NTnu46YMTvndYPK7TRyfdZHHlmx6lZCfn/tl1bi833r+acY+gRezbr6JOn6jwg== X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -3.21 X-Spam-Score: -3.21 X-Migadu-Queue-Id: 6A280EFF8 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-TUID: kHSIjK5QpeD5 --- doc/guix.texi | 12 ++++++++- gnu/home/services/ssh.scm | 52 ++++++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index daefe63074..6c8302e990 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -42625,11 +42625,21 @@ Available @code{openssh-host} fields are: @table @asis @item @code{name} (type: string) -Name of this host declaration. +Name of this host declaration. A @code{openssh-host} must define only +@code{name} or @code{match-criteria}. Use host-name @code{\"*\"} for +top-level options. @item @code{host-name} (type: maybe-string) Host name---e.g., @code{"foo.example.org"} or @code{"192.168.1.2"}. +@item @code{match-criteria} (type: maybe-match-criteria) +When specified, this string denotes the set of hosts to which the entry +applies, superseding the @code{host-name} field. Its first element must be +all or one of @code{ssh-match-keywords}. The rest of the elements are +arguments for the keyword, or other criteria. A @code{openssh-host} must +define only @code{name} or @code{match-criteria}. Other host configuration +options will apply to all hosts matching @code{match-criteria}. + @item @code{address-family} (type: address-family) Address family to use when connecting to this host: one of @code{AF_INET} (for IPv4 only), @code{AF_INET6} (for IPv6 only), or diff --git a/gnu/home/services/ssh.scm b/gnu/home/services/ssh.scm index 4ab2adb292..b0c5a2db71 100644 --- a/gnu/home/services/ssh.scm +++ b/gnu/home/services/ssh.scm @@ -45,6 +45,7 @@ (define-module (gnu home services ssh) openssh-host openssh-host-host-name + openssh-host-match-criteria openssh-host-identity-file openssh-host-name openssh-host-port @@ -116,13 +117,40 @@ (define (serialize-string-list field lst) (define-maybe string-list) +(define ssh-match-keywords + '(canonical final exec host originalhost user localuser)) + +(define (match-criteria? str) + ;; Rule out the case of "all" keyword. + (if (member str '("all" + "canonical all" + "final all")) + #t + (let* ((first (string-take str (string-index str #\ ))) + (keyword (string->symbol (if (string-prefix? "!" first) + (string-drop first 1) + first)))) + (memq keyword ssh-match-keywords)))) + +(define-maybe match-criteria) + (define-configuration openssh-host (name - (string) - "Name of this host declaration.") + maybe-string + "Name of this host declaration. A @code{openssh-host} must define only +@code{name} or @code{match-criteria}. Use host-name @code{\"*\"} for +top-level options.") (host-name maybe-string "Host name---e.g., @code{\"foo.example.org\"} or @code{\"192.168.1.2\"}.") + (match-criteria ;TODO implement stricter match-criteria rules + maybe-match-criteria + "When specified, this string denotes the set of hosts to which the entry +applies, superseding the @code{host-name} field. Its first element must be +all or one of @code{ssh-match-keywords}. The rest of the elements are +arguments for the keyword, or other criteria. A @code{openssh-host} must +define only @code{name} or @code{match-criteria}. Other host configuration +options will apply to all hosts matching @code{match-criteria}.") (address-family maybe-address-family "Address family to use when connecting to this host: one of @@ -171,17 +199,29 @@ (define-configuration openssh-host @file{~/.ssh/config}.")) (define (serialize-openssh-host config) - (define (openssh-host-name-field? field) - (eq? (configuration-field-name field) 'name)) + (define (openssh-host-name-or-match-field? field) + (or (eq? (configuration-field-name field) 'name) + (eq? (configuration-field-name field) 'match-criteria))) (string-append - "Host " (openssh-host-name config) "\n" + (if (maybe-value-set? (openssh-host-name config)) + (if (maybe-value-set? (openssh-host-match-criteria config)) + (raise + (formatted-message + (G_ "You must either define name or match-criteria, not both."))) + (string-append "Host " (openssh-host-name config) "\n")) + (if (maybe-value-set? (openssh-host-match-criteria config)) + (string-append + "Match " (string-join (openssh-host-match-criteria config) " ") "\n") + (raise + (formatted-message + (G_ "You must either define name or match-criteria once."))))) (string-concatenate (map (lambda (field) ((configuration-field-serializer field) (configuration-field-name field) ((configuration-field-getter field) config))) - (remove openssh-host-name-field? + (remove openssh-host-name-or-match-field? openssh-host-fields))))) (define-record-type* -- 2.39.2