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

Add _get_boto_client and STS token management. #25

Closed

Conversation

flavioelawi
Copy link
Contributor

SUMMARY

Fixes #24

Add the following parameters to aws_ssm.py connection plugin:

  • ansible_aws_ssm_access_key_id
  • ansible_aws_ssm_secret_access_key
  • ansible_aws_ssm_session_token
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

This implements some basic STS token management, that can be passed as parameters to the task when the aws_ssm connection plugin is involved, the parameters are scoped to the plugin namespace.

ADDITIONAL INFORMATION

If you have a role that you allowed to assume in a target account, you would need to assume such role in the target account before invoking the task; this example comes from an invocation by using ansible APIs, where even assuming the role in the target account, the connection plugin was still executing under the controller-node account session.

flavioel/.virtualenvs/ansible_ssm/lib/python3.6/site-packages/botocore/client.py\", line 626, in _make_api_call\n    raise error_class(parsed_response, operation_name)\nbotocore.errorfactor
y.TargetNotConnected: An error occurred (TargetNotConnected) when calling the StartSession operation: i-01234567890123456 is not connected.\n",

By implementing the changes in this PR I am able to pass an STS token as a parameter to the task, letting it execute under the target account context.

This change also allows for backward compatibility as if nothing is specified (no OS environment variables, no parameters) the boto3 client will automatically select the default profile configured on the controller.

@flavioelawi
Copy link
Contributor Author

Pinging the the plugin authors: @psharkey @hanumantharaomvl @gau1991 :)

Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to submit this patch.

I think that we should be able to reuse some of the existing helpers rather than building something custom. Untortunately I'm not at all familiar with connection plugins. Hopefully @jillr will be able to add their 2-cents.

plugins/connection/aws_ssm.py Show resolved Hide resolved
plugins/connection/aws_ssm.py Show resolved Hide resolved
plugins/connection/aws_ssm.py Show resolved Hide resolved
@jillr jillr changed the base branch from master to main July 2, 2020 19:48
@ansibullbot ansibullbot added affects_2.10 community_review connection connection plugin feature This issue/PR relates to a feature request needs_triage new_contributor Help guide this first time contributor python3 stale_ci CI is older than 7 days, rerun before merging labels Aug 19, 2020
@ansibullbot ansibullbot added the plugins plugin (any type) label Aug 28, 2020
@MrBones757
Copy link

MrBones757 commented Sep 1, 2020

Is there any update on when we might expect this change to be merged into stable?
It was originally discussed here: ansible/ansible#49652 (comment)
but it was never included in the final release.

Thanks for the PR though - saved me some time as i've just come across this issue myself!

If you need any assistance verifying please let me know!

I have made a copy of this code and have been testing it in AWX - everything works as expected and the session token can be consumed from an external assumerole

Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

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

Change looks sound, after a little digging my previous comments don't really hold true. @gau1991 (one of the authors) has +1ed so I think we're good to merge this.

Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

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

Actually, two minor documentation things:

  1. Please add a changelog fragment https://docs.ansible.com/ansible/latest/community/development_process.html#changelogs-how-to
  2. We need a version_added entry on the new options.

Sorry things stalled out here for a while

plugins/connection/aws_ssm.py Outdated Show resolved Hide resolved
@flavioelawi
Copy link
Contributor Author

Cool, i'll squash the commits, add the changelog fragment and update the pr, thanks.

@flavioelawi flavioelawi closed this Sep 1, 2020
@flavioelawi flavioelawi deleted the aws_ssm_sts_management branch September 1, 2020 20:11
@flavioelawi
Copy link
Contributor Author

I made a mess with the pull requests, the correct one is #218

sorry about that.

alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request May 25, 2022
…le-collections#25)

* Add hostname options concatenation in aws_ec2

* Add changelog fragement

* Add integration tests

* Rename template file

* Apply suggestions from @goneri's code review

* Apply new suggestions from @goneri's code review

* Ignore if prefix is empty

* Remove tag:name error

* Apply @goneri's patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.10 community_review connection connection plugin feature This issue/PR relates to a feature request needs_triage new_contributor Help guide this first time contributor plugins plugin (any type) python3 stale_ci CI is older than 7 days, rerun before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support STS token in aws_ssm connection plugin.
5 participants