Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@alissonbrunosa
Copy link
Contributor

Fixes #2179

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This looks great. But I fear it introduces a regression.

Comment on lines 108 to 112
for _, file := range files {
wg.Add(1)
go func(fileName string) {
_ = p.read(fileName)
wg.Done()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordinarily, this kind of concurrency in Go is great.

In this case, though, parallelism could lead to indeterministic results when multiple files are scanned. We distinctly want the files to be scanned in the order given so that later files (e.g. the user's personal config file) have precedence over earlier files (e.g. system config).

Please either 1) remove the parallelism or 2) ensure that aliases scanned in later files always have precedence over those scanned in earlier files, regardless of the order that the results came back in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the concurrency. I tried making each config file has its own SSHAliasMap and in the end I could merge them in the right precedence, but for now I believe it okay have it sequentially. πŸ€”

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

match := sshHostRE.FindStringSubmatch(line)
match := sshIncludeDirectiveRE.FindStringSubmatch(line)
if match != nil {
fileNames, err := filepath.Glob(match[2])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interested in how relative paths are supposed to be resolved, I've just looked up the documentation for the Include directive and it says:

Include the specified configuration file(s). Multiple pathnames may be specified and each pathname may contain glob(7) wildcards and, for user configurations, shell-like ~ references to user home directories. Files without absolute paths are assumed to be in ~/.ssh if included in a user configuration file or /etc/ssh if included from the system configuration file. Include directive may appear inside a Match or Host block to perform conditional inclusion.

So for this Include implementation to work properly, I think that is missing is:

  • relative path support;
  • multiple paths support (I'm guessing paths are split by spaces?);
  • the contents of an Include following a Match or Host block should only ever apply to that Match/Host block, unless the included file also contains Match/Host directives.

For illustrative purposes:

Host example.com
  Include file1 file2  # the directives in file1 & file2 only apply to `example.com`

Do you think it would be possible to add these features? I realize this blows up the scope a little bit, but I feel that if we add Include support, we should make it work as Include is supposed to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mislav I agree with you, if we want to add support for the Include directive, we should fully support it. I'll take a look at the ssh_config spec and implement a solution for it.

Comment on lines 45 to 50
includedTempFile := createTempFile(t, "included")
includedConfigFile := `
Host webapp
HostName webapp.example.com
`
fmt.Fprint(includedTempFile, includedConfigFile)
Copy link
Contributor Author

@alissonbrunosa alissonbrunosa Nov 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not very happy with this test, but I need to created a temp file under ~/.ssh/ dir in order to test inclusion logic.. Any suggestions on how to improve this will be welcome. πŸ˜ƒ
cc @mislav

Edited: I don't even thing it will work for all builds 😞

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed changes to avoid reading files in tests from either /etc/ssh or ~/.ssh locations, and instead reads files from test stubs. It also adds support for =-delimited keyword-argument pairs as supported by the config format.

Thank you for all your work! πŸŽ‰

- Per ssh_config(5), keywords and arguments may be separated by an `=`
  sign as well as whitespace.
- When following the `Include` directive, skip directories that were
  returned as the result of globbing.
- Respect the `Host` context when recursing into `Include`s
- Avoid having tests read from the actual filesystem.
- Avoid repeatedly looking up the home directory.
@mislav mislav merged commit ae68da6 into cli:trunk Dec 15, 2020
@alissonbrunosa alissonbrunosa deleted the fix-2179 branch December 15, 2020 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support .ssh/config Include directives

2 participants