-
Notifications
You must be signed in to change notification settings - Fork 344
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
Make SCP and StartShell behaves the same way as Device for SSH #649
Open
vincentbernat
wants to merge
4
commits into
Juniper:master
Choose a base branch
from
vincentbernat:fix/ssh-config-scp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
51a68d1
Do not provide the key if it comes from the SSH configuration
vincentbernat a3686e6
scp: simplify SSH connection settings
vincentbernat 63ccdcc
scp: move paramiko SSH client creation into a dedicated function
vincentbernat 35d3390
start_shell: initialize SSH client the same way as for SCP
vincentbernat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# utils/misc.py | ||
|
||
import paramiko | ||
|
||
def get_ssh_client(junos): | ||
"""Get a Paramiko SSHClient using settings from the provided device.""" | ||
ssh = paramiko.SSHClient() | ||
ssh.load_system_host_keys() | ||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | ||
|
||
# use junos._hostname since this will be correct if we are going | ||
# through a jumphost. | ||
|
||
# Retrieve ProxyCommand and IdentityFile | ||
sock = None | ||
key_file = junos._ssh_private_key_file | ||
ssh_config = junos._sshconf_path | ||
if ssh_config: | ||
config = paramiko.SSHConfig() | ||
config.parse(open(ssh_config)) | ||
config = config.lookup(junos._hostname) | ||
if config.get("proxycommand"): | ||
sock = paramiko.proxy.ProxyCommand(config.get("proxycommand")) | ||
key_file = key_file or config.get("identityfile") | ||
|
||
ssh.connect(hostname=junos._hostname, | ||
port=(22, int(junos._port))[ | ||
junos._hostname == 'localhost'], | ||
username=junos._auth_user, | ||
password=junos._auth_password, | ||
key_filename=key_file, | ||
allow_agent=junos._allow_agent, | ||
sock=sock) | ||
return ssh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we can also have ssh key file protected by passphrase. That passphrase in passed to Device as password.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you provide a password, the agent is disabled and Paramiko will fetch the key and decrypt it. The agent doesn't allow you to provide a password for an encrypted key either (it will ask the user for that if needed). Moreover, this code is already present as is. It's just moved here to be able to reuse its result for scp.
IMO, the ability to disable the agent part is odd. The regular "ssh" client doesn't have such an option. It adds complexity and I don't know why this has been implemented. We should just get rid of that.