[BUG] Include directive in sshconfig results in parse error when using salt-ssh / sshconfig roster
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
Using the sshconfig roster with salt-ssh will fail with a parse error if the sshconfig uses the "Include" directive
Setup
- salt 3004.1 running on a Centos 7 VM
Steps to Reproduce the behavior
- with an "Include" directive in the
/etc/.ssh/config:
Include included_ssh_config_directory/*
# rest of the host blocks here
- run any salt-ssh command with the
sshconfigroster
Traceback (most recent call last):
File "/usr/bin/salt-ssh", line 11, in <module>
load_entry_point('salt==3004.1', 'console_scripts', 'salt-ssh')()
File "/usr/lib/python3.6/site-packages/salt/scripts.py", line 459, in salt_ssh
client.run()
File "/usr/lib/python3.6/site-packages/salt/cli/ssh.py", line 21, in run
ssh = salt.client.ssh.SSH(self.config)
File "/usr/lib/python3.6/site-packages/salt/client/ssh/__init__.py", line 240, in __init__
self.targets = self.roster.targets(self.opts["tgt"], self.tgt_type)
File "/usr/lib/python3.6/site-packages/salt/roster/__init__.py", line 100, in targets
targets.update(self.rosters[f_str](tgt, tgt_type))
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1201, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/usr/lib/python3.6/site-packages/contextvars/__init__.py", line 38, in run
return callable(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/loader/lazy.py", line 1216, in _run_as
return _func_or_method(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/salt/roster/sshconfig.py", line 99, in targets
all_minions = parse_ssh_config([line.rstrip() for line in fp])
File "/usr/lib/python3.6/site-packages/salt/roster/sshconfig.py", line 56, in parse_ssh_config
hosts[-1].append(line)
IndexError: list index out of range
The code appears to assume that all lines are either empty, start with a comment, or start with "Host", and a line that starts with "Include" would break that assumption.
Expected behavior
- ideally I'd like for the ssh config parsing to collect all the files listed in the include directives and include them alongside all the other host entries
- this is similar to what paramiko did in early 2018: https://github.com/paramiko/paramiko/pull/872
- in the absolute worst case, ignoring include directives and not bombing out is preferred to the current behavior
Versions Report
salt --versions-report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)Salt Version:
Salt: 3004.1
Dependency Versions:
cffi: Not Installed
cherrypy: unknown
dateutil: 2.4.2
docker-py: Not Installed
gitdb: 0.6.4
gitpython: 1.0.1
Jinja2: 2.11.1
libgit2: Not Installed
M2Crypto: 0.35.2
Mako: Not Installed
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.6.8 (default, Mar 30 2020, 17:04:00)
python-gnupg: Not Installed
PyYAML: 3.13
PyZMQ: 17.0.0
smmap: 0.9.0
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.1.4
System Versions:
dist: centos 7 Core
locale: UTF-8
machine: x86_64
release: 4.4.131-1.el7.centos.x86_64
system: Linux
version: CentOS Linux 7 Core
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with salt/roster/sshconfig.py, especially parse_ssh_config and the sshconfig roster targets entry point. Reproduce the failure using an Include directive and salt-ssh with the sshconfig roster. Done means the roster no longer raises an IndexError and handles the directive according to the issue's expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100