Azure / Azure/azure-cli-extensions
az ssh config under wsl creates empty public key
- Dominant language
- Python
- Stars
- 454
- Forks
- 1.7k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 64
Description
### Related command
az ssh config
### Extension name (the extension in question)
ssh
azure-cli 2.39.0
core 2.39.0
telemetry 1.0.6 *
Extensions:
ssh 1.1.2
Dependencies:
msal 1.18.0b1
azure-mgmt-resource 21.1.0b1
Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Users\AAL146\.azure\cliextensions'
Python (Windows) 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 15:58:59) [MSC v.1929 32 bit (Intel)]
### Description of issue (in as much detail as possible)
When running the az ssh config command under wsl, I get an error and the public key is an empty file (the private key is well generated).
The same command in powershell or dos cmd prompt succeeds.
In my opinion this is related to ssh-keygen, az ssh config under wsl will also start the windows ssh-keygen.exe and not the Ubuntu ssh-keygen.
When running ssh-keygen.exe in wsl I also get this error with an empty public key. But the linux ssh-keygen succeeds.
Potentially there is an issue in ssh-keygen.exe, but we cannot really blame it as there is an alternative; it is maybe the ssh extension that should be smart enough to detect that it is running under wsl (via the platform.uname for example).
az ssh config command
```
~/test_ssh$ az ssh config --file ./azsshconfig --ip "ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com" --overwrite --debug
cli.knack.cli: Command arguments: ['ssh', 'config', '--file', './azsshconfig', '--ip', 'ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com', '--overwrite', '--debug']
cli.knack.cli: __init__ debug log:
Enable color in terminal.
Init colorama.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [, , ]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'ssh': ['azext_ssh']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name Load Time Groups Commands
cli.azure.cli.core: Total (0) 0.000 0 0
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name Load Time Groups Commands Directory
cli.azure.cli.core: ssh 0.009 1 4 C:\Users\AAL146\.azure\cliextensions\ssh
cli.azure.cli.core: Total (1) 0.009 1 4
cli.azure.cli.core: Loaded 1 groups, 4 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : ssh config
cli.azure.cli.core: Command table: ssh config
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate []
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\AAL146\.azure\commands\2022-08-18.09-16-00.ssh_config.6884.log'.
az_command_data_logger: command args: ssh config --file {} --ip {} --overwrite --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [.add_subscription_parameter at 0x04889EC8>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [.add_ids_arguments at 0x04889F58>, .add_cache_arguments at 0x0489B4F0>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [, , .parse_ids_arguments at 0x0489B4A8>]
az_command_data_logger: extension name: ssh
az_command_data_logger: extension version: 1.1.2
cli.azext_ssh.ssh_utils: Platform architecture: 32bit
cli.azext_ssh.ssh_utils: OS architecture: 64bit
cli.azext_ssh.ssh_utils: System Root: C:\WINDOWS
cli.azext_ssh.ssh_utils: Attempting to run ssh-keygen from path C:\WINDOWS\SysNative\openSSH\ssh-keygen.exe
cli.azext_ssh.ssh_utils: Running ssh-keygen command C:\WINDOWS\SysNative\openSSH\ssh-keygen.exe -f \\wsl$\Ubuntu\home\ebourlon\test_ssh\az_ssh_config\ms-dev-iib-vm-we-01.a
zure.bnl-ms.myengie.com\id_rsa -t rsa -q -N
\\wsl$\Ubuntu\home\ebourlon\test_ssh\az_ssh_config\ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com\id_rsa already exists.
Overwrite (y/n)? y
fdopen \\\\wsl$\\Ubuntu\\home\\ebourlon\\test_ssh\\az_ssh_config\\ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com\\id_rsa.pub failed: No such file or directory
cli.azure.cli.core.util: azure.cli.core.util.handle_exception is called with an exception:
cli.azure.cli.core.util: Traceback (most recent call last):
File "C:\Users\AAL146\.azure\cliextensions\ssh\azext_ssh\custom.py", line 348, in _get_modulus_exponent
parser.parse(public_key_text)
File "C:\Users\AAL146\.azure\cliextensions\ssh\azext_ssh\rsa_parser.py", line 26, in parse
raise ValueError(error_str)
ValueError: Incorrectly formatted public key. Key must be format ' '
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
File "C:\Users\AAL146\.azure\cliextensions\ssh\azext_ssh\custom.py", line 104, in ssh_config
_do_ssh_op(cmd, config_session, op_call)
File "C:\Users\AAL146\.azure\cliextensions\ssh\azext_ssh\custom.py", line 172, in _do_ssh_op
op_info.cert_file, op_info.local_user = _get_and_write_certificate(cmd, op_info.public_key_file,
File "C:\Users\AAL146\.azure\cliextensions\ssh\azext_ssh\custom.py", line 213, in _get_and_write_certificate
data = _prepare_jwk_data(public_key_file)
File "C:\Users\AAL146\.azure\cliextensions\ssh\azext_ssh\custom.py", line 242, in _prepare_jwk_data
modulus, exponent = _get_modulus_exponent(public_key_file)
File "C:\Users\AAL146\.azure\cliextensions\ssh\azext_ssh\custom.py", line 350, in _get_modulus_exponent
raise azclierror.FileOperationError(f"Could not parse public key. Error: {str(e)}")
azure.cli.core.azclierror.FileOperationError: Could not parse public key. Error: Incorrectly formatted public key. Key must be format ' '
cli.azure.cli.core.azclierror: Could not parse public key. Error: Incorrectly formatted public key. Key must be format ' '
az_command_data_logger: Could not parse public key. Error: Incorrectly formatted public key. Key must be format ' '
cli.knack.cli: Event: Cli.PostExecute []
az_command_data_logger: exit code: 1
cli.__main__: Command ran in 4.397 seconds (init: 0.697, invoke: 3.700)
telemetry.save: Save telemetry record of length 3349 in cache
telemetry.check: Returns Positive.
telemetry.main: Begin creating telemetry upload process.
telemetry.process: Creating upload process: "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages
\azure\cli\telemetry\__init__.pyc C:\Users\AAL146\.azure"
telemetry.process: Return from creating process
telemetry.main: Finish creating telemetry upload process.
```
```
~/test_ssh$ ls -la /home/ebourlon/test_ssh/az_ssh_config/ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com/
total 4
drwxr-xr-x 1 ebourlon ebourlon 4096 Aug 16 10:41 .
drwxr-xr-x 1 ebourlon ebourlon 4096 Aug 16 10:41 ..
-rw-r--r-- 1 ebourlon ebourlon 2610 Aug 18 09:16 id_rsa
-rw-r--r-- 1 ebourlon ebourlon 0 Aug 18 09:16 id_rsa.pub
```
ssh-keygen.exe
```
~/test_ssh$ ssh-keygen.exe -f /home/ebourlon/test_ssh/az_ssh_config/ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com/id_rsa -t rsa -N blabla -vvv
Generating public/private rsa key pair.
debug3: failed to retrieve the owner sid and dacl of file: //wsl$/Ubuntu/home/ebourlon/test_ssh/az_ssh_config/ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com/id_rsa with erro
r code: 1
/home/ebourlon/test_ssh/az_ssh_config/ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com/id_rsa already exists.
Overwrite (y/n)? y
Your identification has been saved in /home/ebourlon/test_ssh/az_ssh_config/ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com/id_rsa.
fdopen /home/ebourlon/test_ssh/az_ssh_config/ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com/id_rsa.pub failed: No such file or directory
```
ssh-keygen (linux)
```
~/test_ssh$ ssh-keygen -f /home/ebourlon/test_ssh/az_ssh_config/ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com/id_rsa -t rsa -N blabla -vvv
Generating public/private rsa key pair.
/home/ebourlon/test_ssh/az_ssh_config/ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com/id_rsa already exists.
Overwrite (y/n)? y
Your identification has been saved in /home/ebourlon/test_ssh/az_ssh_config/ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com/id_rsa.
Your public key has been saved in /home/ebourlon/test_ssh/az_ssh_config/ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com/id_rsa.pub.
The key fingerprint is:
SHA256:4Amf3kjMBNYM9r3cKhKDGJmUFDwE1+Xjy+gu9hJL5mo ebourlon@EPL20003949
The key's randomart image is:
+---[RSA 2048]----+
|*=+.==. |
|.B o.+o. |
|+ . . * . |
| o . O * o |
|. . o X S . |
| + B + . |
| + oo * o |
| E*. . . |
|oo =+ |
+----[SHA256]-----+
~/test_ssh$ ls -la /home/ebourlon/test_ssh/az_ssh_config/ms-dev-iib-vm-we-01.azure.bnl-ms.myengie.com/
total 4
drwxr-xr-x 1 ebourlon ebourlon 4096 Aug 16 10:41 .
drwxr-xr-x 1 ebourlon ebourlon 4096 Aug 16 10:41 ..
-rw-r--r-- 1 ebourlon ebourlon 1766 Aug 18 09:21 id_rsa
-rw-r--r-- 1 ebourlon ebourlon 402 Aug 18 09:21 id_rsa.pub
```
-----
Contributor guide
Assessment
This issue has not been assessed yet.