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

aws_ec2 inventory plugin does not assume role before trying to find default regions #566

Closed
1 task done
jw-maynard opened this issue Nov 11, 2021 · 3 comments
Closed
1 task done
Labels
bug This issue/PR relates to a bug has_pr python3 traceback

Comments

@jw-maynard
Copy link

Summary

In _boto3_conn the code that tries to get the default regions if the regions configuration is not set does not use the iam_role_arn configuration parameter to assume the role before trying to call DescribeRegions. While this isn't a problem per say as the regions are the same no matter what role you're assuming, it could causes confusion if the role specified in iam_role_arn has the ec2:DescribeRegions IAM permission but the role that ansible-inventory is running as does not.

Issue Type

Bug Report

Component Name

awx_ec2 inventory plugin

Ansible Version

$ ansible --version
core 2.11.6.post0

Collection Versions

$ ansible-galaxy collection list

Not sure, running this in AWX

AWS SDK versions

$ pip show boto boto3 botocore

Not sure, running this in AWX

Configuration

$ ansible-config dump --only-changed

OS / Environment

Not sure, running this in AWX

Steps to Reproduce

  1. Create a IAM principal that does not have permission to call ec2:DescribeRegions.
  2. Create a role that does have ec2:DescribeRegions as well as the other IAM permissions required by the inventory plugin.
  3. Grant the principal created in 1 the ability to assume the role created in 2.
  4. Create an inventory configuration with iam_role_arn set to the role created in 2.
  5. Try to collect the inventory.

Expected Results

I expect that the plugin should used the role configured in iam_role_arn for all AWS api calls it needs to make other than the obvious STS calls needed to assume that role.

Actual Results

[WARNING]:  * Failed to parse /runner/inventory/aws_ec2.yml with auto plugin:
An error occurred (UnauthorizedOperation) when calling the DescribeRegions
operation: You are not authorized to perform this operation.
  File "/usr/local/lib/python3.8/site-packages/ansible/inventory/manager.py", line 290, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/local/lib/python3.8/site-packages/ansible/plugins/inventory/auto.py", line 58, in parse
    plugin.parse(inventory, loader, path, cache=cache)
  File "/usr/share/ansible/collections/ansible_collections/amazon/aws/plugins/inventory/aws_ec2.py", line 758, in parse
    results = self._query(regions, include_filters, exclude_filters, strict_permissions)
  File "/usr/share/ansible/collections/ansible_collections/amazon/aws/plugins/inventory/aws_ec2.py", line 610, in _query
    for i in self._get_instances_by_region(
  File "/usr/share/ansible/collections/ansible_collections/amazon/aws/plugins/inventory/aws_ec2.py", line 487, in _get_instances_by_region
    for connection, region in self._boto3_conn(regions):
  File "/usr/share/ansible/collections/ansible_collections/amazon/aws/plugins/inventory/aws_ec2.py", line 445, in _boto3_conn
    resp = client.describe_regions()
  File "/usr/local/lib/python3.8/site-packages/botocore/client.py", line 391, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.8/site-packages/botocore/client.py", line 719, in _make_api_call
    raise error_class(parsed_response, operation_name)
[WARNING]: Unable to parse /runner/inventory/aws_ec2.yml as an inventory source
ERROR! No inventory was parsed, please check your configuration and options.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@abikouo
Copy link
Contributor

abikouo commented Jan 19, 2022

Hi @jw-maynard
Could you please test using pull request #624 and let me know if it is solving your issue?
Regards
Aubin

@abikouo abikouo added needs_info This issue requires further information. Please answer any outstanding questions has_pr labels Jan 19, 2022
@ansibullbot ansibullbot added bug This issue/PR relates to a bug python3 traceback labels Jan 27, 2022
@jw-maynard
Copy link
Author

Hey @abikouo I'm not really familiar with how I could use the plugin from the PR on our AWX instance where we run our Ansilbe usually. I'll see what I can do. Looking at the code it seems like it should solve the issue.

@ansibullbot ansibullbot removed the needs_info This issue requires further information. Please answer any outstanding questions label Mar 7, 2022
softwarefactory-project-zuul bot pushed a commit that referenced this issue Mar 22, 2022
…ibe regions (#624)

inventory aws_ec2 - assume role using iam_role_arn parameter to describe regions

SUMMARY

This is a proposal to solve #566

ISSUE TYPE


Feature Pull Request

COMPONENT NAME

aws_ec2

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Markus Bergholz <git@osuv.de>
patchback bot pushed a commit that referenced this issue Mar 22, 2022
…ibe regions (#624)

inventory aws_ec2 - assume role using iam_role_arn parameter to describe regions

SUMMARY

This is a proposal to solve #566

ISSUE TYPE

Feature Pull Request

COMPONENT NAME

aws_ec2

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Markus Bergholz <git@osuv.de>
(cherry picked from commit 56e6e69)
patchback bot pushed a commit that referenced this issue Mar 22, 2022
…ibe regions (#624)

inventory aws_ec2 - assume role using iam_role_arn parameter to describe regions

SUMMARY

This is a proposal to solve #566

ISSUE TYPE

Feature Pull Request

COMPONENT NAME

aws_ec2

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Markus Bergholz <git@osuv.de>
(cherry picked from commit 56e6e69)
softwarefactory-project-zuul bot pushed a commit that referenced this issue Mar 22, 2022
…ibe regions (#624) (#725)

[PR #624/56e6e69f backport][stable-2] inventory aws_ec2 - assume role using iam_role_arn parameter to describe regions

This is a backport of PR #624 as merged into main (56e6e69).
SUMMARY

This is a proposal to solve #566

ISSUE TYPE


Feature Pull Request

COMPONENT NAME

aws_ec2
softwarefactory-project-zuul bot pushed a commit that referenced this issue Mar 23, 2022
…ibe regions (#624) (#726)

[PR #624/56e6e69f backport][stable-3] inventory aws_ec2 - assume role using iam_role_arn parameter to describe regions

This is a backport of PR #624 as merged into main (56e6e69).
SUMMARY

This is a proposal to solve #566

ISSUE TYPE


Feature Pull Request

COMPONENT NAME

aws_ec2
@abikouo
Copy link
Contributor

abikouo commented Mar 28, 2022

@jw-maynard PR has been merged, I am closing this, feel to reopen if the issue occurred again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr python3 traceback
Projects
None yet
Development

No branches or pull requests

3 participants