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

s3_bucket.destroy_bucket fails to delete unversioned items #1533

Closed
1 task done
evohnave opened this issue May 8, 2023 · 3 comments · Fixed by #1538
Closed
1 task done

s3_bucket.destroy_bucket fails to delete unversioned items #1533

evohnave opened this issue May 8, 2023 · 3 comments · Fixed by #1538
Labels
waiting_on_contributor Needs help. Feel free to engage to get things unblocked

Comments

@evohnave
Copy link
Contributor

evohnave commented May 8, 2023

Summary

aws s3_client.list_object_versions() now (at least as of boto3 1.26.129) returns "VersionId": "null" for those objects that have no versions. Per the code in s3_bucket.destroy_bucket (lines 1161-1167) previously it did not return a "VersionId" if there was no versioning and so it popped those None values. With these "null" values, s3_client.delete_objects (line 1170) is failing on "Permission Denied". Deletes without the "VersionId" keys work.

Recommend the following change to those lines (comments omitted):

for fk in formatted_keys:  
  if not fk.get("VersionId") or fk.get("VersionId") == "null":  
    fk.pop("VersionId")

Issue Type

Bug Report

Component Name

s3_bucket.destroy_bucket

Ansible Version

$ ansible --version

not applicable

Collection Versions

$ ansible-galaxy collection list

AWS SDK versions

$ pip show boto boto3 botocore

WARNING: Package(s) not found: boto
Name: boto3
Version: 1.24.28
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: c:\users\administrator\anaconda3\lib\site-packages
Requires: botocore, jmespath, s3transfer
Required-by:

Name: botocore
Version: 1.27.28
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: c:\users\administrator\anaconda3\lib\site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer

Configuration

$ ansible-config dump --only-changed

not applicable - transcribing from an isolated system.

OS / Environment

CENTOS 7

Steps to Reproduce

- name: Remove buckets
  tags: s3, aws_resources
  s3_bucket:
    name: "my_bucket_with_objects_with_no_versioning"
    state: absent
    force: yes

Expected Results

I expected all objects in the bucket to get deleted, but they did not since there was no versioning applied.

Actual Results

The bucket does not get deleted since the objects in it remained.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@alinabuzachis
Copy link
Collaborator

@evohnave Thank you for raising this. Would you be willing to open a Pull Request with a patch.

@alinabuzachis alinabuzachis added waiting_on_contributor Needs help. Feel free to engage to get things unblocked and removed needs_triage labels May 9, 2023
@evohnave
Copy link
Contributor Author

evohnave commented May 9, 2023

@alinabuzachis I'm willing, but gotta tell you that I've promised to do this sort of thing to other open source projects and never gotten around to it. I will try to get to it tonight.

@evohnave
Copy link
Contributor Author

Pull request #1538 submitted.

softwarefactory-project-zuul bot pushed a commit that referenced this issue May 11, 2023
s3_bucket: fix VersionId==null when s3 object not versioned

SUMMARY

Boto3 1.26.129 (possibly earlier) returns "VersionId": "null" from s3_client.list_object_versions() when s3 objects are not versioned.  Previously, "VersionId" was None when an s3 object was not versioned.  This change broke s3_bucket.destroy_bucket() because the the VersionId was no longer popped (line 1166) when the s3 object was not versioned, and the subsequent attempts to delete the s3 object failed as the "VersionId" was absolutely not "null".  Adding in `or fk.get("VersionId")=="null" will catch this new value for non-versioned s3 objects while allowing backwards compatibility with previous versions that return None for "VersionId".

Fixes #1533 s3_bucket.destroy_bucket fails to delete unversioned items
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

s3_bucket.py
ADDITIONAL INFORMATION



Ensure that there is an s3 bucket with objects in it



name: Remove buckets
s3_bucket:
name: "my_bucket_with_objects_with_no_versioning"
state: absent
force: yes

Reviewed-by: Mark Chappell
patchback bot pushed a commit that referenced this issue May 11, 2023
s3_bucket: fix VersionId==null when s3 object not versioned

SUMMARY

Boto3 1.26.129 (possibly earlier) returns "VersionId": "null" from s3_client.list_object_versions() when s3 objects are not versioned.  Previously, "VersionId" was None when an s3 object was not versioned.  This change broke s3_bucket.destroy_bucket() because the the VersionId was no longer popped (line 1166) when the s3 object was not versioned, and the subsequent attempts to delete the s3 object failed as the "VersionId" was absolutely not "null".  Adding in `or fk.get("VersionId")=="null" will catch this new value for non-versioned s3 objects while allowing backwards compatibility with previous versions that return None for "VersionId".

Fixes #1533 s3_bucket.destroy_bucket fails to delete unversioned items
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

s3_bucket.py
ADDITIONAL INFORMATION

Ensure that there is an s3 bucket with objects in it

name: Remove buckets
s3_bucket:
name: "my_bucket_with_objects_with_no_versioning"
state: absent
force: yes

Reviewed-by: Mark Chappell
(cherry picked from commit 94bb14c)
softwarefactory-project-zuul bot pushed a commit that referenced this issue May 11, 2023
…1545)

[PR #1538/94bb14c2 backport][stable-6] s3_bucket: fix VersionId==null when s3 object not versioned

This is a backport of PR #1538 as merged into main (94bb14c).
SUMMARY

Boto3 1.26.129 (possibly earlier) returns "VersionId": "null" from s3_client.list_object_versions() when s3 objects are not versioned.  Previously, "VersionId" was None when an s3 object was not versioned.  This change broke s3_bucket.destroy_bucket() because the the VersionId was no longer popped (line 1166) when the s3 object was not versioned, and the subsequent attempts to delete the s3 object failed as the "VersionId" was absolutely not "null".  Adding in `or fk.get("VersionId")=="null" will catch this new value for non-versioned s3 objects while allowing backwards compatibility with previous versions that return None for "VersionId".

Fixes #1533 s3_bucket.destroy_bucket fails to delete unversioned items
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

s3_bucket.py
ADDITIONAL INFORMATION



Ensure that there is an s3 bucket with objects in it



name: Remove buckets
s3_bucket:
name: "my_bucket_with_objects_with_no_versioning"
state: absent
force: yes

Reviewed-by: Mark Chappell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting_on_contributor Needs help. Feel free to engage to get things unblocked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants