Bug 3143 - Add the ability to capture wildcard portion of Host keyword in ssh_config
Summary: Add the ability to capture wildcard portion of Host keyword in ssh_config
Status: NEW
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh (show other bugs)
Version: -current
Hardware: Other Linux
: P5 enhancement
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-31 06:10 AEDT by Lavneet
Modified: 2020-04-02 01:04 AEDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lavneet 2020-03-31 06:10:46 AEDT
Use Case:
`ssh pc-1` would connect to remote-cpu-1.domain.com

Currently we can use `%h` token but it captures the whole argument to Host keyword (i.e pc-1). This feature would enable capturing just the pc number (ie. 1) by using a new `%m` token for example. It is useful to simplify connection to complex ssh hostnames

For the above use-case, the ssh config can be specified as follows:
Host pc-*
  Hostname remote-cpu-%m.domain.com
Comment 1 Darren Tucker 2020-03-31 12:18:37 AEDT
There's a couple of problems with this:
 - the current matching code doesn't lend itself to supporting this kind of backreference
 - it does however currently support multiple wildcards (eg "*-*-?.domain.*") which don't map well onto the token you suggested.  It'd probably need to be regex-style digits %1 - %9.
 - "Host" specifically supports multiple matches.  You could have, eg, "Host pc-? *-* *.*.*", at which point you could have 1, 2 or 3 backrefs.  In that case, what does "%3" evaluate to and when?

I'm not sure it's useful enough to be worth the extra complexity in the parser, which is already pretty complex.
Comment 2 Lavneet 2020-04-02 01:04:14 AEDT
I ended up writting a wrapper script to account for this special case - one that is not very neat - so I realize the complexity this may add to the parser. However, in terms of usefulness, ssh configs are among the best features that boost productivity. I wonder if this logic (and more advanced parsing feature to follow) could be offloaded from the main build - as a plugin of sorts. I'm not aware if this has been done before for any other components of the program.