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

Added functionality for AWS SSM #40

Merged
merged 1 commit into from
Feb 23, 2021
Merged

Added functionality for AWS SSM #40

merged 1 commit into from
Feb 23, 2021

Conversation

jwhaley58
Copy link

I noticed that the existing application had nearly everything needed to do SSM sessions. I have modified the application to allow the ability to use your existing profiles and connect via SSM.

I noticed that the existing application had nearly everything needed to do SSM sessions. I have modified the application to allow the ability to use your existing profiles and connect via SSM.
@jwhaley58
Copy link
Author

My team wants to start using SSM and we use your package pretty extensively. I made a few tweaks and I was able to get it to work with Session Manager.

ENV_SSH_USER,
ENV_TUNNEL_SSH_USER,
ENV_TUNNEL_KEY_PATH,
AWS_REGIONS,
AWS_DEFAULT_PROFILE,
Copy link
Author

Choose a reason for hiding this comment

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

Had to pull in the default profile from the environment variable so that you could change it needed.

@@ -64,7 +68,7 @@ def entrypoint(use_private_ip, key_path, user, ip_only, no_cache, tunnel, tunnel
}
cache.close()
except Exception as e:
print('Exception occured while getting cache, getting instances from AWS api: %s' % e)
print('Exception occurred while getting cache, getting instances from AWS api: %s' % e)
if cache:
Copy link
Author

Choose a reason for hiding this comment

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

Fixed a typo there

user=ENV_TUNNEL_SSH_USER or tunnel_user,
key=ENV_TUNNEL_KEY_PATH or tunnel_key_path,
host=choice(fuzzysearch_bash_command),
if use_ssm or ENV_USE_SSM:
Copy link
Author

Choose a reason for hiding this comment

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

Added a conditional branch to just incorporate all the ssh vs ssm logic in one area

@@ -126,7 +139,11 @@ def choice(fuzzysearch_bash_command):
except subprocess.CalledProcessError:
exit(1)

return choice.split(SEPARATOR)[1].rstrip()
if use_ssm:
output = choice.split(' ')[1].replace('(', '').replace(')', '').rstrip()
Copy link
Author

Choose a reason for hiding this comment

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

instead of stripping out the IP address, I have it pulling the instance id from the string.

ENV_USE_PUBLIC_DNS_OVER_IP = os.getenv('AWS_FUZZ_DNS_OVER_IP', False) # use public DNS over IP (both public or private)
ENV_TUNNEL_SSH_USER = os.getenv('AWS_FUZZ_TUNNEL_USER')
ENV_TUNNEL_KEY_PATH = os.getenv('AWS_FUZZ_TUNNEL_KEY_PATH')
ENV_SSH_COMMAND_TEMPLATE = os.getenv('AWS_FUZZ_SSH_COMMAND_TEMPLATE', "ssh {key} {user}{host}")
ENV_SSM_COMMAND_TEMPLATE = os.getenv('AWS_FUZZ_SSM_COMMAND_TEMPLATE', "aws ssm start-session --profile {profile} --target {target}")
Copy link
Author

Choose a reason for hiding this comment

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

Just needed a different kind of template for find and replace.

@pmazurek
Copy link
Owner

Great work, thank you! This is definitely getting merged, I'll soon bump the version and release it to pip.

@jwhaley58
Copy link
Author

I'm very excited to see this come out. Do you have an idea of what the ETA looks like? We're going to start using it immediately. Thanks again!

@pmazurek pmazurek merged commit 0310a4e into pmazurek:master Feb 23, 2021
@pmazurek
Copy link
Owner

@jwhaley-togetherwork I'll try to release to pip tomorrow, I'll @ you when it's out.

@jwhaley58 jwhaley58 deleted the feature/add-aws-ssm branch February 23, 2021 00:13
@jwhaley58
Copy link
Author

jwhaley58 commented Feb 23, 2021 via email

@pmazurek
Copy link
Owner

@jwhaley-togetherwork fyi I just released v1.1.1 to pip, thanks for your contribution! :)

https://pypi.org/project/aws-fuzzy-finder/1.1.1/

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.

3 participants