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

Pass-through options to ssh on az ssh vm & friends #19101

Closed
roy-work opened this issue Jul 29, 2021 · 5 comments
Closed

Pass-through options to ssh on az ssh vm & friends #19101

roy-work opened this issue Jul 29, 2021 · 5 comments
Labels
argparse feature-request Service Attention This issue is responsible by Azure service team. SSH VM SSH
Milestone

Comments

@roy-work
Copy link

  • If the issue is to do with Azure CLI 2.0 in-particular, create an issue here at Azure/azure-cli

Extension name (the extension in question)

ssh

Description of issue (in as much detail as possible)

az ssh vm (et al.) allows one to SSH; sometimes, we need to set up, e.g., SSH port-forwardings. It would be great if az ssh vm understood -- and passed the remaining options through to SSH, directly. E.g.,

az ssh vm -g my_group -n my_vm -- -o SomeSshOption=3 -L 8080:localhost:8080
          ^^^^^^^^^^^^^^^^^^^^    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               az ssh opts                 options forwarded to ssh

-- is a fairly standard pattern for this sort of thing.

@yonzhan
Copy link
Collaborator

yonzhan commented Jul 29, 2021

route to service team

@N6UDP
Copy link
Member

N6UDP commented Aug 2, 2021

Sadly -- didn't appear to be easy to support given the existing azure cli arguments parser -- for now I've added an additional args parameter as part of Azure/azure-cli-extensions#3698

@jiasli jiasli transferred this issue from Azure/azure-cli-extensions Aug 3, 2021
@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 customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Aug 3, 2021
@jiasli
Copy link
Member

jiasli commented Aug 3, 2021

Transferring this issue to Azure CLI main repo as it is actually a general question.

-- is provided by argparse. As long as the parameter is declared as optional, -- will work.

For an example of declaring a positional argument:

c.positional('key_value', nargs='+', help="Space-separated configurations in the form of <section>.<key>=<value>.")

There was a discussion #18869 about how to pass arguments to another command, because the leading dashes in arguments like -o corrupts argparse's parsing.

Several workarounds are proposed in #18869, but we haven't decided which way to go.

@jiasli jiasli self-assigned this Aug 3, 2021
@jiasli jiasli added the argparse label Aug 3, 2021
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Aug 3, 2021
@jiasli jiasli added feature-request needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Aug 3, 2021
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Aug 3, 2021
@jiasli jiasli removed customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Aug 3, 2021
@yonzhan yonzhan added this to the Aug 2021 (2021-09-07) milestone Aug 3, 2021
@roy-work
Copy link
Author

roy-work commented Oct 1, 2021

One other thing that is really difficult with the current setup is scp. This one is rather thorny, as in the worst case, it can involve up to two separate VMs at the same time, potentially in different tenants.

Yes, it is possible to go down to the lower level commands, such as az ssh cert, but the problem with that is that it forces every person who might use AAD login to have an understanding of how AAD login is actually built, under the hood. It'd be nice to only require those of us who maintain systems (e.g., I work on a cloud infra team, so we mandate AAD login presently, to avoid, e.g., scenarios where we have old keys sitting in authorized_keys files). It really just scales better. This might just mean there needs to be a az ssh scp, or something. (In addition to being able to forward arguments.)

@AchilleAsh
Copy link

Hi,

Using azure cli with ssh extension v1.0.0 or higher, this seems to be implemented:

az ssh vm -n myvm -g mygroup -- "-L 8888:localhost:8888" -v
[...]
debug1: Local connections to LOCALHOST:8888 forwarded to remote address localhost:8888
[...]

This is also briefly documented in the help, with example:

Positional
    <SSH_ARGS>            : Additional arguments passed to OpenSSH.
    
[...]
    Using additional ssh arguments
        az ssh vm --ip 1.2.3.4 -- -A -o ForwardX11=yes

Thus I believe this issue could safely be closed now :)

@yonzhan yonzhan added SSH VM SSH Service Attention This issue is responsible by Azure service team. labels Apr 30, 2022
@yonzhan yonzhan closed this as completed Apr 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
argparse feature-request Service Attention This issue is responsible by Azure service team. SSH VM SSH
Projects
None yet
Development

No branches or pull requests

5 participants