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

fix(s3): bucket deletion fails if object creation races against cleanup #26875

Merged
merged 19 commits into from
Sep 28, 2023

Conversation

miles-po
Copy link
Contributor

@miles-po miles-po commented Aug 24, 2023

Adds a DENY policy for S3:PutObject on buckets to be auto-deleted to prevent a race condition on emptying with external bucket writers.

As a new contributor, the requirements for integration testing were unclear to me. I have tested the policy on my own buckets and included unit tests, but am willing to work toward code compliance with assistance.

Closes #26874.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added bug This issue is a bug. p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Aug 24, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team August 24, 2023 19:43
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@miles-po miles-po changed the title Prevent bucket writes on stack deletion fix: prevent further bucket writes on stack deletion Aug 24, 2023
@miles-po
Copy link
Contributor Author

Clarification Request: As a new contributor, the requirements for integration testing were unclear to me. I have tested the policy on my own buckets and included unit tests, but am willing to work toward code compliance with assistance.

@aws-cdk-automation aws-cdk-automation added the pr/reviewer-clarification-requested The contributor has requested clarification on feedback, a failing build, or a failing PR Linter run label Aug 24, 2023
@miles-po miles-po changed the title fix: prevent further bucket writes on stack deletion fix(auto-delete-object-handlers): prevent further bucket writes on stack deletion Aug 24, 2023
@rix0rrr
Copy link
Contributor

rix0rrr commented Aug 25, 2023

This document should be mostly accurate explaining what they are and how they should be run.

You don't need to add a new one, but you probably will need to update some existing snapshots. You'll need AWS account credentials to run the actual tests in.

The tests are in packages/@aws-cdk-testing/framework-integ these days.

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@mrgrain
Copy link
Contributor

mrgrain commented Sep 19, 2023

@miles-po Thanks for this! Are you still interested in wrapping this up? If you can get the unit tests passing and update the integration test snapshots with --dry-run, that'd be great. Once that's done I can verify for you that the integ tests are working and get it shipped.

@miles-po
Copy link
Contributor Author

Family's been ill, so I've been playing catch-up. I started working on it again late yesterday. Was hoping to finish up today.

@miles-po
Copy link
Contributor Author

@mrgrain I added some fixes including unit test repair. I keep getting an integration test failure in the cdk-s3-bucket-auto-delete-objects stack. I obviously can't rule out user error, but looking back at the code, I can't find why my additions would cause a missing bucket error. Would appreciate any help I can get as I fear I've taken it as far as I know how in this codebase.

Screenshot 2023-09-19 at 12 36 00

@miles-po
Copy link
Contributor Author

And after fixing one set of unit tests, I broke another. Lemme fix that before I ask for more help. (Oops!)

@miles-po
Copy link
Contributor Author

@mrgrain Made my fixes. Appears to me the only failures are now snapshot failures. Been trying to get the integration tests to work in a sandbox account, following the contributors instructions as close as I know how, but nothing I try seems to work. If they work for you, I owe you a beverage of your choice for getting the snapshots to work. If not, I'm here to help with the code debugging process and answer any questions I can.

@miles-po
Copy link
Contributor Author

@mrgrain I didn't run --dry-run because the contributing instructions specifically said:

If you are working on a PR that requires an update to an integration test and you are unable to run the cdk-integ tool to perform a real deployment, please call this out on the pull request so a maintainer can run the tests for you. Please do not run the cdk-integ tool with --dry-run or manually update the snapshot.

@mrgrain mrgrain added pr-linter/do-not-close The PR linter will not close this PR while this label is present and removed closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. no-autoclose labels Sep 25, 2023
@mrgrain mrgrain reopened this Sep 25, 2023
@rix0rrr rix0rrr added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Sep 27, 2023
rix0rrr
rix0rrr previously approved these changes Sep 27, 2023
@rix0rrr rix0rrr changed the title fix(auto-delete-object-handlers): prevent further bucket writes on stack deletion fix(s3): bucket deletion can fail if an object gets written just after cleanup Sep 27, 2023
@rix0rrr rix0rrr changed the title fix(s3): bucket deletion can fail if an object gets written just after cleanup fix(s3): bucket deletion fails if an object gets written just after cleanup Sep 27, 2023
@rix0rrr rix0rrr changed the title fix(s3): bucket deletion fails if an object gets written just after cleanup fix(s3): bucket deletion fails if object creation races against cleanup Sep 27, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 27, 2023 11:33

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@mergify
Copy link
Contributor

mergify bot commented Sep 27, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@miles-po
Copy link
Contributor Author

@mrgrain @rix0rrr Thank you both so much for pushing this through!

@mergify mergify bot dismissed rix0rrr’s stale review September 28, 2023 07:58

Pull request has been modified.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 28, 2023
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 28, 2023
@mergify
Copy link
Contributor

mergify bot commented Sep 28, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: a4d1cee
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 735b786 into aws:main Sep 28, 2023
9 checks passed
@mergify
Copy link
Contributor

mergify bot commented Sep 28, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p1 pr-linter/do-not-close The PR linter will not close this PR while this label is present pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@aws-cdk: S3 buckets block stack deletion
4 participants