-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
s3_object: Add parameter
acl_disabled
to handle uploading files to …
…buckets with ACL disabled. (#921) s3_object: Add parameter `acl_disabled` to handle uploading files to buckets with ACL disabled. SUMMARY Fixes #863 [Update: 07/07/2022] https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.get_bucket_ownership_controls can be used to determine if ACL is disabled or not. Modified code to convert acl_disabled from a user input parameter to a variable used for testing if ACL is enabled/disabled. Add parameter acl_disabled to handle uploading files to buckets with ACL disabled. If set to true, all the permission related operations are skipped in module code. ISSUE TYPE Bugfix Pull Request COMPONENT NAME s3_object ADDITIONAL INFORMATION AWS added the option to create S3 bucket with ACL Disabled in Nov 2021) and made it the default/suggested setting when creating S3 bucket through AWS Portal . Currently the ACL "permission" parameter defaults to ["private"] and there is no way to tell the s3_object module to omit the ACL setting while uploading files to a bucket which has set the ACL as disabled. Tried looking for a way to get the existing bucket info to determine if 'ACL' is enabled/disabled, but was not able to find what I was looking for in API documentation. Reviewed-by: Alina Buzachis <None> Reviewed-by: Jill R <None> Reviewed-by: Mark Chappell <None> Reviewed-by: Mandar Kulkarni <[email protected]>
- Loading branch information
Showing
5 changed files
with
184 additions
and
53 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
changelogs/fragments/921-s3_object-handle-file-upload-to-acl-disabled-bucket.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- s3_object - updated module to add support for handling file upload to a bucket with ACL disabled (https://github.com/ansible-collections/amazon.aws/pull/921). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dependencies: | ||
- setup_remote_tmp_dir |
111 changes: 111 additions & 0 deletions
111
tests/integration/targets/s3_object/tasks/copy_object_acl_disabled_bucket.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
- name: test copying objects to bucket with ACL disabled | ||
block: | ||
- name: Create a bucket with ACL disabled for the test | ||
s3_bucket: | ||
name: "{{ bucket_name }}-acl-disabled" | ||
object_ownership: BucketOwnerEnforced | ||
state: present | ||
register: create_result | ||
|
||
- name: Ensure bucket creation | ||
assert: | ||
that: | ||
- create_result is changed | ||
- create_result is not failed | ||
- create_result.object_ownership == "BucketOwnerEnforced" | ||
|
||
- name: Create content | ||
set_fact: | ||
content: "{{ lookup('password', '/dev/null chars=ascii_letters,digits,hexdigits,punctuation') }}" | ||
|
||
- name: Create local acl_disabled_upload_test.txt | ||
copy: | ||
content: "{{ content }}" | ||
dest: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
|
||
- name: Upload a file to the bucket (check_mode) | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}-acl-disabled" | ||
src: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
object: "acl_disabled_upload_test.txt" | ||
mode: put | ||
check_mode: true | ||
register: upload_file_result | ||
|
||
- assert: | ||
that: | ||
- upload_file_result is changed | ||
- upload_file_result is not failed | ||
- upload_file_result.msg == "PUT operation skipped - running in check mode" | ||
- '"s3:PutObject" not in upload_file_result.resource_actions' | ||
|
||
- name: Upload a file to the bucket | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}-acl-disabled" | ||
src: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
object: "acl_disabled_upload_test.txt" | ||
mode: put | ||
register: upload_file_result | ||
|
||
- assert: | ||
that: | ||
- upload_file_result is changed | ||
- upload_file_result is not failed | ||
- upload_file_result.msg == "PUT operation complete" | ||
- '"s3:PutObject" in upload_file_result.resource_actions' | ||
|
||
- name: Upload a file to the bucket (check_mode - idempotency) | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}-acl-disabled" | ||
src: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
object: "acl_disabled_upload_test.txt" | ||
mode: put | ||
check_mode: true | ||
register: upload_file_result | ||
|
||
- assert: | ||
that: | ||
- upload_file_result is not changed | ||
- upload_file_result is not failed | ||
- upload_file_result.msg != "PUT operation complete" | ||
- '"s3:PutObject" not in upload_file_result.resource_actions' | ||
|
||
- name: Upload a file to the bucket (idempotency) | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}-acl-disabled" | ||
src: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
object: "acl_disabled_upload_test.txt" | ||
mode: put | ||
register: upload_file_result | ||
|
||
- assert: | ||
that: | ||
- upload_file_result is not changed | ||
- upload_file_result is not failed | ||
- upload_file_result.msg != "PUT operation complete" | ||
- '"s3:PutObject" not in upload_file_result.resource_actions' | ||
|
||
always: | ||
|
||
- name: Delete the file in the bucket | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}-acl-disabled" | ||
src: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
object: "acl_disabled_upload_test.txt" | ||
mode: delobj | ||
retries: 3 | ||
delay: 3 | ||
ignore_errors: true | ||
|
||
- name: Delete bucket created in this test | ||
s3_bucket: | ||
name: "{{ bucket_name }}-acl-disabled" | ||
object_ownership: BucketOwnerEnforced | ||
state: absent | ||
register: delete_result | ||
|
||
- name: Ensure bucket deletion | ||
assert: | ||
that: | ||
- delete_result is changed | ||
- delete_result is not failed |
Oops, something went wrong.