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

Use more precise does S3 bucket exist method #34123

Merged
merged 2 commits into from
Sep 28, 2018

Conversation

jasontedor
Copy link
Member

We are using a deprecated method for checking if an S3 bucket exists. This deprecated method has a limitation that it can not distinguish between invalid credentials and a lack of permissions. This commit switches to using a method that correctly surfaces if invalid credentials are supplied when checking for the existence of a bucket.

We are using a deprecated method for checking if an S3 bucket
exists. This deprecated method has a limitation that it can not
distinguish between invalid credentials and a lack of permissions. This
commit switches to using a method that correctly surfaces if invalid
credentials are supplied when checking for the existence of a bucket.
@jasontedor jasontedor added review :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v7.0.0 v6.5.0 labels Sep 27, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

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

I don't think that we can or that we should be doing this change: doesBucketExist() is implemented as a HEAD bucket request while doesBucketExistV2() is implemented as GET bucket acl request, which requires different bucket permissions than what we've been recommending. The reason why doesBucketExistV2() got introduced can be found here. I'm not sure if this is the method that we actually want to check. We are less interested in knowing whether the bucket exists (but we might not be able to access it), but rather interested whether it exists and we can access it. The request to check this is just the plain old headBucket request. If you want to improve this code section, I therefore recommend changing it to a plain clientReference.client().headBucket(new HeadBucketRequest(bucket)), then catch the AmazonServiceException and wrap it with an exception saying something along the lines of bucket does not exist or cannot be accessed, and the more detailed cause will then be provided by the AmazonServiceException.

@jasontedor
Copy link
Member Author

That is a shame, as the Javadocs here indicate that AmazonS3#doesBucketExist is deprecated by AmazonS3#doesBucketExistV2. This was something I noticed while working on #33793. Thanks for digging the extra level @ywelsch.

@tlrx
Copy link
Member

tlrx commented Sep 28, 2018

Two important things:

  • it would have been caught by our third party tests on CI
  • Magic Yannick strikes again, thanks a lot.

@jasontedor
Copy link
Member Author

@ywelsch I pushed.

Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

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

LGTM

@jasontedor jasontedor merged commit 99681f9 into elastic:master Sep 28, 2018
jasontedor added a commit that referenced this pull request Sep 28, 2018
We are using a deprecated method for checking if an S3 bucket
exists. This deprecated method has a limitation that it can not
distinguish between invalid credentials and a lack of permissions. This
commit switches to using a method that correctly surfaces if invalid
credentials are supplied when checking for the existence of a bucket.
@jasontedor jasontedor deleted the does-bucket-exist-v2 branch September 28, 2018 14:10
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Sep 28, 2018
* master:
  Use more precise does S3 bucket exist method (elastic#34123)
  LLREST: Introduce a strict mode (elastic#33708)
  [CCR] Adjust list retryable errors (elastic#33985)
  Fix AggregationFactories.Builder equality and hash regarding order (elastic#34005)
  MINOR: Remove some deadcode in NodeEnv and Related (elastic#34133)
  Rest-Api-Spec: Correct spelling in filter_path description (elastic#33154)
  Core: Don't rely on java time for epoch seconds formatting (elastic#34086)
  Retry errors when fetching follower global checkpoint. (elastic#34019)
  Watcher: Reenable watcher stats REST tests (elastic#34107)
  Remove special-casing of Synonym filters in AnalysisRegistry (elastic#34034)
  Rename CCR APIs (elastic#34027)
  Fixed CCR stats api serialization issues and (elastic#33983)
  Support 'string'-style queries on metadata fields when reasonable. (elastic#34089)
  Logging: Drop Settings from security logger get calls (elastic#33940)
  SQL: Internal refactoring of operators as functions (elastic#34097)
kcm pushed a commit that referenced this pull request Oct 30, 2018
We are using a deprecated method for checking if an S3 bucket
exists. This deprecated method has a limitation that it can not
distinguish between invalid credentials and a lack of permissions. This
commit switches to using a method that correctly surfaces if invalid
credentials are supplied when checking for the existence of a bucket.
ywelsch added a commit that referenced this pull request Nov 26, 2018
This reverts commit da71d66 which breaks compatibility
with our documented IAM policies (see #35703).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >enhancement v6.5.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants