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

Ensure necessary security context for s3 bulk deletions #108280

Merged

Conversation

ywangd
Copy link
Member

@ywangd ywangd commented May 4, 2024

This PR moves the doPrivileged wrapper closer to the actual deletion request to ensure the necesary security context is established at all times. Also added a new repository setting to configure max size for s3 deleteObjects request.

Fixes: #108049

This PR moves the doPrivileged wrapper closer to the actual deletion
request to ensure the necesary security context is established at all
times.

Resolves: elastic#108049
@ywangd ywangd added >bug :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v8.14.0 labels May 4, 2024
@ywangd ywangd requested review from arteam and DaveCTurner May 4, 2024 13:10
Copy link

github-actions bot commented May 4, 2024

Documentation preview:

@elasticsearchmachine
Copy link
Collaborator

Hi @ywangd, I've created a changelog YAML for you.

@elasticsearchmachine elasticsearchmachine added the Team:Distributed Meta label for distributed team label May 4, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

.put("client", "repo_test_kit")
.put("bucket", bucket)
.put("base_path", basePath)
.put("deletion_batch_size", between(1, 1000))
Copy link
Member Author

Choose a reason for hiding this comment

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

I took the easy way to piggyback on the existing repo analysis test. Please let me know if this works for you. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 should be fine, but could you just confirm that this exposes the bug?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I tested locally with real s3 by setting the properties listed here. I can confirm the test can fail without the fix.

A few notes:

  1. It does not fail with the fixture. I wonder whether it has something to do with the fixture running on localhost.
  2. When the size is 1, it will fail at repo verification without even start running the test.
  3. I expected it to fail anytime the deletion is done inside the lambda but that is not always the case. I guess maybe if there is existing connection to perform the deletion request, it does not trigger the permission check. I did not look into it deeply since it feels sufficient to me that it does fail sometimes without the fix.

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

Couple of nits, overall looks great tho. WDYT about backporting all the way to 8.13? I think there'll be another release before 8.14, would be good to fix this ASAP.

* The batch size for bulk deletion
*/
static final Setting<Integer> DELETION_BATCH_SIZE_SETTING = Setting.intSetting(
"deletion_batch_size",
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming nit/suggestion: WDYT about delete_objects_max_size? The relevant S3 API is called DeleteObjects so I think mentioning that in the name would be helpful.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good to me. Updated it as you suggested 61255e5

.put("client", "repo_test_kit")
.put("bucket", bucket)
.put("base_path", basePath)
.put("deletion_batch_size", between(1, 1000))
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 should be fine, but could you just confirm that this exposes the bug?

@ywangd ywangd added v8.13.4 auto-backport-and-merge Automatically create backport pull requests and merge when ready labels May 6, 2024
@ywangd
Copy link
Member Author

ywangd commented May 6, 2024

WDYT about backporting all the way to 8.13? I think there'll be another release before 8.14, would be good to fix this ASAP.

I agree. Added v8.13.4. Thanks!

@ywangd ywangd requested a review from DaveCTurner May 6, 2024 02:51
Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticsearchmachine
Copy link
Collaborator

Hi @ywangd, I've updated the changelog YAML for you.

@ywangd ywangd added the auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label May 6, 2024
@elasticsearchmachine
Copy link
Collaborator

Hi @ywangd, I've updated the changelog YAML for you.

@ywangd ywangd removed the auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label May 6, 2024
Copy link
Contributor

@arteam arteam left a comment

Choose a reason for hiding this comment

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

LGTM2

@DaveCTurner DaveCTurner added the auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label May 6, 2024
@ywangd
Copy link
Member Author

ywangd commented May 6, 2024

@elasticmachine update branch

@elasticsearchmachine elasticsearchmachine merged commit bcf4297 into elastic:main May 6, 2024
15 checks passed
@ywangd ywangd deleted the es-108049-fix-s3-access-control branch May 6, 2024 10:02
ywangd added a commit to ywangd/elasticsearch that referenced this pull request May 6, 2024
This PR moves the doPrivileged wrapper closer to the actual deletion
request to ensure the necesary security context is established at all
times. Also added a new repository setting to configure max size for s3
deleteObjects request.

Fixes: elastic#108049
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.14
8.13 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 108280

@ywangd
Copy link
Member Author

ywangd commented May 6, 2024

💚 All backports created successfully

Status Branch Result
8.13

Questions ?

Please refer to the Backport tool documentation

ywangd added a commit to ywangd/elasticsearch that referenced this pull request May 6, 2024
This PR moves the doPrivileged wrapper closer to the actual deletion
request to ensure the necesary security context is established at all
times. Also added a new repository setting to configure max size for s3
deleteObjects request.

Fixes: elastic#108049
(cherry picked from commit bcf4297)

# Conflicts:
#	docs/reference/snapshot-restore/repository-s3.asciidoc
#	modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobStore.java
elasticsearchmachine pushed a commit that referenced this pull request May 6, 2024
…08298)

This PR moves the doPrivileged wrapper closer to the actual deletion
request to ensure the necesary security context is established at all
times. Also added a new repository setting to configure max size for s3
deleteObjects request.

Fixes: #108049
elasticsearchmachine pushed a commit that referenced this pull request May 6, 2024
…08299)

This PR moves the doPrivileged wrapper closer to the actual deletion
request to ensure the necesary security context is established at all
times. Also added a new repository setting to configure max size for s3
deleteObjects request.

Fixes: #108049
(cherry picked from commit bcf4297)

# Conflicts:
#	docs/reference/snapshot-restore/repository-s3.asciidoc
#	modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobStore.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-and-merge Automatically create backport pull requests and merge when ready auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) backport pending >bug :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed Meta label for distributed team v8.13.4 v8.14.0 v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deleting files in s3 buckets can trip AccessControlException
5 participants