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

SSH extension #1363

Merged
merged 20 commits into from
Aug 17, 2020
Merged

SSH extension #1363

merged 20 commits into from
Aug 17, 2020

Conversation

rlrossiter
Copy link
Contributor

Add an extension used for AAD-based SSH for Azure VMs.


This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally?

For new extensions:

@azuresdkci
Copy link

If this PR is for a new extension or change to an existing extension, use the following to try out the changes in this PR:

docker run -it microsoft/azure-cli:latest
export EXT=<NAME>
pip install --upgrade --target ~/.azure/cliextensions/$EXT "git+https://github.com/rlrossiter/azure-cli-extensions.git@ssh-extension#subdirectory=src/$EXT&egg=$EXT"

@yonzhan yonzhan requested a review from qwordy March 7, 2020 01:41
@yonzhan
Copy link
Collaborator

yonzhan commented Mar 7, 2020

SSH for Azure VM

@yungezz yungezz requested review from arrownj and removed request for qwordy March 7, 2020 01:49
@yungezz yungezz assigned arrownj and unassigned qwordy Mar 7, 2020
@yungezz
Copy link
Member

yungezz commented Mar 7, 2020

hi @rlrossiter we'll look at the issue and keep offline syncing with you.

Ryan Rossiter added 2 commits March 31, 2020 10:06
CLI arguments were changed from extra to argument with None defaults in
custom. Changed resource_group to resource_group_name argument for
auto-population from cli-core.

Removed Python 2 and added new Python 3s to setup.
src/ssh/setup.py Outdated Show resolved Hide resolved
src/ssh/azext_ssh/__init__.py Outdated Show resolved Hide resolved
src/ssh/azext_ssh/azext_metadata.json Outdated Show resolved Hide resolved
def _get_ssh_path():
ssh_path = "ssh"

if platform.system() == 'Windows':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible there is no ssh in other platform ?

@mock.patch('azext_ssh.custom._do_ssh_op')
@mock.patch('azext_ssh.custom.ssh_utils')
@mock.patch('functools.partial')
def test_ssh_config(self, mock_partial, mock_ssh_utils, mock_do_op):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rlrossiter , which python version are you using to run this test ? It always failed from my side (python 3.8).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version isn't the problem, the code changed and broke the unit tests. A lot of them are now failing for me too because of the code changes (Python 3.6).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rlrossiter, what other tests also failed for you ? As you can see from the CI log, all other tests are passed. Did you use the latest azure-cli dev branch and rerun azdev setup ? It should be only this test failed. And the reason has something to do with functions.partial. I'm not sure the root cause currently, will investigate deeper.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I didn't have all of the commits you added to this branch. Will re-pull and take a look if I get a chance.

]

DEPENDENCIES = [
'paramiko==2.6.0',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rlrossiter, seems we do not use these dependencies in our code any more ? Can we remove them ?

op_call(ssh_ip, username, cert_file, private_key_file)


def _prepare_jwk_data(public_key_file):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These codes were previously in azure-cli-core. I move it here because we think it is ssh certificate specific. In azure-cli-core, we expose a function get_msal_token in _profile.Profile to make it simple and clean. @rlrossiter @danybeam, could you please help review it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the use of the _profile module from core outside of core because modules that start with _ usually denote that it's a private module that shouldn't be used outside of the repo it lives in. That's why I put this in azure-cli-core to start

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with you about the private module part. For this _profile case, as there are lots of examples in extensions to use _profile directly, so I think we can just follow it. From cli-core perspective, we have an internal discussion, and we think we'd better not include SSH specific logic in it.

profile = Profile(cli_ctx=cmd.cli_ctx)
username, certificate = profile.get_msal_token(scopes, data)

cert_file = _write_cert_file(public_key_file, username, certificate)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rlrossiter , previously there is a fixed [email protected] in certificate head, which is weird to me. I replace it with username, could you please help check whether it is right ?

Previous code in azure-cli-core

class SSHCredentials(object):
    def __init__(self, username, cert):
        self.username = username
        self.certificate = "[email protected] " + cert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original was correct as that was the type of certificate the file was (it's required by SSH). The username is encoded as part of the base64 bytes written to the file. The username was passed back alongside the credentials but not part of the certificate in order to know who to SSH as

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your explain. Yes, I decode the certificate and find [email protected] is in it. I have change it back. You can have a look.

Could you please share more about this? Is there any document which explain it? It's still weird to me that why it is a fixed name in the certificate. Thanks in advance.

@arrownj arrownj merged commit 92a2530 into Azure:master Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants