Skip to content
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

az ssh config --file crashes if given filename with no / #3512

Closed
roy-work opened this issue Jun 17, 2021 · 3 comments
Closed

az ssh config --file crashes if given filename with no / #3512

roy-work opened this issue Jun 17, 2021 · 3 comments
Assignees
Labels
feature-request This issue requires a new behavior in the product in order be resolved. Service Attention This issue is responsible by Azure service team. VM SSH

Comments

@roy-work
Copy link

Extension name (the extension in question)

The az ssh extension

Description of issue (in as much detail as possible)

Attempting to run,

» az ssh config -f foo -g test -n test-new-aad-ext

Results in the following crash:

CLIInternalError: The command failed with an unexpected error. Here is the traceback:
[Errno 2] No such file or directory: ''
Traceback (most recent call last):
  File "/usr/local/Cellar/azure-cli/2.16.0/libexec/lib/python3.8/site-packages/knack/cli.py", line 215, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/local/Cellar/azure-cli/2.16.0/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 654, in execute
    raise ex
  File "/usr/local/Cellar/azure-cli/2.16.0/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 717, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/usr/local/Cellar/azure-cli/2.16.0/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 710, in _run_job
    six.reraise(*sys.exc_info())
  File "/usr/local/Cellar/azure-cli/2.16.0/libexec/lib/python3.8/site-packages/six.py", line 703, in reraise
    raise value
  File "/usr/local/Cellar/azure-cli/2.16.0/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 688, in _run_job
    result = cmd_copy(params)
  File "/usr/local/Cellar/azure-cli/2.16.0/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 325, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/local/Cellar/azure-cli/2.16.0/libexec/lib/python3.8/site-packages/azure/cli/core/__init__.py", line 784, in default_command_handler
    return op(**command_args)
  File "/Users/roy/.azure/cliextensions/ssh/azext_ssh/custom.py", line 28, in ssh_config
    _do_ssh_op(cmd, resource_group_name, vm_name, ssh_ip, public_key_file, private_key_file, use_private_ip, op_call)
  File "/Users/roy/.azure/cliextensions/ssh/azext_ssh/custom.py", line 49, in _do_ssh_op
    op_call(ssh_ip, username, cert_file, private_key_file)
  File "/Users/roy/.azure/cliextensions/ssh/azext_ssh/ssh_utils.py", line 54, in write_ssh_config
    file_utils.make_dirs_for_file(config_path)
  File "/Users/roy/.azure/cliextensions/ssh/azext_ssh/file_utils.py", line 12, in make_dirs_for_file
    mkdir_p(os.path.dirname(file_path))
  File "/Users/roy/.azure/cliextensions/ssh/azext_ssh/file_utils.py", line 17, in mkdir_p
    os.makedirs(path)
  File "/usr/local/Cellar/[email protected]/3.8.6_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/os.py", line 223, in makedirs
    mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: ''
To open an issue, please run: 'az feedback'

This is because write_ssh_config attempts to make any non-existing directories:

def write_ssh_config(config_path, resource_group, vm_name, overwrite,
ip, username, cert_file, private_key_file):
file_utils.make_dirs_for_file(config_path)

Which calls this:

def make_dirs_for_file(file_path):
if not os.path.exists(file_path):
mkdir_p(os.path.dirname(file_path))

The immediate problem is that, for foo, os.path.dirname returns '' ; it then tries to create this directory, which of course fails.

While that's the immediate cause, I would really not expect this utility to be creating directories like that. It's only being asked to emit the config to the path that I've specified. If a directory in that path doesn't exist, just error out & tell me. Worse, if I typo, it will created the typo'd directory. The examples in the docs for this flag also use ~/.ssh, which needs to have strict permissions on it, which this would ignore. It's better to just to what was asked (emit the config) & not try to correct for mistakes here.

@ghost ghost added needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 17, 2021
@yonzhan yonzhan added the VM SSH label Jun 17, 2021
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Jun 17, 2021
@yonzhan yonzhan removed the question The issue doesn't require a change to the product in order to be resolved. Most issues start as that label Jun 17, 2021
@yonzhan yonzhan added this to the S189 milestone Jun 17, 2021
@yonzhan
Copy link
Collaborator

yonzhan commented Jun 17, 2021

VM SSH

@yonzhan yonzhan added feature-request This issue requires a new behavior in the product in order be resolved. OKR3.2 Candidate labels Jun 23, 2021
@yonzhan yonzhan modified the milestones: S189, Jul 2021 (2021-08-03) Jul 2, 2021
@Juliehzl Juliehzl added the Service Attention This issue is responsible by Azure service team. label Jul 13, 2021
@yonzhan yonzhan removed this from the Jul 2021 (2021-08-03) milestone Jul 31, 2021
@N6UDP
Copy link
Member

N6UDP commented Aug 2, 2021

Fixed in #3698

@maertendMSFT
Copy link
Member

closing as it is called out as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request This issue requires a new behavior in the product in order be resolved. Service Attention This issue is responsible by Azure service team. VM SSH
Projects
None yet
Development

No branches or pull requests

5 participants