From: Nicolas Graves via Guix-patches via <guix-patches@gnu.org>
To: 62461@debbugs.gnu.org
Cc: ngraves@ngraves.fr
Subject: [bug#62461] [PATCH v3 2/4] gnu: openssh-host: Add option match-criteria.
Date: Mon, 5 Jun 2023 14:34:46 +0200 [thread overview]
Message-ID: <ecf20672533fb7f16c56f7555587a3f4e848e8e3.1685968477.git.ngraves@ngraves.fr> (raw)
In-Reply-To: <6e0836e1ad23b625b912f2aa0893c2c0b1f4e37c.1685968477.git.ngraves@ngraves.fr>
---
doc/guix.texi | 12 +++++++-
gnu/home/services/ssh.scm | 58 ++++++++++++++++++++++++++++++++++-----
2 files changed, 62 insertions(+), 8 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index d5f81f6fcd..a3d5f8446d 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -43126,11 +43126,21 @@ Secure Shell
@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: maybe-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).
diff --git a/gnu/home/services/ssh.scm b/gnu/home/services/ssh.scm
index 2de78eb1c4..017bbbc2dd 100644
--- a/gnu/home/services/ssh.scm
+++ b/gnu/home/services/ssh.scm
@@ -48,6 +48,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
@@ -95,7 +96,11 @@ (define (serialize-address-family field family)
(cond ((= family AF_INET) "inet")
((= family AF_INET6) "inet6")
;; The 'else' branch is unreachable.
- (else (raise (condition (&error)))))
+ (else
+ (raise
+ (formatted-message
+ (G_ "~s: invalid 'address-family' value")
+ value))))
"\n")
""))
@@ -173,13 +178,40 @@ (define (sanitize-proxy-command properties)
(configuration-field-error (source-properties->location properties) 'proxy-command value))
value))
+(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
@@ -234,17 +266,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* <home-openssh-configuration>
--
2.40.1
next prev parent reply other threads:[~2023-06-05 12:35 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-26 13:58 [bug#62461] Additional ssh configuration options Nicolas Graves via Guix-patches via
2023-03-26 14:07 ` [bug#62461] [PATCH 1/3] gnu: home-openssh-configuration: Add field add-keys-to-agent Nicolas Graves via Guix-patches via
2023-03-26 14:07 ` [bug#62461] [PATCH 2/3] gnu: openssh-host: Add option match-criteria Nicolas Graves via Guix-patches via
2023-04-01 7:59 ` [bug#62461] Additional ssh configuration options Ludovic Courtès
2023-04-17 15:08 ` Nicolas Graves via Guix-patches via
2023-03-26 14:07 ` [bug#62461] [PATCH 3/3] gnu: ssh: Export configuration predicates Nicolas Graves via Guix-patches via
2023-04-01 8:00 ` [bug#62461] Additional ssh configuration options Ludovic Courtès
2023-04-01 7:45 ` Ludovic Courtès
2023-04-20 8:30 ` [bug#62461] [PATCH v2 1/4] gnu: home-openssh-configuration: Add field add-keys-to-agent Nicolas Graves via Guix-patches via
2023-04-20 8:30 ` [bug#62461] [PATCH v2 2/4] gnu: openssh-host: Add option match-criteria Nicolas Graves via Guix-patches via
2023-04-20 8:30 ` [bug#62461] [PATCH v2 3/4] gnu: ssh: Export configuration predicates Nicolas Graves via Guix-patches via
2023-04-20 8:30 ` [bug#62461] [PATCH v2 4/4] gnu: ssh: Export home-ssh-agent variables Nicolas Graves via Guix-patches via
2023-05-14 21:11 ` [bug#62461] Additional ssh configuration options Ludovic Courtès
2023-06-05 12:34 ` [bug#62461] [PATCH v3 1/4] gnu: home-openssh-configuration: Add field add-keys-to-agent Nicolas Graves via Guix-patches via
2023-06-05 12:34 ` Nicolas Graves via Guix-patches via [this message]
2023-06-05 12:34 ` [bug#62461] [PATCH v3 3/4] gnu: ssh: Export configuration predicates Nicolas Graves via Guix-patches via
2023-06-05 12:34 ` [bug#62461] [PATCH v3 4/4] gnu: ssh: Export home-ssh-agent variables Nicolas Graves via Guix-patches via
2023-06-09 21:43 ` bug#62461: Additional ssh configuration options Ludovic Courtès
2023-07-04 20:17 ` [bug#62461] " Josselin Poiret via Guix-patches via
2023-07-21 20:23 ` Nicolas Graves via Guix-patches via
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ecf20672533fb7f16c56f7555587a3f4e848e8e3.1685968477.git.ngraves@ngraves.fr \
--to=guix-patches@gnu.org \
--cc=62461@debbugs.gnu.org \
--cc=ngraves@ngraves.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).