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

ssm connection: pull bucket region info rather than taking from region var #1176

Merged
merged 9 commits into from
Jun 30, 2022
Merged

Conversation

JLukeBlakey
Copy link
Contributor

@JLukeBlakey JLukeBlakey commented May 30, 2022

SUMMARY

Fix issue where syntax error is reported if using ssm connection and the target node is located in a different region to the s3 bucket.

Fixes #1190, #637

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

aws_ssm connection plugin

ADDITIONAL INFORMATION

When using SSM for ansible connection and the target node is in a different region to the s3 bucket used, the playbook immediately errors with the following. (There are no issues when both target and s3 bucket are in the same region)

fatal: [i-04444a7f03cc2bffd]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "", "module_stdout": " File \"/tmp/ansible/ansible-tmp-1653576081.8378458-29658-258097978113216/AnsiballZ_setup.py\", line 1\r\r\n <?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\r\n ^\r\r\nSyntaxError: invalid syntax\r\r", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}

The tmp file has the following contents

<?xml version="1.0" encoding="UTF-8"?> <Error><Code>AuthorizationQueryParametersError</Code><Message>Error parsing the X-Amz-Credential parameter; the region 'us-east-1' is wrong; expecting 'eu-west-1'</Message><Region>eu-west-1</Region><RequestId>4VTAGR4C1V9ATBJT</RequestId><HostId>OahjGsFQHlr3ihxobH/yyH7Mzxq98mwjcb6+J3Y2EifDU7FykCe8b6QJTNodIG5WSquVeJF+Zsk=</HostId></Error>

Steps to reproduce: run an ansible playbook using the following:

  • aws_ec2 inventory
  • aws_ssm connection type
  • specify an s3 bucket (ansible_aws_ssm_bucket_name var) that is in a different location to the target node

The presigned url generated includes the region the s3 bucket is in, so this region must be used for the session obtained in the _get_url function.

@ansibullbot ansibullbot added bug This issue/PR relates to a bug community_review connection connection plugin needs_triage new_contributor Help guide this first time contributor plugins plugin (any type) labels May 30, 2022
@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

ansible-galaxy-importer FAILURE in 5m 18s (non-voting)
✔️ build-ansible-collection SUCCESS in 5m 04s
ansible-test-sanity-docker-devel FAILURE in 10m 34s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 12m 01s
ansible-test-sanity-docker-stable-2.9 FAILURE in 12m 29s
ansible-test-sanity-docker-stable-2.11 FAILURE in 12m 12s
ansible-test-sanity-docker-stable-2.12 FAILURE in 10m 20s
✔️ ansible-test-units-community-aws-python38 SUCCESS in 7m 21s
✔️ ansible-test-splitter SUCCESS in 2m 34s
⚠️ integration-community.aws-1 SKIPPED
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED

@github-actions
Copy link

github-actions bot commented May 30, 2022

Docs Build 📝

Thank you for contribution!✨

This PR has been merged and your docs changes will be incorporated when they are next published.

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

ansible-galaxy-importer FAILURE in 4m 23s (non-voting)
✔️ build-ansible-collection SUCCESS in 5m 06s
ansible-test-sanity-docker-devel FAILURE in 11m 33s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 11m 31s
ansible-test-sanity-docker-stable-2.9 FAILURE in 13m 34s
ansible-test-sanity-docker-stable-2.11 FAILURE in 12m 14s
ansible-test-sanity-docker-stable-2.12 FAILURE in 10m 37s
✔️ ansible-test-units-community-aws-python38 SUCCESS in 6m 43s
✔️ ansible-test-splitter SUCCESS in 3m 08s
⚠️ integration-community.aws-1 SKIPPED
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

ansible-galaxy-importer FAILURE in 4m 00s (non-voting)
✔️ build-ansible-collection SUCCESS in 4m 52s
ansible-test-sanity-docker-devel FAILURE in 11m 42s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 10m 28s
✔️ ansible-test-sanity-docker-stable-2.9 SUCCESS in 15m 12s
ansible-test-sanity-docker-stable-2.11 FAILURE in 11m 17s
ansible-test-sanity-docker-stable-2.12 FAILURE in 9m 20s
✔️ ansible-test-units-community-aws-python38 SUCCESS in 6m 35s
✔️ ansible-test-splitter SUCCESS in 2m 27s
⚠️ integration-community.aws-1 SKIPPED
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

ansible-galaxy-importer FAILURE in 4m 16s (non-voting)
✔️ build-ansible-collection SUCCESS in 4m 45s
ansible-test-sanity-docker-devel FAILURE in 9m 05s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 9m 21s
✔️ ansible-test-sanity-docker-stable-2.9 SUCCESS in 14m 50s
ansible-test-sanity-docker-stable-2.11 FAILURE in 9m 31s
ansible-test-sanity-docker-stable-2.12 FAILURE in 9m 16s
✔️ ansible-test-units-community-aws-python38 SUCCESS in 6m 42s
✔️ ansible-test-splitter SUCCESS in 2m 27s
⚠️ integration-community.aws-1 SKIPPED
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

ansible-galaxy-importer FAILURE in 4m 51s (non-voting)
✔️ build-ansible-collection SUCCESS in 4m 56s
ansible-test-sanity-docker-devel FAILURE in 12m 10s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 9m 29s
✔️ ansible-test-sanity-docker-stable-2.9 SUCCESS in 12m 24s
ansible-test-sanity-docker-stable-2.11 FAILURE in 11m 52s
ansible-test-sanity-docker-stable-2.12 FAILURE in 9m 51s
✔️ ansible-test-units-community-aws-python38 SUCCESS in 5m 54s
✔️ ansible-test-splitter SUCCESS in 2m 27s
⚠️ integration-community.aws-1 SKIPPED
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

ansible-galaxy-importer FAILURE in 5m 51s (non-voting)
✔️ build-ansible-collection SUCCESS in 4m 45s
✔️ ansible-test-sanity-docker-devel SUCCESS in 12m 31s (non-voting)
✔️ ansible-test-sanity-docker-milestone SUCCESS in 11m 15s
✔️ ansible-test-sanity-docker-stable-2.9 SUCCESS in 12m 33s
✔️ ansible-test-sanity-docker-stable-2.11 SUCCESS in 10m 06s
✔️ ansible-test-sanity-docker-stable-2.12 SUCCESS in 9m 32s
✔️ ansible-test-units-community-aws-python38 SUCCESS in 7m 43s
✔️ ansible-test-splitter SUCCESS in 2m 40s
⚠️ integration-community.aws-1 SKIPPED
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

ansible-galaxy-importer FAILURE in 4m 03s (non-voting)
✔️ build-ansible-collection SUCCESS in 5m 00s
✔️ ansible-test-sanity-docker-devel SUCCESS in 11m 36s (non-voting)
✔️ ansible-test-sanity-docker-milestone SUCCESS in 9m 31s
✔️ ansible-test-sanity-docker-stable-2.12 SUCCESS in 9m 37s
✔️ ansible-test-sanity-docker-stable-2.13 SUCCESS in 9m 33s
✔️ ansible-test-units-community-aws-python38 SUCCESS in 6m 04s
✔️ ansible-test-units-community-aws-python39 SUCCESS in 6m 42s
✔️ ansible-test-splitter SUCCESS in 2m 39s
⚠️ integration-community.aws-1 SKIPPED
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED

@ansibullbot ansibullbot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR and removed community_review labels Jun 20, 2022
@markuman markuman added backport-3 PR should be backported to the stable-3 branch backport-4 PR should be backported to the stable-4 branch labels Jun 30, 2022
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

✔️ ansible-galaxy-importer SUCCESS in 3m 59s (non-voting)
✔️ build-ansible-collection SUCCESS in 4m 49s
✔️ ansible-test-sanity-docker-devel SUCCESS in 10m 56s (non-voting)
✔️ ansible-test-sanity-docker-milestone SUCCESS in 10m 49s
✔️ ansible-test-sanity-docker-stable-2.12 SUCCESS in 12m 03s
✔️ ansible-test-sanity-docker-stable-2.13 SUCCESS in 11m 05s
✔️ ansible-test-units-community-aws-python38 SUCCESS in 5m 06s
✔️ ansible-test-units-community-aws-python39 SUCCESS in 6m 54s
✔️ ansible-test-splitter SUCCESS in 2m 35s
⚠️ integration-community.aws-1 SKIPPED
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED

@tremble tremble added the mergeit Merge the PR (SoftwareFactory) label Jun 30, 2022
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded (gate pipeline).

✔️ ansible-galaxy-importer SUCCESS in 3m 59s (non-voting)
✔️ build-ansible-collection SUCCESS in 4m 51s
✔️ ansible-test-sanity-docker-devel SUCCESS in 10m 48s (non-voting)
✔️ ansible-test-sanity-docker-milestone SUCCESS in 10m 52s
✔️ ansible-test-sanity-docker-stable-2.12 SUCCESS in 11m 23s
✔️ ansible-test-sanity-docker-stable-2.13 SUCCESS in 10m 43s
✔️ ansible-test-units-community-aws-python38 SUCCESS in 5m 41s
✔️ ansible-test-units-community-aws-python39 SUCCESS in 6m 32s
✔️ ansible-test-splitter SUCCESS in 2m 37s
⚠️ integration-community.aws-1 SKIPPED
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED

@softwarefactory-project-zuul
Copy link
Contributor

Pull request merge failed: Resource not accessible by integration, You may need to manually rebase your PR and retry.

@tremble tremble merged commit 1be7da1 into ansible-collections:main Jun 30, 2022
@patchback
Copy link

patchback bot commented Jun 30, 2022

Backport to stable-3: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-3/1be7da11d3f4f764372f9de17936e13f04ba66fc/pr-1176

Backported as #1290

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jun 30, 2022
…n var (#1176)

SUMMARY

Fix issue where syntax error is reported if using ssm connection and the target node is located in a different region to the s3 bucket.

Fixes #1190, #637
ISSUE TYPE

    Bugfix Pull Request

COMPONENT NAME

aws_ssm connection plugin
ADDITIONAL INFORMATION

When using SSM for ansible connection and the target node is in a different region to the s3 bucket used, the playbook immediately errors with the following. (There are no issues when both target and s3 bucket are in the same region)

fatal: [i-04444a7f03cc2bffd]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "", "module_stdout": " File \"/tmp/ansible/ansible-tmp-1653576081.8378458-29658-258097978113216/AnsiballZ_setup.py\", line 1\r\r\n <?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\r\n ^\r\r\nSyntaxError: invalid syntax\r\r", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}

The tmp file has the following contents

<?xml version="1.0" encoding="UTF-8"?> <Error><Code>AuthorizationQueryParametersError</Code><Message>Error parsing the X-Amz-Credential parameter; the region 'us-east-1' is wrong; expecting 'eu-west-1'</Message><Region>eu-west-1</Region><RequestId>4VTAGR4C1V9ATBJT</RequestId><HostId>OahjGsFQHlr3ihxobH/yyH7Mzxq98mwjcb6+J3Y2EifDU7FykCe8b6QJTNodIG5WSquVeJF+Zsk=</HostId></Error>

Steps to reproduce: run an ansible playbook using the following:

    aws_ec2 inventory
    aws_ssm connection type
    specify an s3 bucket (ansible_aws_ssm_bucket_name var) that is in a different location to the target node

The presigned url generated includes the region the s3 bucket is in, so this region must be used for the session obtained in the _get_url function.

(cherry picked from commit 1be7da1)
@patchback
Copy link

patchback bot commented Jun 30, 2022

Backport to stable-4: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-4/1be7da11d3f4f764372f9de17936e13f04ba66fc/pr-1176

Backported as #1291

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jun 30, 2022
…n var (#1176)

SUMMARY

Fix issue where syntax error is reported if using ssm connection and the target node is located in a different region to the s3 bucket.

Fixes #1190, #637
ISSUE TYPE

    Bugfix Pull Request

COMPONENT NAME

aws_ssm connection plugin
ADDITIONAL INFORMATION

When using SSM for ansible connection and the target node is in a different region to the s3 bucket used, the playbook immediately errors with the following. (There are no issues when both target and s3 bucket are in the same region)

fatal: [i-04444a7f03cc2bffd]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "", "module_stdout": " File \"/tmp/ansible/ansible-tmp-1653576081.8378458-29658-258097978113216/AnsiballZ_setup.py\", line 1\r\r\n <?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\r\n ^\r\r\nSyntaxError: invalid syntax\r\r", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}

The tmp file has the following contents

<?xml version="1.0" encoding="UTF-8"?> <Error><Code>AuthorizationQueryParametersError</Code><Message>Error parsing the X-Amz-Credential parameter; the region 'us-east-1' is wrong; expecting 'eu-west-1'</Message><Region>eu-west-1</Region><RequestId>4VTAGR4C1V9ATBJT</RequestId><HostId>OahjGsFQHlr3ihxobH/yyH7Mzxq98mwjcb6+J3Y2EifDU7FykCe8b6QJTNodIG5WSquVeJF+Zsk=</HostId></Error>

Steps to reproduce: run an ansible playbook using the following:

    aws_ec2 inventory
    aws_ssm connection type
    specify an s3 bucket (ansible_aws_ssm_bucket_name var) that is in a different location to the target node

The presigned url generated includes the region the s3 bucket is in, so this region must be used for the session obtained in the _get_url function.

(cherry picked from commit 1be7da1)
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Jun 30, 2022
…n var (#1176) (#1291)

[PR #1176/1be7da11 backport][stable-4] ssm connection: pull bucket region info rather than taking from region var

This is a backport of PR #1176 as merged into main (1be7da1).
SUMMARY
Fix issue where syntax error is reported if using ssm connection and the target node is located in a different region to the s3 bucket.
Fixes #1190, #637
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ssm connection plugin
ADDITIONAL INFORMATION
When using SSM for ansible connection and the target node is in a different region to the s3 bucket used, the playbook immediately errors with the following. (There are no issues when both target and s3 bucket are in the same region)
fatal: [i-04444a7f03cc2bffd]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "", "module_stdout": "  File \"/tmp/ansible/ansible-tmp-1653576081.8378458-29658-258097978113216/AnsiballZ_setup.py\", line 1\r\r\n    <?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\r\n    ^\r\r\nSyntaxError: invalid syntax\r\r", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}
The tmp file has the following contents
<?xml version="1.0" encoding="UTF-8"?> <Error><Code>AuthorizationQueryParametersError</Code><Message>Error parsing the X-Amz-Credential parameter; the region 'us-east-1' is wrong; expecting 'eu-west-1'</Message><Region>eu-west-1</Region><RequestId>4VTAGR4C1V9ATBJT</RequestId><HostId>OahjGsFQHlr3ihxobH/yyH7Mzxq98mwjcb6+J3Y2EifDU7FykCe8b6QJTNodIG5WSquVeJF+Zsk=</HostId></Error>
Steps to reproduce: run an ansible playbook using the following:

aws_ec2 inventory
aws_ssm connection type
specify an s3 bucket (ansible_aws_ssm_bucket_name var) that is in a different location to the target node

The presigned url generated includes the region the s3 bucket is in, so this region must be used for the session obtained in the _get_url function.

Reviewed-by: Mark Chappell <None>
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Jun 30, 2022
…n var (#1176) (#1290)

[PR #1176/1be7da11 backport][stable-3] ssm connection: pull bucket region info rather than taking from region var

This is a backport of PR #1176 as merged into main (1be7da1).
SUMMARY
Fix issue where syntax error is reported if using ssm connection and the target node is located in a different region to the s3 bucket.
Fixes #1190, #637
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ssm connection plugin
ADDITIONAL INFORMATION
When using SSM for ansible connection and the target node is in a different region to the s3 bucket used, the playbook immediately errors with the following. (There are no issues when both target and s3 bucket are in the same region)
fatal: [i-04444a7f03cc2bffd]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "", "module_stdout": "  File \"/tmp/ansible/ansible-tmp-1653576081.8378458-29658-258097978113216/AnsiballZ_setup.py\", line 1\r\r\n    <?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\r\n    ^\r\r\nSyntaxError: invalid syntax\r\r", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}
The tmp file has the following contents
<?xml version="1.0" encoding="UTF-8"?> <Error><Code>AuthorizationQueryParametersError</Code><Message>Error parsing the X-Amz-Credential parameter; the region 'us-east-1' is wrong; expecting 'eu-west-1'</Message><Region>eu-west-1</Region><RequestId>4VTAGR4C1V9ATBJT</RequestId><HostId>OahjGsFQHlr3ihxobH/yyH7Mzxq98mwjcb6+J3Y2EifDU7FykCe8b6QJTNodIG5WSquVeJF+Zsk=</HostId></Error>
Steps to reproduce: run an ansible playbook using the following:

aws_ec2 inventory
aws_ssm connection type
specify an s3 bucket (ansible_aws_ssm_bucket_name var) that is in a different location to the target node

The presigned url generated includes the region the s3 bucket is in, so this region must be used for the session obtained in the _get_url function.

Reviewed-by: Mark Chappell <None>
@phene
Copy link
Contributor

phene commented Aug 30, 2022

FYI @JLukeBlakey -- See #1428

@charles-paul-mox
Copy link

Hi @phene - please see this (closed) PR as well: https://github.com/ansible-collections/community.aws/pull/743/files

softwarefactory-project-zuul bot pushed a commit that referenced this pull request Oct 18, 2022
Fix detection of ssm connection bucket region

Fix detection of ssm connection bucket region by ensuring that the boto client is created normally and able to use supported credential sources
SUMMARY
PR #1176 introduced detection of an S3 bucket's region to handle cases where the bucket is in a different region than the SSM connection itself. This change did not use the preferred mechanism for creating client objects, which caused it to not have access to credentials from all supported sources. It also broke the ability to use this plugin in partitions other than aws. (e.g. aws-us-gov).
This change fixes this by building the bucket location client using _get_boto_client and the region for the connection to ensure it is both getting the proper credentials and starting in a region from the same partition as the client itself. From the default global region (or a hard-coded region), it will detect the bucket's region and continue S3 API calls using the bucket's own region.
Fixes bug introduced from #1176
Fixes #1413
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ssm connection plugin

Reviewed-by: Markus Bergholz <git@osuv.de>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: Mark Chappell <None>
patchback bot pushed a commit that referenced this pull request Oct 18, 2022
Fix detection of ssm connection bucket region

Fix detection of ssm connection bucket region by ensuring that the boto client is created normally and able to use supported credential sources
SUMMARY
PR #1176 introduced detection of an S3 bucket's region to handle cases where the bucket is in a different region than the SSM connection itself. This change did not use the preferred mechanism for creating client objects, which caused it to not have access to credentials from all supported sources. It also broke the ability to use this plugin in partitions other than aws. (e.g. aws-us-gov).
This change fixes this by building the bucket location client using _get_boto_client and the region for the connection to ensure it is both getting the proper credentials and starting in a region from the same partition as the client itself. From the default global region (or a hard-coded region), it will detect the bucket's region and continue S3 API calls using the bucket's own region.
Fixes bug introduced from #1176
Fixes #1413
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ssm connection plugin

Reviewed-by: Markus Bergholz <git@osuv.de>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: Mark Chappell <None>
(cherry picked from commit fa58965)
patchback bot pushed a commit that referenced this pull request Oct 18, 2022
Fix detection of ssm connection bucket region

Fix detection of ssm connection bucket region by ensuring that the boto client is created normally and able to use supported credential sources
SUMMARY
PR #1176 introduced detection of an S3 bucket's region to handle cases where the bucket is in a different region than the SSM connection itself. This change did not use the preferred mechanism for creating client objects, which caused it to not have access to credentials from all supported sources. It also broke the ability to use this plugin in partitions other than aws. (e.g. aws-us-gov).
This change fixes this by building the bucket location client using _get_boto_client and the region for the connection to ensure it is both getting the proper credentials and starting in a region from the same partition as the client itself. From the default global region (or a hard-coded region), it will detect the bucket's region and continue S3 API calls using the bucket's own region.
Fixes bug introduced from #1176
Fixes #1413
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ssm connection plugin

Reviewed-by: Markus Bergholz <git@osuv.de>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: Mark Chappell <None>
(cherry picked from commit fa58965)
@demahum
Copy link

demahum commented Nov 2, 2022

Changes here introduced the usage of get_bucket_location.

Is that call too conservative in this case considering that:

To use this implementation of the operation, you must be the bucket owner.

https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLocation.html

softwarefactory-project-zuul bot pushed a commit that referenced this pull request Nov 20, 2022
[PR #1428/fa58965f backport][stable-5] Fix detection of ssm connection bucket region

This is a backport of PR #1428 as merged into main (fa58965).
Fix detection of ssm connection bucket region by ensuring that the boto client is created normally and able to use supported credential sources
SUMMARY
PR #1176 introduced detection of an S3 bucket's region to handle cases where the bucket is in a different region than the SSM connection itself. This change did not use the preferred mechanism for creating client objects, which caused it to not have access to credentials from all supported sources. It also broke the ability to use this plugin in partitions other than aws. (e.g. aws-us-gov).
This change fixes this by building the bucket location client using _get_boto_client and the region for the connection to ensure it is both getting the proper credentials and starting in a region from the same partition as the client itself. From the default global region (or a hard-coded region), it will detect the bucket's region and continue S3 API calls using the bucket's own region.
Fixes bug introduced from #1176
Fixes #1413
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ssm connection plugin

Reviewed-by: Mark Chappell <None>
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Dec 2, 2022
[PR #1428/fa58965f backport][stable-4] Fix detection of ssm connection bucket region

This is a backport of PR #1428 as merged into main (fa58965).
Fix detection of ssm connection bucket region by ensuring that the boto client is created normally and able to use supported credential sources
SUMMARY
PR #1176 introduced detection of an S3 bucket's region to handle cases where the bucket is in a different region than the SSM connection itself. This change did not use the preferred mechanism for creating client objects, which caused it to not have access to credentials from all supported sources. It also broke the ability to use this plugin in partitions other than aws. (e.g. aws-us-gov).
This change fixes this by building the bucket location client using _get_boto_client and the region for the connection to ensure it is both getting the proper credentials and starting in a region from the same partition as the client itself. From the default global region (or a hard-coded region), it will detect the bucket's region and continue S3 API calls using the bucket's own region.
Fixes bug introduced from #1176
Fixes #1413
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ssm connection plugin

Reviewed-by: Mark Chappell <None>
@Hokwang
Copy link

Hokwang commented Jul 19, 2023

This should be roll-back.

  1. get-bucket-location has a problem when bucket is in different region with machine.

  2. and aws recommend use headbucket
    https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLocation.html

@tremble
Copy link
Contributor

tremble commented Jul 19, 2023

@Hokwang ,

Thank you for taking the time to look into this. However, adding a comment to PR that was merged over a year ago generally isn't the best way to raise issues.

get-bucket-location has a problem when bucket is in different region with machine.

If you're seeing a specific issue then please open an Issue and be more specific about what you believe is broken (i.e. error messages, which version of the code you're using, etc). "It has a problem" does nothing to aid in the diagnosis of the issue and if we can't reproduce the issue, we can't test fixes.

and aws recommend use headbucket

This change predated amazon's recommendation by about 9 months. You're welcome to open a PR if you believe you have a better way to handle this.

abikouo pushed a commit to abikouo/community.aws that referenced this pull request Oct 24, 2023
ec2_eip - Remove deprecated instance_id alias

SUMMARY
fixes: ansible-collections#1176
Removes deprecated instance_id alias
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
ec2_eip
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3 PR should be backported to the stable-3 branch backport-4 PR should be backported to the stable-4 branch bug This issue/PR relates to a bug community_review connection connection plugin mergeit Merge the PR (SoftwareFactory) needs_triage new_contributor Help guide this first time contributor plugins plugin (any type)
Projects
None yet
8 participants