-
Notifications
You must be signed in to change notification settings - Fork 4
Use a default temp folder for keys and certs #1
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
base: ssharc
Are you sure you want to change the base?
Changes from all commits
7509ca0
5f717fe
ebed8fb
2cf822b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ def ssh_vm(cmd, resource_group_name=None, vm_name=None, resource_id=None, ssh_ip | |
|
|
||
| _assert_args(resource_group_name, vm_name, ssh_ip, resource_id, cert_file, local_user) | ||
| do_ssh_op = _decide_op_call(cmd, resource_group_name, vm_name, resource_id, ssh_ip, None, None, | ||
| ssh_client_path, ssh_args, delete_privkey) | ||
| ssh_client_path, ssh_args, delete_privkey, local_user) | ||
| do_ssh_op(cmd, ssh_ip, public_key_file, private_key_file, local_user, | ||
| cert_file, port, use_private_ip) | ||
|
|
||
|
|
@@ -40,7 +40,7 @@ def ssh_config(cmd, config_path, resource_group_name=None, vm_name=None, ssh_ip= | |
|
|
||
| _assert_args(resource_group_name, vm_name, ssh_ip, resource_id, cert_file, local_user) | ||
| do_ssh_op = _decide_op_call(cmd, resource_group_name, vm_name, resource_id, ssh_ip, config_path, overwrite, | ||
| None, None, None) | ||
| None, None, None, None) | ||
| do_ssh_op(cmd, ssh_ip, public_key_file, private_key_file, local_user, | ||
| cert_file, port, use_private_ip) | ||
|
|
||
|
|
@@ -184,10 +184,16 @@ def _assert_args(resource_group, vm_name, ssh_ip, resource_id, cert_file, userna | |
| def _check_or_create_public_private_files(public_key_file, private_key_file): | ||
| # If nothing is passed in create a temporary directory with a ephemeral keypair | ||
| if not public_key_file and not private_key_file: | ||
| temp_dir = tempfile.mkdtemp(prefix="aadsshcert") | ||
| temp_dir = os.path.join(tempfile.gettempdir(), consts.DEFAULT_KEY_TEMPDIR_NAME) | ||
| public_key_file = os.path.join(temp_dir, "id_rsa.pub") | ||
| private_key_file = os.path.join(temp_dir, "id_rsa") | ||
| ssh_utils.create_ssh_keyfile(private_key_file) | ||
| if not os.path.isdir(temp_dir): | ||
| new_temp_dir = tempfile.mkdtemp() | ||
| os.rename(new_temp_dir, os.path.join(os.path.dirname(new_temp_dir), consts.DEFAULT_KEY_TEMPDIR_NAME)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why can't we create the temp directory with the desired name. What's the need for rename?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I agree that's a little weird. But the way this tempfile library works is that we can provide a prefix and/or a suffix for the name, but they are gonna add some random characters in the middle. So I just rename it instead so we don't have to deal with that. |
||
| if not os.path.isfile(public_key_file) or not os.path.isfile(private_key_file): | ||
| file_utils.delete_file(public_key_file, f"Couldn't delete existing public key {public_key_file}. ") | ||
| file_utils.delete_file(private_key_file, f"Couldn't delete existing private key {private_key_file}. ") | ||
| ssh_utils.create_ssh_keyfile(private_key_file) | ||
|
|
||
| if not public_key_file: | ||
| if private_key_file: | ||
|
|
@@ -311,7 +317,7 @@ def _arc_list_access_details(cmd, resource_group, vm_name): | |
|
|
||
|
|
||
| def _decide_op_call(cmd, resource_group_name, vm_name, resource_id, ssh_ip, config_path, overwrite, | ||
| ssh_client_path, ssh_args, delete_privkey): | ||
| ssh_client_path, ssh_args, delete_privkey, local_user): | ||
|
|
||
| # If the user provides an IP address the target will be treated as an Azure VM even if it is an | ||
| # Arc Server. Which just means that the Connectivity Proxy won't be used to establish connection. | ||
|
|
@@ -350,8 +356,11 @@ def _decide_op_call(cmd, resource_group_name, vm_name, resource_id, ssh_ip, conf | |
| op_call = functools.partial(ssh_utils.write_ssh_config, config_path=config_path, overwrite=overwrite, | ||
| resource_group=resource_group_name) | ||
| else: | ||
| delete_cert = False | ||
| if not local_user: | ||
| delete_cert = True | ||
| op_call = functools.partial(ssh_utils.start_ssh_connection, ssh_client_path=ssh_client_path, ssh_args=ssh_args, | ||
| delete_privkey=delete_privkey) | ||
| delete_privkey=delete_privkey, delete_cert=delete_cert) | ||
| do_ssh_op = functools.partial(_do_ssh_op, resource_group_name=resource_group_name, vm_name=vm_name, | ||
| is_arc=is_arc_server, op_call=op_call) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call it as DEFAULT_TEMPDIR.
We will store keys, relay information, etc in this folder.