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 network bastion ssh + AAD fails with "WARNING: UNPROTECTED PRIVATE KEY FILE!" #6408

Open
ckittel opened this issue Jun 14, 2023 · 18 comments
Labels
Auto-Assign Auto assign by bot bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-team-attention This issue needs attention from Azure service team or SDK team Network - Bastion Network Service Attention This issue is responsible by Azure service team.
Milestone

Comments

@ckittel
Copy link
Member

ckittel commented Jun 14, 2023

Describe the bug

When using az network bastion ssh --auth-type AAD the SSL certificate is automatically added to /tmp/aadsshcert... but the file permissions are set such that OpenSSH 8.2 fails with

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/tmp/aadsshcert23cd5o7q/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.

which means the connection cannot be established.

I know the bastion command delegates this work to the ssh extension, so this is probably more of an issue for the ssh extension authors to address.

Related command

az network bastion ssh --auth-type AAD

Errors

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/tmp/aadsshcert23cd5o7q/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.

Issue script & Debug output

cli.azext_ssh.ssh_utils: Running ssh-keygen command ssh-keygen -f /tmp/aadsshcert23cd5o7q/id_rsa -t rsa -q -N 
...
cli.azext_bastion.custom: Running ssh command /usr/bin/ssh [email protected]@localhost -i /tmp/aadsshcert23cd5o7q/id_rsa -o CertificateFile=/tmp/aadsshcert23cd5o7q/id_rsa.pub-aadcert.pub -p 34457 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=Error

Expected behavior

The generated id_rsa file is set to permissions of 600.

As a bonus, I think it could even to set to 400 since this directory is transient by nature. The temp directory (aadsshcert23cd5o7q in this specific example above) could even be set to 700 as well for added security/intent hygiene.

Environment Summary

azure-cli                         2.49.0

core                              2.49.0
telemetry                          1.0.8

Extensions:
bastion                            0.2.4
resource-graph                     2.1.0
ssh                                1.1.6

Dependencies:
msal                              1.20.0
azure-mgmt-resource               22.0.0

Additional context

No response

@ckittel ckittel added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Jun 14, 2023
@yonzhan
Copy link
Collaborator

yonzhan commented Jun 14, 2023

Thank you for opening this issue, we will look into it.

@ghost ghost added the Network label Jun 14, 2023
@ghost ghost added this to the Backlog milestone Jun 14, 2023
@ghost ghost assigned necusjz Jun 14, 2023
@ghost ghost added Auto-Assign Auto assign by bot Azure CLI Team The command of the issue is owned by Azure CLI team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that CXP Attention This issue is handled by CXP team. Network - Bastion labels Jun 14, 2023
@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 14, 2023
@navba-MSFT navba-MSFT added Service Attention This issue is responsible by Azure service team. needs-team-attention This issue needs attention from Azure service team or SDK team and removed CXP Attention This issue is handled by CXP team. labels Jun 19, 2023
@ghost
Copy link

ghost commented Jun 19, 2023

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @aznetsuppgithub.

Issue Details

Describe the bug

When using az network bastion ssh --auth-type AAD the SSL certificate is automatically added to /tmp/aadsshcert... but the file permissions are set such that OpenSSH 8.2 fails with

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/tmp/aadsshcert23cd5o7q/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.

which means the connection cannot be established.

I know the bastion command delegates this work to the ssh extension, so this is probably more of an issue for the ssh extension authors to address.

Related command

az network bastion ssh --auth-type AAD

Errors

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/tmp/aadsshcert23cd5o7q/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.

Issue script & Debug output

cli.azext_ssh.ssh_utils: Running ssh-keygen command ssh-keygen -f /tmp/aadsshcert23cd5o7q/id_rsa -t rsa -q -N 
...
cli.azext_bastion.custom: Running ssh command /usr/bin/ssh [email protected]@localhost -i /tmp/aadsshcert23cd5o7q/id_rsa -o CertificateFile=/tmp/aadsshcert23cd5o7q/id_rsa.pub-aadcert.pub -p 34457 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=Error

Expected behavior

The generated id_rsa file is set to permissions of 600.

As a bonus, I think it could even to set to 400 since this directory is transient by nature. The temp directory (aadsshcert23cd5o7q in this specific example above) could even be set to 700 as well for added security/intent hygiene.

Environment Summary

azure-cli                         2.49.0

core                              2.49.0
telemetry                          1.0.8

Extensions:
bastion                            0.2.4
resource-graph                     2.1.0
ssh                                1.1.6

Dependencies:
msal                              1.20.0
azure-mgmt-resource               22.0.0

Additional context

No response

Author: ckittel
Assignees: -
Labels:

bug, Network, Service Attention, needs-team-attention, Network - Bastion, Auto-Assign, Azure CLI Team

Milestone: Backlog

@navba-MSFT
Copy link
Contributor

Non customer reported. Adding Service team to look into this.

@ckittel
Copy link
Member Author

ckittel commented Jun 27, 2023

@navba-MSFT how's this coming along?

@ckittel
Copy link
Member Author

ckittel commented Jul 10, 2023

Any updates to share? We are introducing a pretty significant workaround due to this in our customer-facing content -- would be great to simplify this back to a process that "just works" based on how it was designed to operate.

@ckittel
Copy link
Member Author

ckittel commented Jul 27, 2023

What's the decision here, @navba-MSFT? Any more information I can provide. Reach out to me on teams if you require a sync call.

@navba-MSFT
Copy link
Contributor

@ckittel As mentioned above, this needs to be looked by Service team. Please follow-up with @aznetsuppgithub.

@aznetsuppgithub Please look into this on priority and reach out to @ckittel if you need any more information on this.

@isamorris
Copy link

@ckittel reviewing now

@earlb-cr2
Copy link

I faced the same issue when using command:
az network bastion ssh --name MyBastionName --resource-group MyGR --target-resource-id MyResourceID --auth-type AAD --debug

I modified line 348 in the following python script '%UserProfile%.azure\cliextensions\ssh\azext_ssh\custom.py'. To change the permission definition from '0o644' to '0o600' and this solved the permissions issue.
..
--oschmod.set_mode(cert_file, 0o644)
++oschmod.set_mode(cert_file, 0o600)

..

However, now I am faced with the dreaded 'invalid format' for the certificate file
Load key "%AppData%\Temp\aadsshxxxxx\id_rsa.pub-aadcert.pub": invalid format

Strangely, this error does not occur with the first generated certificate file, only subsequent generated files, even though files are identical.
Adding the exception to the sshd_config file does not help
PubkeyAcceptedAlgorithms [email protected]
CASignatureAlgorithms +ssh-rsa

When will we see support for ed25519 format?

@ckittel
Copy link
Member Author

ckittel commented Aug 28, 2023

@isamorris

reviewing now

Hey there Isabelle, what did your review yield?

@n0rthdev
Copy link

n0rthdev commented Dec 5, 2023

@isamorris

are there any updates?

@yonzhan yonzhan removed the Azure CLI Team The command of the issue is owned by Azure CLI team label Dec 6, 2023
@ckittel
Copy link
Member Author

ckittel commented Dec 12, 2023

Any updates @yonzhan or @isamorris?

@aavalang
Copy link
Member

@vthiebaut10 can you take a look at this? This is likely a ssh extension issue as we can az ssh to generate the cert.

@ckittel
Copy link
Member Author

ckittel commented Dec 26, 2023

Hey there @vthiebaut10, what did you find when you took a look at this?

@vthiebaut10
Copy link
Contributor

Thank you for your patience. This problem is currently being investigated here Azure/azure-cli#28417

I'm currently out of office, and will continue the investigation as soon as I arrive. As a temporary workaround, the users in the other issue reported that downgrading Azure CLI fixes the issue.

@sciacca75
Copy link

Same issue for me

@vthiebaut10
Copy link
Contributor

I shared a temporary workaround for this issue in the main issue: Azure/azure-cli#28417

@n0rthdev
Copy link

Thanks @vthiebaut10 for the workaround. This deeplink to the workaround mentioned above in Azure/azure-cli#28417 : Azure/azure-cli#28417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-team-attention This issue needs attention from Azure service team or SDK team Network - Bastion Network Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

10 participants