Skip to content

Commit

Permalink
Tighten SSH option passthrough
Browse files Browse the repository at this point in the history
Previously, options without values (e.g. `-t`) would be passed as:
('-t', '')

When passed through to the shell, this became the following:
-t ''

This is unfortunately not the same as intended:
-t

Additionally, previously we indiscriminately appended `--` to the
`az ssh vm` command, even if it was not needed. Now, we only do that
when options or arguments are specified.
  • Loading branch information
daviewales committed Nov 14, 2024
1 parent c732b60 commit b603118
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ https://github.com/Azure/azure-cli-extensions/issues/7285
- An Azure VM with the `AADSSHLoginForLinux` VM extension installed.
- An Entra account with the `Virtual Machine Administrator Login` or
`Virtual Machine User Login` role configured for the VM.
- Linux or WSL
- Linux or WSL (Windows is not supported due to
<https://github.com/PowerShell/PowerShell/issues/24585>).

## Install from PyPI

Expand Down
12 changes: 10 additions & 2 deletions az_ssh_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,16 @@ def main():
# Work around quoting issue on Windows (still works on Linux)
az_path = f'"{az_path}"'

ssh_opts = [" ".join(opt) for opt in filter(opt_filter, opts)]
exec_args = [az_path, "ssh", "vm", "--ip", destination, "--", *ssh_opts, *args]
ssh_opts = []
for opt in filter(opt_filter, opts):
# Only keep truthy options. e.g.
# ('-t', '') --> ('t',)
# (Yes, this is important.)
ssh_opts += filter(lambda o: o, opt)

exec_args = [az_path, "ssh", "vm", "--ip", destination]
if ssh_opts or args:
exec_args.extend(["--", *ssh_opts, *args])

os.execvp("az", exec_args)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "az-ssh-wrapper"
authors = [
{name = "David Wales", email = "david.wales@swsphn.com.au"}
]
version = "1.0.2"
version = "1.0.3"
description = "SSH Wrapper for Azure CLI's `az ssh` command"
readme = "README.md"
license = {file = "LICENSE"}
Expand Down

0 comments on commit b603118

Please sign in to comment.