forked from Azure/azure-cli-extensions
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Ssh v1.0.1 #23
Closed
Closed
Ssh v1.0.1 #23
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e8426ae
Fix filepath with spaces bug. Improve deletion warnings
vthiebaut10 9323307
update version to 1.0.1
vthiebaut10 365dc0f
Small change just to create remote branch
vthiebaut10 d3f5920
Merge pull request #22 from vthiebaut10/fix_space_bug
vthiebaut10 15a57d9
1.0.1 changes
vthiebaut10 988faa2
Print error messages from the client log
vthiebaut10 1967288
Prepend -v to ssh_args if az ssh vm is run in debug mode
vthiebaut10 091cf57
Refactor extension
vthiebaut10 238b746
Address style errors
vthiebaut10 30b42bf
Make sure credentials_folder is absolute
vthiebaut10 c3c04a1
Properly append config entries
vthiebaut10 ea82f53
fix unit tests
vthiebaut10 e709c5c
Fix a few style issues
vthiebaut10 f933d61
update history
vthiebaut10 22067bb
check if config folder exists even if credential folder is provided
vthiebaut10 f022fb4
Merge branch 'Azure:main' into ssh-v1.0.1
vthiebaut10 a678cce
Add license header to ssh_info.py
vthiebaut10 25f48cb
fix function that print error messages from the log
vthiebaut10 38da127
address review comments
vthiebaut10 126f83e
Add green message at the end of az ssh cert
vthiebaut10 5fab4c2
Address review comments
vthiebaut10 963105b
Remove colorama dependency, throw error before writing config file if…
vthiebaut10 d61c18d
Remove comment
vthiebaut10 912d2dd
Allow * as ip for config
vthiebaut10 30792f9
Disable known pylint errors
vthiebaut10 a904acf
Roll back to version 1.0.0
vthiebaut10 2919211
Warn users when using incompatible openssh versions
vthiebaut10 958c81d
Address review comments
vthiebaut10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import time | ||
import multiprocessing as mp | ||
import datetime | ||
import re | ||
from azext_ssh import file_utils | ||
|
||
from knack import log | ||
|
@@ -48,9 +49,6 @@ def start_ssh_connection(ssh_info, delete_keys, delete_cert): | |
logger.debug("Running ssh command %s", ' '.join(command)) | ||
connection_status = subprocess.call(command, shell=platform.system() == 'Windows') | ||
|
||
if log_file: | ||
_print_error_messages_from_ssh_log(log_file, connection_status) | ||
|
||
if delete_keys or delete_cert: | ||
if cleanup_process.is_alive(): | ||
cleanup_process.terminate() | ||
|
@@ -59,6 +57,9 @@ def start_ssh_connection(ssh_info, delete_keys, delete_cert): | |
while cleanup_process.is_alive() and (time.time() - t0) < CLEANUP_AWAIT_TERMINATION_IN_SECONDS: | ||
time.sleep(1) | ||
|
||
if log_file: | ||
_print_error_messages_from_ssh_log(log_file, connection_status) | ||
|
||
# Make sure all files have been properly removed. | ||
_do_cleanup(delete_keys, delete_cert, ssh_info.cert_file, ssh_info.private_key_file, ssh_info.public_key_file) | ||
if log_file: | ||
|
@@ -156,13 +157,50 @@ def get_certificate_start_and_end_times(cert_file, ssh_client_folder=None): | |
def _print_error_messages_from_ssh_log(log_file, connection_status): | ||
with open(log_file, 'r', encoding='utf-8') as ssh_log: | ||
log_text = ssh_log.read() | ||
log_lines = log_text.splitlines() | ||
if "debug1: Authentication succeeded" not in log_text or connection_status != 0: | ||
for line in log_text.splitlines(): | ||
for line in log_lines: | ||
if "debug1:" not in line: | ||
print(line) | ||
|
||
if "Permission denied (publickey)." in log_text: | ||
# pylint: disable=bare-except | ||
# pylint: disable=too-many-boolean-expressions | ||
# Check if OpenSSH client and server versions are incompatible | ||
try: | ||
regex = 'OpenSSH.*_([0-9]+)\\.([0-9]+)' | ||
local_major, local_minor = re.findall(regex, log_lines[0])[0] | ||
remote_major, remote_minor = re.findall(regex, _get_line_that_contains("remote software version", | ||
log_lines))[0] | ||
local_major = int(local_major) | ||
local_minor = int(local_minor) | ||
remote_major = int(remote_major) | ||
remote_minor = int(remote_minor) | ||
except: | ||
ssh_log.close() | ||
return | ||
|
||
if (remote_major < 7 or (remote_major == 7 and remote_minor < 8)) and \ | ||
(local_major > 8 or (local_major == 8 and local_minor >= 8)): | ||
logger.warning("The OpenSSH server version in the target VM %d.%d is too old. " | ||
"Version incompatible with OpenSSH client version %d.%d.", | ||
remote_major, remote_minor, local_major, local_minor) | ||
|
||
elif (local_major < 7 or (local_major == 7 and local_minor < 8)) and \ | ||
(remote_major > 8 or (remote_major == 8 and remote_minor >= 8)): | ||
logger.warning("The OpenSSH client version %d.%d is too old." | ||
"Version incompatible with OpenSSH server version %d.%d in the target VM .", | ||
local_major, local_minor, remote_major, remote_minor) | ||
ssh_log.close() | ||
|
||
|
||
def _get_line_that_contains(substring, lines): | ||
for line in lines: | ||
if substring in line: | ||
return line | ||
return None | ||
|
||
|
||
def _get_ssh_client_path(ssh_command="ssh", ssh_client_folder=None): | ||
if ssh_client_folder: | ||
ssh_path = os.path.join(ssh_client_folder, ssh_command) | ||
|
@@ -209,8 +247,10 @@ def _get_ssh_client_path(ssh_command="ssh", ssh_client_folder=None): | |
|
||
if not os.path.isfile(ssh_path): | ||
raise azclierror.UnclassifiedUserFault( | ||
"Could not find " + ssh_command + ".exe on path " + ssh_path + ". ", | ||
"https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse") | ||
"Could not find " + ssh_command + ".exe on path " + ssh_path + ". " | ||
"Make sure OpenSSH is installed correctly: " | ||
"https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse. " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Give a space before "." in the end. If the terminal is intelligent enough to detect this as a URL then "." will result in bad URL < url >/openssh_install_firstuse. -> < url >/openssh_install_firstuse . |
||
"Or use --ssh-client-folder to provide folder path with ssh executables. ") | ||
|
||
return ssh_path | ||
|
||
|
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.
Add the below line to line 185, 191.
Refer to https://bugzilla.mindrot.org/show_bug.cgi?id=3351 for more information.