-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vm] Enable password and ssh key authentication during linux VM creation #7863
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
Changes from 6 commits
4b81e24
e14aa49
a4d43bb
8527141
dd99cfb
7257cbf
e865c7e
0f3e2cf
96593a5
fa5faa5
3ff3b99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -837,16 +837,11 @@ def _validate_vm_vmss_create_auth(namespace): | |
| # validate proper arguments supplied based on the authentication type | ||
| if namespace.authentication_type == 'password': | ||
| if namespace.ssh_key_value or namespace.ssh_dest_key_path: | ||
| raise ValueError( | ||
| "incorrect usage for authentication-type 'password': " | ||
| "[--admin-username USERNAME] --admin-password PASSWORD") | ||
| raise CLIError('SSH key cannot be used with password authentication type.') | ||
|
|
||
| from knack.prompting import prompt_pass, NoTTYException | ||
| try: | ||
| if not namespace.admin_password: | ||
| namespace.admin_password = prompt_pass('Admin Password: ', confirm=True) | ||
| except NoTTYException: | ||
| raise CLIError('Please specify password in non-interactive mode.') | ||
| # if password not given, attempt to prompt user for password. | ||
| if not namespace.admin_password: | ||
| _prompt_for_password(namespace) | ||
|
|
||
| # validate password | ||
| _validate_admin_password(namespace.admin_password, | ||
|
|
@@ -855,14 +850,36 @@ def _validate_vm_vmss_create_auth(namespace): | |
| elif namespace.authentication_type == 'ssh': | ||
|
|
||
| if namespace.admin_password: | ||
| raise ValueError('Admin password cannot be used with SSH authentication type') | ||
| raise CLIError('Admin password cannot be used with SSH authentication type.') | ||
|
|
||
| validate_ssh_key(namespace) | ||
|
|
||
| if not namespace.ssh_dest_key_path: | ||
| namespace.ssh_dest_key_path = \ | ||
| '/home/{}/.ssh/authorized_keys'.format(namespace.admin_username) | ||
|
|
||
| elif namespace.authentication_type == 'all': | ||
| if namespace.os_type.lower() == 'windows': | ||
| raise CLIError('SSH not supported for Windows VMs. Use password authentication.') | ||
|
|
||
| if not namespace.admin_password: | ||
| _prompt_for_password(namespace) | ||
| _validate_admin_password(namespace.admin_password, | ||
|
||
| namespace.os_type) | ||
|
|
||
| validate_ssh_key(namespace) | ||
| if not namespace.ssh_dest_key_path: | ||
| namespace.ssh_dest_key_path = \ | ||
|
||
| '/home/{}/.ssh/authorized_keys'.format(namespace.admin_username) | ||
|
|
||
|
|
||
| def _prompt_for_password(namespace): | ||
| from knack.prompting import prompt_pass, NoTTYException | ||
| try: | ||
| namespace.admin_password = prompt_pass('Admin Password: ', confirm=True) | ||
| except NoTTYException: | ||
| raise CLIError('Please specify password in non-interactive mode.') | ||
|
|
||
|
|
||
| def _validate_admin_username(username, os_type): | ||
| import re | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.