-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
aws ec2-instance connect ssh
fails on Windows
#9114
Comments
Hi @fabiomoratti, thanks for reaching out. I wasn't able to reproduce the behavior you've described on CLI version 2.17.35. Could you provide full debug logs? You can get debug logs by adding |
Hello @RyanFitzSimmonsAK I confirm that version 2.17.35 is working as expected so I tried all 2.17.x version to see where the bug emerged (that is 18 versions..., I hope the effort is appreciated...):
As requested find below the output of the My guess is that between version 2.17.51 and version 2.17.52 the code to generate the temp key has changed and somehow does not sets the correct permission of the newly created temp key file. I also tried to find the code where the log "Generated temporary key file:" (line 53 in the attached file) is printed to inspect the coded there but I failed, maybe I was looking in the wrong place. Thank you for the kind assistance. ec2-instance-connect-out--2.17.55 (success).txt |
hi, i have the same behavior with the temp pem file that is too open, im using 2.22.14. if i downgrade to 2.17.35 its working well. @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ |
Hey, thanks for following up. I was able to reproduce this behavior. While we look into this, you can specify your private key as a workaround. In my testing, using |
indeed its what i use too. |
Thanks for raising this issue with us. The root cause is that the generated key file inherits permissions from the directory created by Python's |
I'm trying to take a look at how we might go about fixing this issue within the aws-cli (in the case that changes on the CPython and OpenSSH side don't come), and I'm having trouble reproducing the issue now. I added some print debug logs in anticipation of hitting the bug, but I'm successfully connecting to my instance from a Windows machine.
I'm definitely not experienced using Windows, so my test environment (had to spin up a Windows EC2 instance, connect using Fleet Manager RDP, and set up local aws-cli and connect using Are other folks able to continue reproducing this issue? EDIT: Not able to build the aws cli locally and reproduce the issue, but I can still get the issue when I connect to my Windows test environment using SSM Sessions Manager (Windows system permissions instead of Admin permissions) which allows me to reproduce the bug.
More test environment playing to be done. |
@CharlesReinhardt It looks like you're using an AWS CLI v2 binary built locally (something like |
Thanks @hssyoo, that was exactly my issue. I was able to set up my local environment for testing using python 3.12.6 and reproduce the issue. I was playing around with the pywin32 module (to give us more windows-specific control over file permissions) and was able to modify the generated key file so that it doesn't upset PowerShell/Win32-OpenSSH (in the logic here). If other fixes for this issue don't pan out (PowerShell/Win32-OpenSSH#2317 and python/cpython#128038), would we consider adding a dependency on pywin32 for the aws-cli? I assume we'd need to restrict the dependency to when the cli is running on Windows machines, and I'm not even sure how we would do that if we can. |
@CharlesReinhardt In general, we avoid adding dependencies since they can compound existing technical debt (eg version conflicts). If we can't get a long-term fix upstream, I'd prefer finding a simpler workaround. One possibility is to vend our own version of |
It would be nice if It might be possible to ditch the temporary directory completely and instead just create a temporary file for the private key using Possible downsides that come to mind is
|
Describe the bug
On Windows, the following command
fails because of the (temporary) key file permissions.
Regression Issue
Expected Behavior
Connect to the remote instance.
Current Behavior
The complete error (with the user and instance id anonymized) is:
Note that, after the command fails, the key file (
private-key
) and its folder (C:\Users\XXXX\AppData\Local\Temp\tmp3cja4v_s
) are missing, I presume they are created "on the fly" by the command and then removed, so there is no (easy) way to examine the file and its permission.Reproduction Steps
Possible Solution
I suspect that the temporary private key created for the connection does not have the correct permissions.
The solution is to downgrade to a previous version of the CLI that does not present the regression.
Additional Information/Context
This appears to be a regression, version up to 2.17.0 work as expected, while versions 2.17.65, 2.18.0, 2.20.0 and 2.22.0 fail with the above error.
I did not check all the minor 2.17 versions, but apparently the regression appeared between 2.17.0 and 2.17.65.
CLI version used
aws-cli/2.17.65 Python/3.12.6 Windows/11 exe/AMD64
Environment details (OS name and version, etc.)
Windows 11 Pro, version 23H2 - OS Build 22631.4460
The text was updated successfully, but these errors were encountered: