-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add AWS SSM Direct connection #36
base: master
Are you sure you want to change the base?
Conversation
@boris-smidt-klarrio , did you try this version, so we can confirm it actually works in the EKS use-case of yours as well? I'll edit the README and add your suggestions, thanks... |
I updated the PR with more content for the README.md, thanks for the suggestion. |
I had another try at using this script and it seems i have a race condition in this script with the Kubernetes provider. |
Update it seems that we have to use the module.kubernetes_tunnel.host otherwise the script will not wait for the ssm command. I suppose i should make a pr that this script waits on both port and host untill the port forwarding script ran. |
@theomega @boris-smidt-klarrio Any plans to merge this? |
Hi @theomega, thanks for this PR. After looking at this code, it seems much simpler and smarter than the current 'ssm' code. That's why I wonder if it could just just replace the current 'ssm' implementation. In other words, is there any interest to keep 'ssm', once we add 'ssm_direct'. If you think it can replace it, can you please modify your PR accordingly and include the profile and assumed role optional parameters which were recently added to the 'ssm' code ? Thanks |
I'm happy to do this modification, just before I do that: The I'm unsure how bad it is to require this version that is more than two years old. I leave it to you to decide if you want to accept this. |
@theomega , requiring a version released more than two years ago seems completely acceptable to me, We just need to document it correctly in the readme file. Please feel free to proceed. Thanks |
Hi all, I just accidentally re-implemented this before finding this pr. It would be super helpful if this got merged! |
aws ssm start-session \ | ||
--target $TUNNEL_GATEWAY_HOST \ | ||
--document-name AWS-StartPortForwardingSessionToRemoteHost \ | ||
--parameters "{\"host\":[\"$TUNNEL_TARGET_HOST\"], \"portNumber\":[\"$TUNNEL_TARGET_PORT\"], \"localPortNumber\":[\"$TUNNEL_LOCAL_PORT\"]}" & |
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.
aws ssm start-session \ | |
--target $TUNNEL_GATEWAY_HOST \ | |
--document-name AWS-StartPortForwardingSessionToRemoteHost \ | |
--parameters "{\"host\":[\"$TUNNEL_TARGET_HOST\"], \"portNumber\":[\"$TUNNEL_TARGET_PORT\"], \"localPortNumber\":[\"$TUNNEL_LOCAL_PORT\"]}" & | |
aws ssm start-session $TUNNEL_SSM_OPTIONS \ | |
--target $TUNNEL_GATEWAY_HOST \ | |
--document-name AWS-StartPortForwardingSessionToRemoteHost \ | |
--parameters "{\"host\":[\"$TUNNEL_TARGET_HOST\"], \"portNumber\":[\"$TUNNEL_TARGET_PORT\"], \"localPortNumber\":[\"$TUNNEL_LOCAL_PORT\"]}" & |
I just hit an issue with this opening a connection to an instance in us-west-2 while doing a deployment in us-east-1. It would be great to include support for the ssm_options
like the current ssm tunnel does so this works cross-region etc
@@ -0,0 +1,5 @@ | |||
aws ssm start-session \ | |||
--target $TUNNEL_GATEWAY_HOST \ | |||
--document-name AWS-StartPortForwardingSessionToRemoteHost \ |
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.
Can this be updated to use $TUNNEL_SSM_DOCUMENT_NAME
please?
so that it'll be possible to specify custom document if needed.
I also was about to re-implement this and send a PR :) The reason for me is a little different - right now using SSM tunnel still requires the SSH key installed on the bastion host that you proxy the connection through. |
This PR implements a second way how to use AWS SSM to do the port forwarding. It does not use SSH but rather directly uses AWS SSM without SSH to create the tunnel. See the docs for how this is done:
https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-sessions-start.html#sessions-remote-port-forwarding
Main advantage is that this also works with containers/tasks running inside AWS ECS and thus allows much cheaper bastion hosts. Also it is way simpler than SSH.