-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Allow to specify the STS endpoint for hive connector on S3 #10169
Allow to specify the STS endpoint for hive connector on S3 #10169
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@trino.io. For more information, see https://github.com/trinodb/cla. |
313534c
to
a998448
Compare
Can you please explain what is the use case for this? Also how have you tested it? |
The use case for this is using a third-party s3 / AWS service provider such as minio in your setup, but still depending on STS to get temporary credentials. |
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@trino.io. For more information, see https://github.com/trinodb/cla. |
b769fc6
to
2470411
Compare
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@trino.io. For more information, see https://github.com/trinodb/cla. |
1f25ab3
to
05710de
Compare
AWSSecurityTokenServiceClientBuilder stsClientBuilder = | ||
AWSSecurityTokenServiceClientBuilder.standard() | ||
.withCredentials(provider); | ||
stsClientBuilder.withEndpointConfiguration( |
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.
If stsRegionOverwrite
is set but stsEndpointOverwrite
is not it looks like we want to call stsClientBuilder.withRegion
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.
Good point, I will update that
String stsEndpointOverwrite = conf.get(STS_ENDPOINT); | ||
String stsRegionOverwrite = conf.get(STS_REGION); | ||
|
||
if (stsEndpointOverwrite != null && stsRegionOverwrite != null) { |
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.
if (stsEndpointOverwrite != null && stsRegionOverwrite != null) { | |
if (!isNullOrEmpty(stsEndpointOverwrite)l && !isNullOrEmpty(stsRegionOverwrite)) { |
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.
Looks good, I will update that
.withExternalId(externalId) | ||
.withLongLivedCredentialsProvider(provider) | ||
.build(); | ||
String stsEndpointOverwrite = conf.get(STS_ENDPOINT); |
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.
I'd format this block a bit differently, withLongLivedCredentialsProvider
is also deprecated so using AWSSecurityTokenServiceClientBuilder
is preferred in all cases:
String stsEndpointOverwrite = conf.get(STS_ENDPOINT);
String stsRegionOverwrite = conf.get(STS_REGION);
AWSSecurityTokenServiceClientBuilder stsClient = ...
.withCredentials(provider);
if (<both overrides are set>) {
stsClient.withEndpointConfiguration(...);
}
else if (<region is set>) {
stsClient.withRegion(...);
}
provider = new STSAssumeRoleSessionCredentialsProvider.Builder(iamRole, "trino-session")
.with(<all the common properties>);
.withStsClient(stsClient.build())
.build();
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.
I thought the same and wanted to get rid of the deprecated withLongLivedCredentialsProvider
as well, but that resulted in errors in TrinoS3FileSystemTest
: com.amazonaws.SdkClientException: Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region.
So the question is: fix the tests setup or stay with the deprecated method (or use a option I have not thought of) ?
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.
You probably need to use the default region provider chain, and if that comes up empty use us-east-1
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.
Good point, I updated the PR accordingly
@alexjo2144 thank you very much for your review. I will try to update the PR tomorrow based on your suggestions and I am looking forward to your answer to my question. |
bfce7ca
to
f079163
Compare
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@trino.io. For more information, see https://github.com/trinodb/cla. |
9bd1c9a
to
4f3515d
Compare
@alexjo2144 @electrum @kokosing hey guys, I hope you had a fantastic Christmas time and started well in the new year 2022. Would be great if you would find the time to check this PR again since all of the checks are passing now. Thank you! |
final String defaultRegion = "us-east-1"; | ||
log.debug("Falling back to default AWS region " + defaultRegion); | ||
stsClientBuilder.withRegion(defaultRegion); |
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.
I think we should throw here instead hard-coding failover to us-east-1
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.
Thank you for looking into the PR. Your review directly contradicts @alexjo2144 's review comment earlier on, unfortunately. I am really okay with both, I would just like to know which way to take to get this PR approved.
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.
For what it's worth, we default to us-east-1 when creating the AmazonS3
client object: https://github.com/trinodb/trino/blob/master/plugin/trino-hive/src/main/java/io/trino/plugin/hive/s3/TrinoS3FileSystem.java#L885
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.
fair :)
public static final String STS_ENDPOINT = "trino.sts.endpoint"; | ||
public static final String STS_REGION = "trino.sts.region"; |
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.
As these are used only for accessing S3 I would use trino.s3.sts.endpoint/region
. And S3_STS_* as constant names.
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.
Makes sense to me, will update as soon as I know how to proceed regarding your first comment.
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@trino.io. For more information, see https://github.com/trinodb/cla. |
3be751b
to
203a634
Compare
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@trino.io. For more information, see https://github.com/trinodb/cla. |
fbea926
to
c8f6b6f
Compare
String stsEndpointOverwrite = conf.get(S3_STS_ENDPOINT); | ||
String stsRegionOverwrite = conf.get(S3_STS_REGION); |
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.
nit: Overwrite -> Override
region = regionProviderChain.getRegion(); | ||
} | ||
catch (SdkClientException ex) { | ||
log.debug("Falling back to default AWS region " + US_EAST_1); |
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.
log as WARN
LGTM. @clemensvonschwerin did you have a chance to test it. I do not belive it is covered with automated tests. |
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.
Mostly style nits, one real question.
@losipiuk This needs a Trino based mirror PR to run the S3 tests right?
AWSSecurityTokenServiceClientBuilder stsClientBuilder = | ||
AWSSecurityTokenServiceClientBuilder.standard() | ||
.withCredentials(provider); |
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.
You can inline the first two lines
AWSSecurityTokenServiceClientBuilder stsClientBuilder = | |
AWSSecurityTokenServiceClientBuilder.standard() | |
.withCredentials(provider); | |
AWSSecurityTokenServiceClientBuilder stsClientBuilder = AWSSecurityTokenServiceClientBuilder.standard() | |
.withCredentials(provider); |
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.
I'd also move this down to right before it's used
DefaultAwsRegionProviderChain regionProviderChain = | ||
new DefaultAwsRegionProviderChain(); |
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.
No need to wrap this line
DefaultAwsRegionProviderChain regionProviderChain = | |
new DefaultAwsRegionProviderChain(); | |
DefaultAwsRegionProviderChain regionProviderChain = new DefaultAwsRegionProviderChain(); |
stsClientBuilder.withEndpointConfiguration( | ||
new EndpointConfiguration(stsEndpointOverwrite, region)); |
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.
Here too
stsClientBuilder.withEndpointConfiguration( | |
new EndpointConfiguration(stsEndpointOverwrite, region)); | |
stsClientBuilder.withEndpointConfiguration(new EndpointConfiguration(stsEndpointOverwrite, region)); |
@@ -973,9 +979,40 @@ private AWSCredentialsProvider createAwsCredentialsProvider(URI uri, Configurati | |||
.orElseGet(DefaultAWSCredentialsProviderChain::getInstance); | |||
|
|||
if (iamRole != null) { | |||
String stsEndpointOverwrite = conf.get(S3_STS_ENDPOINT); |
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.
I'm not super familiar with the need for STS region/endpoint overrides. Is it only ever useful when an IAM role is used, or could it also be used without a role?
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.
Since STS service is used to assume a specific IAM role and get temporary credentials for that role I do not see any use case without setting an IAM role.
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@trino.io. For more information, see https://github.com/trinodb/cla. |
ef3a4b7
to
3caac54
Compare
So an older version of this PR has been running on our dev and production trino instances for a while and works without issues. The combination of Trino and S3 & STS on Minio for our dev systems is possible that way. |
f2be8c9
to
075e504
Compare
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.
@clemensvonschwerin Please also add documentation to hive-s3.rst
075e504
to
9905c4c
Compare
@losipiuk sure, I updated |
No. other than that I think it is good to go. But please fix the doc error :) |
9905c4c
to
3d2bbc7
Compare
I updated myself - lets wait for CI. |
3d2bbc7
to
f500388
Compare
f500388
to
0d66aa4
Compare
Description
Allow to specify the STS endpoint for hive connector on S3
Improvement.
Hive/Iceberg/Delta connectors
Allow to specify the STS endpoint for hive connector on S3
Documentation
(x) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.
Release notes
() No release notes entries required.
(x) Release notes entries required with the following suggested text: