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

iam role boundary does not account for gov-cloud #1846

Closed
1 task done
zer0glitch opened this issue Jun 21, 2023 · 2 comments · Fixed by #1848
Closed
1 task done

iam role boundary does not account for gov-cloud #1846

zer0glitch opened this issue Jun 21, 2023 · 2 comments · Fixed by #1848

Comments

@zer0glitch
Copy link

Summary

When using a gov cloud policy the arn starts with 'arn:aws-us-gov:iam'

if not module.params.get("boundary").startswith("arn:aws:iam"):
module.fail_json(msg="Boundary policy must be an ARN")

Issue Type

Bug Report

Component Name

community.aws.iam_role:

Ansible Version

$ ansible --version
ansible [core 2.14.2]
  config file = /home/oitchawhetsj0/dev/mhvops-ansible/ansible.cfg
  configured module search path = ['/home/oitchawhetsj0/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /home/oitchawhetsj0/.ansible/collections:/usr/share/ansible/collections
  executable location = /bin/ansible
  python version = 3.11.2 (main, Feb 17 2023, 09:28:16) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True

Collection Versions

$ ansible-galaxy collection list
amazon.aws        6.0.0  
ansible.posix     1.3.0  
ansible.windows   1.10.0 

community.aws     6.0.0  
community.crypto  2.3.1  
community.docker  3.4.3  
community.general 4.8.1  
community.grafana 1.4.0  
community.windows 1.10.0 
kubernetes.core   2.4.0 

AWS SDK versions

$ pip show boto boto3 botocore

Name: boto
Version: 2.49.0
Summary: Amazon Web Services Library
Home-page: https://github.com/boto/boto/
Author: Mitch Garnaat
Author-email: [email protected]
License: MIT
Location: /home/oitchawhetsj0/.local/lib/python3.11/site-packages
Requires: 
Required-by: 
---
Name: boto3
Version: 1.26.156
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Location: /home/oitchawhetsj0/.local/lib/python3.11/site-packages
Requires: botocore, jmespath, s3transfer
Required-by: 
---
Name: botocore
Version: 1.29.156
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Location: /home/oitchawhetsj0/.local/lib/python3.11/site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer

Configuration

$ ansible-config dump --only-changed

OS / Environment

RHEL8

Steps to Reproduce

- name: Create IAM Role for EKS Cluster
  community.aws.iam_role:
    name: "{{ cluster_iam_role_name }}_node"
    path: "{{ path }}"
    assume_role_policy_document: |
      {
        "Version": "2012-10-17",
        "Statement": [
          {
            "Effect": "Allow",
            "Principal": {
              "Service": "ec2.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
          },
          {
            "Effect": "Allow",
            "Principal": {
              "Service": "ec2.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
          }
        ]
      }
    state: "{{ state|default('present') }}"
    region: "{{ aws_region }}"
    purge_policies: true
    #boundary: arn:aw-us-govs:iam::000000000000:policy/mypolicy

    create_instance_profile: False
    managed_policies:
    - arn:aws:iam::aws:policy/AmazonEKSClusterPolicy

Expected Results

I expected the role to be created

Actual Results

 msg: Boundary policy must be an ARN

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@zer0glitch
Copy link
Author

The example has the boundary commented, but not in the actual code

tremble added a commit to tremble/community.aws that referenced this issue Jun 21, 2023
fixes: ansible-collections#1846

Various modules had hard-coded ARN handling which assumed the use of the main  partition.  This causes problems for folks using Gov Cloud (and aws-cn)
@tremble
Copy link
Contributor

tremble commented Jun 21, 2023

Thanks for taking the time to open this issue. It looks like we did this in various places. I've lined up a pair of PRs to try and fix the issue.

tremble added a commit to tremble/community.aws that referenced this issue Jun 22, 2023
fixes: ansible-collections#1846

Various modules had hard-coded ARN handling which assumed the use of the main  partition.  This causes problems for folks using Gov Cloud (and aws-cn)
tremble added a commit to tremble/community.aws that referenced this issue Jun 22, 2023
fixes: ansible-collections#1846

Various modules had hard-coded ARN handling which assumed the use of the main  partition.  This causes problems for folks using Gov Cloud (and aws-cn)
softwarefactory-project-zuul bot pushed a commit to ansible-collections/amazon.aws that referenced this issue Jun 23, 2023
Refactor ARN validation code

SUMMARY

Adds resource_id and resource_type to parse_aws_arn() return value.
Adds validate_aws_arn() to handle common pattern matching for ARNs.

ISSUE TYPE

Feature Pull Request

COMPONENT NAME
ec2_instance
iam_user
ADDITIONAL INFORMATION
Related to ansible-collections/community.aws#1846 - We've been doing things like assuming the aws partition.

Reviewed-by: Alina Buzachis
patchback bot pushed a commit to ansible-collections/amazon.aws that referenced this issue Jun 23, 2023
Refactor ARN validation code

SUMMARY

Adds resource_id and resource_type to parse_aws_arn() return value.
Adds validate_aws_arn() to handle common pattern matching for ARNs.

ISSUE TYPE

Feature Pull Request

COMPONENT NAME
ec2_instance
iam_user
ADDITIONAL INFORMATION
Related to ansible-collections/community.aws#1846 - We've been doing things like assuming the aws partition.

Reviewed-by: Alina Buzachis
(cherry picked from commit 344dbd1)
tremble added a commit to tremble/community.aws that referenced this issue Jun 23, 2023
fixes: ansible-collections#1846

Various modules had hard-coded ARN handling which assumed the use of the main  partition.  This causes problems for folks using Gov Cloud (and aws-cn)
tremble added a commit to tremble/community.aws that referenced this issue Jun 26, 2023
fixes: ansible-collections#1846

Various modules had hard-coded ARN handling which assumed the use of the main  partition.  This causes problems for folks using Gov Cloud (and aws-cn)
softwarefactory-project-zuul bot pushed a commit that referenced this issue Jun 26, 2023
Various ARN handling fixes

Depends-On: ansible-collections/amazon.aws#1619
SUMMARY
fixes: #1846
Various modules had hard-coded ARN handling which assumed the use of the main  partition.  This causes problems for folks using Gov Cloud (and aws-cn)
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
plugins/modules/batch_compute_environment.py
plugins/modules/ec2_launch_template.py
plugins/modules/elasticache_info.py
plugins/modules/iam_group.py
plugins/modules/iam_role.py
plugins/modules/msk_config.py
plugins/modules/redshift.py
plugins/modules/sns_topic.py
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis
tremble pushed a commit to ansible-collections/amazon.aws that referenced this issue Jun 27, 2023
SUMMARY

Adds resource_id and resource_type to parse_aws_arn() return value.
Adds validate_aws_arn() to handle common pattern matching for ARNs.

ISSUE TYPE

Feature Pull Request

COMPONENT NAME

ec2_instance
iam_user

ADDITIONAL INFORMATION

Related to ansible-collections/community.aws#1846 - We've been doing things like assuming the aws partition.

Reviewed-by: Alina Buzachis
(cherry picked from commit 344dbd1)
patchback bot pushed a commit that referenced this issue Jun 27, 2023
Various ARN handling fixes

Depends-On: ansible-collections/amazon.aws#1619
SUMMARY
fixes: #1846
Various modules had hard-coded ARN handling which assumed the use of the main  partition.  This causes problems for folks using Gov Cloud (and aws-cn)
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
plugins/modules/batch_compute_environment.py
plugins/modules/ec2_launch_template.py
plugins/modules/elasticache_info.py
plugins/modules/iam_group.py
plugins/modules/iam_role.py
plugins/modules/msk_config.py
plugins/modules/redshift.py
plugins/modules/sns_topic.py
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis
(cherry picked from commit 25a636c)
softwarefactory-project-zuul bot pushed a commit that referenced this issue Jun 27, 2023
[PR #1848/25a636ce backport][stable-6] Various ARN handling fixes

This is a backport of PR #1848 as merged into main (25a636c).
Depends-On: ansible-collections/amazon.aws#1619
SUMMARY
fixes: #1846
Various modules had hard-coded ARN handling which assumed the use of the main  partition.  This causes problems for folks using Gov Cloud (and aws-cn)
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
plugins/modules/batch_compute_environment.py
plugins/modules/ec2_launch_template.py
plugins/modules/elasticache_info.py
plugins/modules/iam_group.py
plugins/modules/iam_role.py
plugins/modules/msk_config.py
plugins/modules/redshift.py
plugins/modules/sns_topic.py
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell
abikouo pushed a commit to abikouo/community.aws that referenced this issue Oct 24, 2023
Various ARN handling fixes

Depends-On: ansible-collections/amazon.aws#1619
SUMMARY
fixes: ansible-collections#1846
Various modules had hard-coded ARN handling which assumed the use of the main  partition.  This causes problems for folks using Gov Cloud (and aws-cn)
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
plugins/modules/batch_compute_environment.py
plugins/modules/ec2_launch_template.py
plugins/modules/elasticache_info.py
plugins/modules/iam_group.py
plugins/modules/iam_role.py
plugins/modules/msk_config.py
plugins/modules/redshift.py
plugins/modules/sns_topic.py
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections@25a636c
abikouo pushed a commit to abikouo/community.aws that referenced this issue Oct 24, 2023
Various ARN handling fixes

Depends-On: ansible-collections/amazon.aws#1619
SUMMARY
fixes: ansible-collections#1846
Various modules had hard-coded ARN handling which assumed the use of the main  partition.  This causes problems for folks using Gov Cloud (and aws-cn)
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
plugins/modules/batch_compute_environment.py
plugins/modules/ec2_launch_template.py
plugins/modules/elasticache_info.py
plugins/modules/iam_group.py
plugins/modules/iam_role.py
plugins/modules/msk_config.py
plugins/modules/redshift.py
plugins/modules/sns_topic.py
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections@25a636c
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 a pull request may close this issue.

2 participants