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

aws-s3: option for Bucket.grantDelete to not grant s3:DeleteObjectVersion #32375

Open
2 tasks
plumdog opened this issue Dec 3, 2024 · 3 comments
Open
2 tasks
Labels
@aws-cdk/aws-s3 Related to Amazon S3 effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@plumdog
Copy link
Contributor

plumdog commented Dec 3, 2024

Describe the feature

Allow an easy way of granting an identity permission to modify the contents of a versioned bucket, but not delete versions.

Use Case

I want to be able to grant applications permissions to modify objects in a bucket as they need to, but want be sure that they won't permanently delete data. Enabling versioning on the bucket allows this, but if the applications are granted s3:DeleteObjectVersion then a bug or compromise of that application could still delete all data from the bucket including previous versions.

I think this one of the natural uses of S3 versioning, and so the CDK making it easy to grant a suitable set of permissions for this would be helpful.

Proposed Solution

Perhaps add an option like exceptVersions: boolean to Bucket.grantDelete. Or maybe add a new method.

Other Information

There might already be an easy way to do this with the other Bucket.grant* methods, eg with Bucket.grantWrite and passing some values from https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-s3/lib/perms.ts as the third argument.

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.171.1

Environment details (OS name and version, etc.)

n/a

@plumdog plumdog added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 3, 2024
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Dec 3, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 3, 2024
@khushail khushail self-assigned this Dec 3, 2024
@khushail
Copy link
Contributor

khushail commented Dec 3, 2024

Hi @plumdog , thanks for reaching out. just curious to understand your usecase, wouldn't it be feasbile using granting write access so user can modify the objects -Bucket.grant* and denying the access like this -

{
      "Sid": "statement2",
      "Effect": "Deny",
      "Principal": {
        "AWS": "arn:aws:iam::123456789012:user/abcd"
      },
      "Action": [
        "s3:DeleteObject",
        "s3:DeleteObjectVersion",
        "s3:PutLifecycleConfiguration"
      ],
      "Resource": [
        "arn:aws:s3:::amzn-s3-demo-bucket1",
	    "arn:aws:s3:::amzn-s3-demo-bucket1/*"
      ]
    }

Please feel free to correct me if this understanding is wrong.

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Dec 3, 2024
@plumdog
Copy link
Contributor Author

plumdog commented Dec 4, 2024

Hi @khushail, in principle I think there could be a way to add a deny for s3:DeleteObjectVersion, though it is perhaps simplest to just not grant the permission at all, rather than grant it and then also deny it. And I don't see any methods like Bucket.deny*` that would do this easily in CDK. Are you able to show how this could be done using CDK?

Regarding your example, I think I would still need for applications to have s3:DeleteObject as I just want to ensure they are not able to permanently delete data from the bucket, they should still be able to create delete markers. And it doesn't look like any of the Bucket.grant* methods grant s3:PutLifecycleConfiguration anyway, so I don't think that would need to be denied.

Ideally, I would identify a simple way of achieving this that I can advertise internally as the correct way of granting applications access to manage data within buckets. And so something like:

always enable bucket versioning and grant applications permissions using myBucket.grantReadWrite(myRole, ['*'], { exceptVersions: true })

would work for this. Something requiring developers to add a policy would introduce more room for error which I would like to avoid if possible.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 4, 2024
@khushail
Copy link
Contributor

khushail commented Dec 5, 2024

Thanks for getting back and explaining your point of view in this context @plumdog . I totally understand your point when assigning the access and then denying it would be extra hassle and would leave markers and chance of error as well. Since there is no policy as Bucket.Deny*, IMO , your suggestion to exclude versioned buckets is more appealing and makes sense. Marking it as P2 as this is a good to have feature and P2 would mean it won't be immediately addressed by the team however it would be on their radar and also contributions from the community are welcome in this regard.

@khushail khushail added the effort/medium Medium work item – several days of effort label Dec 5, 2024
@khushail khushail removed their assignment Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants