Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SSH Agent forwarding for paramiko SSH connections #159

Merged

Conversation

wvandeun
Copy link
Contributor

Adds the ssh_forwardagent (bool) attribute to a Host.
This value can be set in the inventory (nornir_ssh_forwardagent), or can be read from a ssh_config file using the host ForwardAgent flag (see man ssh_config).

Tasks, like remote_command, can then enable Agent Forwarding on the paramiko channel.

dbarrosop and others added 5 commits January 22, 2018 11:27
First release after renaming the project to nornir
Adds the ssh_forwardagent (bool) attribute to a Host.
This value can be set in the inventory (nornir_ssh_forwardagent), or can be read from a ssh_config file using the host ForwardAgent flag (see man ssh_config).

Tasks, like remote_command, can then enable Agent Forwarding on the paramiko channel.
@coveralls
Copy link

coveralls commented Jun 23, 2018

Pull Request Test Coverage Report for Build 709

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.3%) to 92.374%

Totals Coverage Status
Change from base Build 701: -0.3%
Covered Lines: 969
Relevant Lines: 1049

💛 - Coveralls

@ktbyers
Copy link
Collaborator

ktbyers commented Jun 25, 2018

I think we should also consider how this integrates to Netmiko when an SSH config file is used (and also potentially NAPALM for the Netmiko-based drivers).

Unit tests are failing looks like there are some linting and black errors.

@wvandeun
Copy link
Contributor Author

Linting issue has been fixed.
Are you aware of devices that support ssh agent forwarding, for which there is a netmiko driver?

@@ -191,6 +191,15 @@ def ssh_port(self):
"""Either ``nornir_ssh_port`` or 22."""
return self.get("nornir_ssh_port", 22)

@property
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth adding this as a property? I think I'd rather keep things in the ssh config to avoid making this more complex. What do you think? Is there a strong case where you think it'd be worth managing this in an inventory file instead of in a proper ssh config file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought pretty much the same thing...i.e. that it probably didn't make sense to have a separate attribute for this and that we should just do this through the SSH config file.

@wvandeun
Copy link
Contributor Author

wvandeun commented Jun 26, 2018 via email

@dbarrosop
Copy link
Contributor

I’ll remove it, if that is the consensus.

let's do that, let's just read it from the ssh config. If someone comes with a compelling use case we can revisit this.

@@ -35,6 +35,11 @@ def paramiko_connection(task=None):
if "proxycommand" in user_config:
parameters["sock"] = paramiko.ProxyCommand(user_config["proxycommand"])

task.host["ssh_forwardagent"] = False
Copy link
Contributor

@dbarrosop dbarrosop Jul 9, 2018

Choose a reason for hiding this comment

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

can you turn this into a private attribute (i.e. task.host._ssh_forward_agent), please? I don't want to write into the Host inventory data. To avoid problems make sure you initialize the same attribute in Host.__init__() as None.

@dbarrosop dbarrosop merged commit d870431 into nornir-automation:develop Jul 12, 2018
@dbarrosop
Copy link
Contributor

I did minor changes to your code and merged it here: 0baf86f

If there is anything wrong let me know.

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.

4 participants