Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
8ae508f
Moving SSHArc changes from private repo to the public repo
vthiebaut10 Sep 29, 2021
75aab5c
Fix linter exclusions
vthiebaut10 Sep 29, 2021
74c35d7
Added license header to constants file
vthiebaut10 Sep 29, 2021
af62216
Fixed the local user parameter options for the config command
vthiebaut10 Sep 30, 2021
12e1c15
Changed --local-user-name to --local-user for the config command
vthiebaut10 Sep 30, 2021
5c9170c
Host for arc servers on config is not rg-vm instead of just vm
vthiebaut10 Oct 7, 2021
2601ea2
Merge branch 'Azure:main' into ssharc
vthiebaut10 Oct 11, 2021
67c61e1
Merge origin
vthiebaut10 Oct 15, 2021
1eb2100
Add HostName to arc config files
vthiebaut10 Oct 17, 2021
53e4cd2
Fixed config tests
vthiebaut10 Oct 18, 2021
0c08a46
Include OS and architecture in the proxy filename
vthiebaut10 Oct 20, 2021
7c99a1e
Stop throwing exception immediately if user not authorized to get vm …
vthiebaut10 Oct 21, 2021
b89a631
Merge pull request #8 from vthiebaut10/ssharc-exceptionhandling
vthiebaut10 Nov 1, 2021
be6ffb2
addind hybridconnectivity
vthiebaut10 Nov 2, 2021
be11b71
Change hybrid connectivity SDK to be subscription bound
vthiebaut10 Nov 3, 2021
adb6237
Adjust request for access details
vthiebaut10 Nov 5, 2021
5411e7e
Using the latest stable version of connected machines sdk
vthiebaut10 Nov 5, 2021
2029802
Merge pull request #9 from vthiebaut10/ssharc-v2-hybridconnectivity
vthiebaut10 Nov 5, 2021
61d7a66
add a exception handling to requesting relay info
vthiebaut10 Nov 5, 2021
d4d8b53
Initial changes to clean up credentials on ssh arc
vthiebaut10 Nov 9, 2021
337a5ce
Fixing a few bugs
vthiebaut10 Nov 10, 2021
d317d35
clean-up credentials
vthiebaut10 Nov 11, 2021
206ac44
config for arc no longer create temp folder for relay if there isn't …
vthiebaut10 Nov 11, 2021
5ba2fb6
Clean up, resource type param, and tests
vthiebaut10 Nov 12, 2021
32273d3
Add ssharc telemetry
vthiebaut10 Nov 12, 2021
f814e06
Style fixes
vthiebaut10 Nov 12, 2021
cac0a79
Changed some Telemetry data points names
vthiebaut10 Nov 16, 2021
426971a
Debug logs with OS and architecture
vthiebaut10 Nov 16, 2021
5e3977e
Address comments
vthiebaut10 Nov 16, 2021
ec0900d
Merge pull request #13 from vthiebaut10/ssharc-v2-cleanup-removeid-te…
vthiebaut10 Nov 16, 2021
02bbf16
remove print statement
vthiebaut10 Nov 16, 2021
3f42be5
Merge branch 'main' of https://github.com/Azure/azure-cli-extensions …
vthiebaut10 Nov 16, 2021
0479a62
fix order of args
vthiebaut10 Nov 17, 2021
bbf28ab
Fix telemetry. Collect strings instead of floats
vthiebaut10 Nov 30, 2021
26d3437
Revert "Fix telemetry. Collect strings instead of floats"
vthiebaut10 Dec 2, 2021
eb7c022
Make --local-user mandatory for windows
vthiebaut10 Dec 10, 2021
a3b55a5
local-user mandatory for windows, check resources
vthiebaut10 Dec 10, 2021
ba9d01a
az ssh config always stores relay on /az_ssh_config/myrg-myvm
vthiebaut10 Dec 10, 2021
c9a7e14
Add new parameter --arc-proxy-folder
vthiebaut10 Dec 14, 2021
b5d11ee
Add quotation marks around paths in config file
vthiebaut10 Dec 14, 2021
a96356c
Ignore capitalization on resource type
vthiebaut10 Dec 14, 2021
7e578e5
Sync validity of relay information with certificate validity
vthiebaut10 Dec 14, 2021
9cff8a1
Style fixes
vthiebaut10 Dec 14, 2021
44a2014
Fixes based on review comments
vthiebaut10 Dec 15, 2021
c767210
Change the way we print the lifetime of the relay and certificate
vthiebaut10 Dec 15, 2021
b3fddde
Style check
vthiebaut10 Dec 15, 2021
a96c59f
Fix error with IP as parameter
vthiebaut10 Dec 15, 2021
1b7e3ea
datetime.fromisoformat() fails for python lower than 3.7
vthiebaut10 Dec 15, 2021
679cd1e
Changes based on review comments
vthiebaut10 Dec 16, 2021
cd3829a
Fix config console messages
vthiebaut10 Dec 16, 2021
976dc87
Sync
vthiebaut10 Dec 16, 2021
0e0268b
Revert "Sync"
vthiebaut10 Dec 16, 2021
dfee170
Merge remote-tracking branch 'upstream/main' into ssharc
vthiebaut10 Dec 16, 2021
69c8f98
Fix a few style errors
vthiebaut10 Dec 16, 2021
19a621a
Use constant for validity
vthiebaut10 Dec 17, 2021
01fdf2b
Change message for resource not found error
vthiebaut10 Dec 17, 2021
b01b728
Change format of expiration date from military time to standard time
vthiebaut10 Dec 17, 2021
63c89db
Merge branch 'Azure:main' into ssharc
vthiebaut10 Dec 20, 2021
b6e4cb6
Merge pull request #17 from vthiebaut10/ssharc-v3
vthiebaut10 Dec 20, 2021
0fd3f30
Style changes
vthiebaut10 Dec 20, 2021
80c8ab8
fix unit tests
vthiebaut10 Dec 20, 2021
771a11d
1 line instead of 2
vthiebaut10 Dec 20, 2021
1d733b4
Merge branch 'Azure:main' into ssharc
vthiebaut10 Feb 22, 2022
c3bbe60
Merge upstream
vthiebaut10 Mar 21, 2022
5507554
Initial enhancements for public preview
vthiebaut10 Mar 23, 2022
9115399
Avoid failures caused by ips with unsupported characters
vthiebaut10 Mar 23, 2022
794d403
Fix style and tests
vthiebaut10 Mar 24, 2022
878ce73
fix history
vthiebaut10 Mar 24, 2022
a5469e1
Change tests
vthiebaut10 Mar 24, 2022
d81ed27
Fix one error message
vthiebaut10 Mar 24, 2022
5f37ef7
Merge pull request #24 from vthiebaut10/public_preview
vthiebaut10 Mar 24, 2022
ac6f575
Merge branch 'Azure:main' into ssharc
vthiebaut10 Mar 24, 2022
e61dc1c
fix history
vthiebaut10 Mar 24, 2022
ac4a0bf
Address review comments
vthiebaut10 Mar 25, 2022
412af5e
Fix test failures
vthiebaut10 Mar 25, 2022
5b5007e
Change error message for endpoint creation
vthiebaut10 Mar 25, 2022
e4029ce
Change cleanup logic
vthiebaut10 Mar 28, 2022
9a5daa0
A few final improvements
vthiebaut10 Mar 28, 2022
b9f1bba
Fix cleanup logic
vthiebaut10 Mar 30, 2022
c27f6e7
Address review comments. Change ACL of generated files, search for pr…
vthiebaut10 Apr 5, 2022
7acea38
Catch stderr
vthiebaut10 Apr 7, 2022
2a935e7
Improve help, remove explicit exception telemetry, a few changes
vthiebaut10 Apr 8, 2022
0756512
Address review comments
vthiebaut10 Apr 8, 2022
5125936
Change ssh not found error message
vthiebaut10 Apr 8, 2022
f63ec2c
Fix help and add localuser name to ip entry
vthiebaut10 Apr 8, 2022
abd4a28
help improvements
vthiebaut10 Apr 8, 2022
fb61c79
Add ssh not found error recommendation to constants
vthiebaut10 Apr 8, 2022
24bdef4
Make sure we capture stderr only when log is not supposed to be displyed
vthiebaut10 Apr 8, 2022
39be94f
update tests, help, and style
vthiebaut10 Apr 11, 2022
e224c70
Merge pull request #25 from vthiebaut10/ssharc-proxyerror
vthiebaut10 Apr 11, 2022
f7769b8
Fix linter tests
vthiebaut10 Apr 11, 2022
8c130f2
Improve some error messages
vthiebaut10 Apr 12, 2022
72f1668
Address review comments
vthiebaut10 Apr 13, 2022
a29b56c
Fix one error message
vthiebaut10 Apr 13, 2022
dd62ee4
Fix help file
vthiebaut10 Apr 13, 2022
546fa01
Add new telemetry event: TargetResourceType
vthiebaut10 Apr 13, 2022
b61b590
Fix style error
vthiebaut10 Apr 13, 2022
2692e78
Add changes to HISTORY file
vthiebaut10 Apr 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions linter_exclusions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,11 @@ ssh vm:
ssh_args:
rule_exclusions:
- no_positional_parameters
ssh arc:
parameters:
ssh_args:
rule_exclusions:
- no_positional_parameters
storage account create:
parameters:
hierarchical_namespace:
Expand Down
12 changes: 11 additions & 1 deletion src/ssh/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Release History
===============
1.1.0
-----
* SSHArc Public Preview
* Add support for connecting to Arc Servers using AAD Certificates or Local User credentials.
* New command az ssh arc.
* New parameters: --resource-type and --ssh-proxy-folder.
* Validate that target machine exists before attempting to connect.
* Stop looking for OpenSSH client executables under C:\Windows\System32\OpenSSH on Windows. Path variable must be set properly for pre-installed OpenSSH.
* Append username to host name on config files when using local user credentials.

1.0.1
-----
* Added --ssh-client-folder parameter.
Expand Down Expand Up @@ -68,4 +78,4 @@ Release History

0.1.0
-----
* Initial release.
* Initial release.
31 changes: 31 additions & 0 deletions src/ssh/azext_ssh/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from azure.cli.core.commands.client_factory import get_mgmt_service_client


def cf_hybridconnectivity_cl(cli_ctx, *_):
from azext_ssh.vendored_sdks.hybridconnectivity import HybridConnectivityManagementAPI
return get_mgmt_service_client(cli_ctx,
HybridConnectivityManagementAPI)


def cf_endpoint(cli_ctx, *_):
return cf_hybridconnectivity_cl(cli_ctx).endpoints


def cf_connectedmachine_cl(cli_ctx, *_):
from azext_ssh.vendored_sdks.connectedmachine import ConnectedMachine
return get_mgmt_service_client(cli_ctx,
ConnectedMachine)


def cf_machine(cli_ctx, *_):
return cf_connectedmachine_cl(cli_ctx).machines
94 changes: 77 additions & 17 deletions src/ssh/azext_ssh/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

helps['ssh'] = """
type: group
short-summary: SSH into resources (Azure VMs, etc) using AAD issued openssh certificates
short-summary: SSH into resources (Azure VMs, Arc servers, etc) using AAD issued openssh certificates.
"""

helps['ssh vm'] = """
type: command
short-summary: SSH into Azure VMs using an ssh certificate
long-summary: Users can login using AAD issued certificates or using local user credentials. We recommend login using AAD issued certificates. To SSH as a local user in the target machine, you must provide the local user name using the --local-user argument.
short-summary: SSH into Azure VMs or Arc Servers.
long-summary: Users can login using AAD issued certificates or using local user credentials. We recommend login using AAD issued certificates. To SSH using local user credentials, you must provide the local user name using the --local-user parameter.
examples:
- name: Give a resource group and VM to SSH to
- name: Give a resource group name and machine name to SSH using AAD issued certificates
text: |
az ssh vm --resource-group myResourceGroup --vm-name myVm
az ssh vm --resource-group myResourceGroup --name myVM

- name: Give the public IP (or hostname) of a VM to SSH to
- name: Give the public IP (or hostname) of a VM to SSH using AAD issued certificates
text: |
az ssh vm --ip 1.2.3.4
az ssh vm --hostname example.com
Expand All @@ -32,33 +32,51 @@
text: |
az ssh vm --ip 1.2.3.4 -- -A -o ForwardX11=yes

- name: Give a local user name to SSH using local user credentials on the target machine using certificate based authentication.
- name: Give the Resource Type of the target. Useful when there is an Azure VM and an Arc Server with the same name in the same resource group. Resource type can be either "Microsoft.HybridCompute" for Arc Servers or "Microsoft.Compute" for Azure Virtual Machines.
text: |
az ssh vm --local-user username --ip 1.2.3.4 --certificate-file cert.pub --private-key key
az ssh vm --resource-type [Microsoft.Compute|Microsoft.HybridCompute] --resource-group myResourceGroup --name myVM

- name: Give a local user name to SSH using local user credentials on the target machine using key based authentication.
- name: Give a local user name to SSH with local user credentials using certificate based authentication.
text: |
az ssh vm --local-user username --resource-group myResourceGroup --vm-name myVM --private-key-file key
az ssh vm --local-user username --ip 1.2.3.4 --certificate-file cert.pub --private-key-file key

- name: Give a local user name to SSH using local user credentials on the target machine using password based authentication.
- name: Give a local user name to SSH with local user credentials using key based authentication.
text: |
az ssh vm --local-user username --ip 1.2.3.4
az ssh vm --local-user username --resource-group myResourceGroup --name myVM --private-key-file key

- name: Give a local user name to SSH with local user credentials using password based authentication.
text: |
az ssh vm --local-user username --resource-group myResourceGroup --name myArcServer

- name: Give a SSH Client Folder to use the ssh executables in that folder, like ssh-keygen.exe and ssh.exe. If not provided, the extension attempt to use pre-installed OpenSSH client (in that case, ensure OpenSSH client is installed and the Path environment variable is set correctly).
text: |
az ssh vm --resource-group myResourceGroup --name myVM --ssh-client-folder "C:\\Program Files\\OpenSSH"
"""

helps['ssh config'] = """
type: command
short-summary: Create an SSH config for resources (Azure VMs, etc) which can then be used by clients that support OpenSSH configs and certificates
long-summary: Other software (git/rsync/etc) that support setting an SSH command can be set to use the config file by setting the command to 'ssh -F /path/to/config' e.g. rsync -e 'ssh -F /path/to/config'
short-summary: Create an SSH config for resources (Azure VMs, Arc Servers, etc) which can then be used by clients that support OpenSSH configs and certificates
long-summary: Other software (git/rsync/etc) that support setting an SSH command can be set to use the config file by setting the command to 'ssh -F /path/to/config' e.g. rsync -e 'ssh -F /path/to/config'. Users can create ssh config files that use AAD issued certificates or local user credentials.
examples:
- name: Give a resource group and VM for which to create a config, and save in a local file
- name: Give the resource group and machine name for which to create a config using AAD issued certificates, save in a local file, and then ssh into that resource
text: |
az ssh config --resource-group myResourceGroup --vm-name myVm --file ./sshconfig
az ssh config --resource-group myResourceGroup --name myVm --file ./sshconfig
ssh -F ./sshconfig myResourceGroup-myVM

- name: Give the public IP (or hostname) of a VM for which to create a config and then ssh
- name: Give the public IP (or hostname) of an Azure VM for which to create a config and then ssh into that VM
text: |
az ssh config --ip 1.2.3.4 --file ./sshconfig
ssh -F ./sshconfig 1.2.3.4

- name: Give a local user to create a config using local user credentials, save in local file, and then ssh into that resource
text: |
az ssh config --resource-group myResourceGroup --name myMachine --local-user username --certificate-file cert --private-key-file key --file ./sshconfig
ssh -F ./sshconfig MyResourceGroup-myMachine-username

- name: Give Keys Destination Folder to store the generated keys and certificates. If not provided, SSH keys are stored in new folder "az_ssh_config" next to the config file.
text: |
az ssh config --ip 1.2.3.4 --file ./sshconfig --keys-destination-folder /home/user/mykeys

- name: Create a generic config for use with any host
text: |
#Bash
Expand All @@ -72,6 +90,14 @@
az ssh config --ip \\* --file ./sshconfig
rsync -e 'ssh -F ./sshconfig' -avP directory/ myvm:~/directory
GIT_SSH_COMMAND="ssh -F ./sshconfig" git clone myvm:~/gitrepo

- name: Give SSH Client Folder to use the ssh executables in that folder. If not provided, the extension attempt to use pre-installed OpenSSH client (in that case, ensure OpenSSH client is installed and the Path environment variable is set correctly).
text: |
az ssh config --file ./sshconfig --resource-group myResourceGroup --name myMachine --ssh-client-folder "C:\\Program Files\\OpenSSH"

- name: Give the Resource Type of the target. Useful when there is an Azure VM and an Arc Server with the same name in the same resource group. Resource type can be either "Microsoft.HybridCompute" for Arc Servers or "Microsoft.Compute" for Azure Virtual Machines.
text: |
az ssh config --resource-type [Microsoft.Compute|Microsoft.HybridCompute] --resource-group myResourceGroup --name myVM --file ./myconfig
"""

helps['ssh cert'] = """
Expand All @@ -82,3 +108,37 @@
text: |
az ssh cert --public-key-file ./id_rsa.pub --file ./id_rsa-aadcert.pub
"""

helps['ssh arc'] = """
type: command
short-summary: SSH into Azure Arc Servers
long-summary: Users can login using AAD issued certificates or using local user credentials. We recommend login using AAD issued certificates as azure automatically rotate SSH CA keys. To SSH as a local user in the target machine, you must provide the local user name using the --local-user argument.
examples:
- name: Give a resource group name and machine name to SSH using AAD issued certificates
text: |
az ssh arc --resource-group myResourceGroup --name myMachine

- name: Using a custom private key file
text: |
az ssh arc --resource-group myResourceGroup --name myMachine --private-key-file key --public-key-file key.pub

- name: Using additional ssh arguments
text: |
az ssh arc --resource-group myResourceGroup --name myMachine -- -A -o ForwardX11=yes

- name: Give a local user name to SSH with local user credentials using certificate based authentication.
text: |
az ssh arc --local-user username --resource-group myResourceGroup --name myMachine --certificate-file cert.pub --private-key-file key

- name: Give a local user name to SSH with local user credentials using key based authentication.
text: |
az ssh arc --local-user username --resource-group myResourceGroup --name myMachine --private-key-file key

- name: Give a local user name to SSH with local user credentials using password based authentication.
text: |
az ssh arc --local-user username --resource-group myResourceGroup --name myMachine

- name: Give a SSH Client Folder to use the ssh executables in that folder, like ssh-keygen.exe and ssh.exe. If not provided, the extension attempt to use pre-installed OpenSSH client (ensure OpenSSH client is installed and the Path environment variable is set correctly).
text: |
az ssh arc --resource-group myResourceGroup --name myMachine --ssh-client-folder "C:\\Program Files\\OpenSSH"
"""
37 changes: 36 additions & 1 deletion src/ssh/azext_ssh/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ def load_arguments(self, _):
c.argument('cert_file', options_list=['--certificate-file', '-c'],
help='Path to a certificate file used for authentication when using local user credentials.')
c.argument('port', options_list=['--port'], help='SSH port')
c.argument('resource_type', options_list=['--resource-type'],
help='Resource type should be either Microsoft.Compute or Microsoft.HybridCompute',
completer=["Microsoft.HybridCompute", "Microsoft.Compute"])
c.argument('ssh_client_folder', options_list=['--ssh-client-folder'],
help='Folder path that contains ssh executables (ssh.exe, ssh-keygen.exe, etc). '
'Default to ssh pre-installed if not provided.')
c.argument('delete_credentials', options_list=['--force-delete-credentials', '--delete-private-key'],
help=('This is an internal argument. This argument is used by Azure Portal to provide a one click '
'SSH login experience in Cloud shell.'),
deprecate_info=c.deprecate(hide=True), action='store_true')
c.argument('ssh_proxy_folder', options_list=['--ssh-proxy-folder'],
help=('Path to the folder where the ssh proxy should be saved. '
'Default to .clientsshproxy folder in user\'s home directory if not provided.'))
c.positional('ssh_args', nargs='*', help='Additional arguments passed to OpenSSH')

with self.argument_context('ssh config') as c:
Expand All @@ -38,8 +48,13 @@ def load_arguments(self, _):
help='Overwrites the config file if this flag is set')
c.argument('credentials_folder', options_list=['--keys-destination-folder', '--keys-dest-folder'],
help='Folder where new generated keys will be stored.')
c.argument('port', options_list=['--port'], help='SSH Port')
c.argument('resource_type', options_list=['--resource-type'],
help='Resource type should be either Microsoft.Compute or Microsoft.HybridCompute')
c.argument('cert_file', options_list=['--certificate-file', '-c'], help='Path to certificate file')
c.argument('port', options_list=['--port'], help='SSH port')
c.argument('ssh_proxy_folder', options_list=['--ssh-proxy-folder'],
help=('Path to the folder where the ssh proxy should be saved. '
'Default to .clientsshproxy folder in user\'s home directory if not provided.'))
c.argument('ssh_client_folder', options_list=['--ssh-client-folder'],
help='Folder path that contains ssh executables (ssh.exe, ssh-keygen.exe, etc). '
'Default to ssh pre-installed if not provided.')
Expand All @@ -53,3 +68,23 @@ def load_arguments(self, _):
c.argument('ssh_client_folder', options_list=['--ssh-client-folder'],
help='Folder path that contains ssh executables (ssh.exe, ssh-keygen.exe, etc). '
'Default to ssh pre-installed if not provided.')

with self.argument_context('ssh arc') as c:
c.argument('vm_name', options_list=['--vm-name', '--name', '-n'], help='The name of the Arc Server')
c.argument('public_key_file', options_list=['--public-key-file', '-p'], help='The RSA public key file path')
c.argument('private_key_file', options_list=['--private-key-file', '-i'], help='The RSA private key file path')
c.argument('local_user', options_list=['--local-user'],
help='The username for a local user')
c.argument('cert_file', options_list=['--certificate-file', '-c'], help='Path to certificate file')
c.argument('port', options_list=['--port'], help='Port to connect to on the remote host.')
c.argument('ssh_client_folder', options_list=['--ssh-client-folder'],
help='Folder path that contains ssh executables (ssh.exe, ssh-keygen.exe, etc). '
'Default to ssh pre-installed if not provided.')
c.argument('delete_credentials', options_list=['--force-delete-credentials', '--delete-private-key'],
help=('This is an internal argument. This argument is used by Azure Portal to provide a one click '
'SSH login experience in Cloud shell.'),
deprecate_info=c.deprecate(hide=True), action='store_true')
c.argument('ssh_proxy_folder', options_list=['--ssh-proxy-folder'],
help=('Path to the folder where the ssh proxy should be saved. '
'Default to .clientsshproxy folder in user\'s home directory if not provided.'))
c.positional('ssh_args', nargs='*', help='Additional arguments passed to OpenSSH')
1 change: 1 addition & 0 deletions src/ssh/azext_ssh/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ def load_command_table(self, _):
g.custom_command('vm', 'ssh_vm')
g.custom_command('config', 'ssh_config')
g.custom_command('cert', 'ssh_cert')
g.custom_command('arc', 'ssh_arc')
Loading