-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
r/aws_s3_bucket: Allow deletion of objects with non-XML-safe bytes in their keys #40537
r/aws_s3_bucket: Allow deletion of objects with non-XML-safe bytes in their keys #40537
Conversation
Community NoteVoting for Prioritization
For Submitters
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome @ravron 👋
It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTOR guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.
Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.
Thanks again, and welcome to the community! 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀.
% make testacc TESTARGS='-run=TestAccS3Bucket_Basic_forceDestroy\|TestAccS3DirectoryBucket_forceDestroy' PKG=s3 ACCTEST_PARALLELISM=3
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.3 test ./internal/service/s3/... -v -count 1 -parallel 3 -run=TestAccS3Bucket_Basic_forceDestroy\|TestAccS3DirectoryBucket_forceDestroy -timeout 360m
2024/12/18 15:57:47 Initializing Terraform AWS Provider...
=== RUN TestAccS3Bucket_Basic_forceDestroy
=== PAUSE TestAccS3Bucket_Basic_forceDestroy
=== RUN TestAccS3Bucket_Basic_forceDestroyWithUnusualKeyBytes
=== PAUSE TestAccS3Bucket_Basic_forceDestroyWithUnusualKeyBytes
=== RUN TestAccS3Bucket_Basic_forceDestroyWithObjectVersions
=== PAUSE TestAccS3Bucket_Basic_forceDestroyWithObjectVersions
=== RUN TestAccS3Bucket_Basic_forceDestroyWithObjectVersionsUnusualKeyBytes
=== PAUSE TestAccS3Bucket_Basic_forceDestroyWithObjectVersionsUnusualKeyBytes
=== RUN TestAccS3Bucket_Basic_forceDestroyWithEmptyPrefixes
=== PAUSE TestAccS3Bucket_Basic_forceDestroyWithEmptyPrefixes
=== RUN TestAccS3Bucket_Basic_forceDestroyWithObjectLockEnabled
=== PAUSE TestAccS3Bucket_Basic_forceDestroyWithObjectLockEnabled
=== RUN TestAccS3DirectoryBucket_forceDestroy
=== PAUSE TestAccS3DirectoryBucket_forceDestroy
=== RUN TestAccS3DirectoryBucket_forceDestroyWithUnusualKeyBytes
=== PAUSE TestAccS3DirectoryBucket_forceDestroyWithUnusualKeyBytes
=== CONT TestAccS3Bucket_Basic_forceDestroy
=== CONT TestAccS3Bucket_Basic_forceDestroyWithEmptyPrefixes
=== CONT TestAccS3Bucket_Basic_forceDestroyWithObjectVersions
--- PASS: TestAccS3Bucket_Basic_forceDestroy (16.17s)
=== CONT TestAccS3Bucket_Basic_forceDestroyWithObjectVersionsUnusualKeyBytes
--- PASS: TestAccS3Bucket_Basic_forceDestroyWithEmptyPrefixes (16.45s)
=== CONT TestAccS3DirectoryBucket_forceDestroy
--- PASS: TestAccS3Bucket_Basic_forceDestroyWithObjectVersions (20.52s)
=== CONT TestAccS3DirectoryBucket_forceDestroyWithUnusualKeyBytes
--- PASS: TestAccS3DirectoryBucket_forceDestroy (14.69s)
=== CONT TestAccS3Bucket_Basic_forceDestroyWithObjectLockEnabled
--- PASS: TestAccS3Bucket_Basic_forceDestroyWithObjectVersionsUnusualKeyBytes (17.80s)
=== CONT TestAccS3Bucket_Basic_forceDestroyWithUnusualKeyBytes
--- PASS: TestAccS3DirectoryBucket_forceDestroyWithUnusualKeyBytes (14.24s)
--- PASS: TestAccS3Bucket_Basic_forceDestroyWithUnusualKeyBytes (14.33s)
--- PASS: TestAccS3Bucket_Basic_forceDestroyWithObjectLockEnabled (18.77s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/s3 55.276s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
@ravron Thanks for the contribution 🎉 👏. |
This functionality has been released in v5.82.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Description
This PR teaches
aws_s3_bucket
andaws_s3_directory_bucket
to handle non-XML-safe characters in object keys when emptying bucket contents on destroy becauseforce_destroy
is true. This PR addresses #40489, which contains more details on the issue, its cause, and the resolution.The fundamental problem is that S3 object keys can contain any Unicode characters, but XML cannot encode all Unicode characters (see section 2.2 of the XML spec for allowed characters). For example, U+10 is a disallowed character. As a result, ListObjectVersions can return XML containing disallowed characters when listing objects whose keys themselves contain those characters, and the AWS Go SDK correctly refuses to parse the XML.
This is a well-known issue; see the references. The solution is to tell ListObjectVersions to URL-encode returned keys, which is easily done by setting EncodingType: types.EncodingTypeUrl, then URL-decode the keys on the client side. This works, but causes a new issue: DeleteObjectVersions will silently fail to delete any object whose key contains these invalid characters. This is because DeleteObjectVersions uses an XML request body, and Go will replace invalid characters with � (U+FFFD, the replacement character) in the request body.
This PR modifies several functions in
internal/service/s3/delete.go
with two goals:While here, I consolidated the implementations of
deletePageOfObjectVersions
,deletePageOfDeleteMarkers
, anddeletePageOfObjects
.Relations
Closes #40489.
References
Here are some issues about the challenges of listing and bulk-deleting objects whose keys contain non-XML-safe characters:
Output from Acceptance Testing