forked from apache/hadoop
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Vyu/tdi 43726 upgrade hadoop for s3 #4
Open
vyu-talend
wants to merge
6
commits into
tlnd-2.7.3.3-SNAPSHOT
Choose a base branch
from
vyu/tdi-43726_upgrade_hadoop_for_S3
base: tlnd-2.7.3.3-SNAPSHOT
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ff6a634
feat(tdi-43726):upgrade hadoop for s3/tpd.
582568a
feat(tdi-43726):upgrade hadoop for s3/tpd.
465bb92
feat(tdi-43726):upgrade hadoop-aws version.
0749af3
feat(tdi-43726):upgrade hadoop for s3/tpd.
0fe9522
feat(tdi-43726):upgrade hadoop for s3/tpd.
34de38c
feat(tdi-43726):delete useless code in pom.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/sts/Constants4STS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.apache.hadoop.fs.s3a.sts; | ||
|
||
/** | ||
* To implement the feature in TDI-43726, the parameters below are needed. | ||
*/ | ||
public class Constants4STS { | ||
|
||
public static final String STS_SPECIFY = "tpd.s3.sts.specifySTS"; | ||
|
||
public static final String STS_ROLE_ARN = "tpd.s3.sts.roleARN"; | ||
|
||
public static final String STS_ROLE_SESSION_NAME = "tpd.s3.sts.roleSessionName"; | ||
|
||
public static final String STS_SIGNING_REGION = "tpd.s3.sts.signingRegion"; | ||
|
||
public static final String STS_SPECIFY_ROLE_EXTERNAL_ID = "tpd.s3.sts.specifyRoleExternalId"; | ||
|
||
public static final String STS_ROLE_EXTERNAL_ID = "tpd.s3.sts.roleExternalId"; | ||
|
||
public static final String STS_SPECIFY_ENDPOINT = "tpd.s3.sts.specifyEndpoint"; | ||
|
||
public static final String STS_ENDPOINT = "tpd.s3.sts.stsEndpoint"; | ||
|
||
public static final String STS_SPECIFY_SESSION_DURATION = "tpd.s3.sts.specifySessionDuration"; | ||
|
||
public static final String STS_SESSION_DURATION = "tpd.s3.sts.sessionDuration"; | ||
|
||
public static final String STS_SPECIFY_SERIAL_NUM = "tpd.s3.sts.specifySerialNum"; | ||
|
||
public static final String STS_SERIAL_NUMBER = "tpd.s3.sts.serialNumber"; | ||
|
||
public static final String STS_SPECIFY_TOKEN_CODE = "tpd.s3.sts.specifyTokenCode"; | ||
|
||
public static final String STS_TOKEN_CODE = "tpd.s3.sts.tokenCode"; | ||
|
||
public static final String STS_SPECIFY_TAGS = "tpd.s3.sts.specifyTags"; | ||
|
||
public static final String STS_TAGS = "tpd.s3.sts.tags"; | ||
|
||
public static final String STS_SPECIFY_POLICY_JSON = "tpd.s3.sts.specifyPolicyJson"; | ||
|
||
public static final String STS_POLICY_JSON = "tpd.s3.sts.policyJson"; | ||
|
||
public static final String STS_SPECIFY_POLICY_ARNS = "tpd.s3.sts.specifyPolicyARNs"; | ||
|
||
public static final String STS_POLICY_ARNS = "tpd.s3.sts.policyARNs"; | ||
|
||
} |
147 changes: 147 additions & 0 deletions
147
...p-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/sts/STSCredentialsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package org.apache.hadoop.fs.s3a.sts; | ||
|
||
import com.amazonaws.auth.AWSCredentials; | ||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicSessionCredentials; | ||
import com.amazonaws.client.builder.AwsClientBuilder; | ||
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder; | ||
import com.amazonaws.services.securitytoken.model.*; | ||
import org.apache.hadoop.conf.Configuration; | ||
|
||
import static org.apache.hadoop.fs.s3a.sts.Constants4STS.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class STSCredentialsProvider { | ||
|
||
private final String roleARN; | ||
|
||
private final String roleSessionName; | ||
|
||
private final String signingRegion; | ||
|
||
private final boolean specifyRoleExternalId; | ||
|
||
private final String roleExternalId; | ||
|
||
private final boolean specifySTSEndpoint; | ||
|
||
private final String stsEndpoint; | ||
|
||
private final boolean specifySessionDuration; | ||
|
||
private final int sessionDuration; | ||
|
||
private final boolean specifySerialNum; | ||
|
||
private final String serialNumber; | ||
|
||
private final boolean specifyTokenCode; | ||
|
||
private final String tokenCode; | ||
|
||
private final boolean specifyTags; | ||
|
||
private final String tags; | ||
|
||
private final boolean specifyPolicyJson; | ||
|
||
private final String policyJson; | ||
|
||
private final boolean specifyPolicyARNs; | ||
|
||
private final String policyARNs; | ||
|
||
public STSCredentialsProvider(Configuration conf) { | ||
roleARN = conf.get(STS_ROLE_ARN,null); | ||
roleSessionName = conf.get(STS_ROLE_SESSION_NAME,null); | ||
signingRegion = conf.get(STS_SIGNING_REGION,"us-east-1"); | ||
specifyRoleExternalId = conf.getBoolean(STS_SPECIFY_ROLE_EXTERNAL_ID,false); | ||
roleExternalId = conf.get(STS_ROLE_EXTERNAL_ID,null); | ||
specifySTSEndpoint = conf.getBoolean(STS_SPECIFY_ENDPOINT,false); | ||
stsEndpoint = conf.get(STS_ENDPOINT,null); | ||
specifySessionDuration = conf.getBoolean(STS_SPECIFY_SESSION_DURATION,false); | ||
sessionDuration = conf.getInt(STS_SESSION_DURATION,15); | ||
specifySerialNum = conf.getBoolean(STS_SPECIFY_SERIAL_NUM,false); | ||
serialNumber = conf.get(STS_SERIAL_NUMBER,null); | ||
specifyTokenCode = conf.getBoolean(STS_SPECIFY_TOKEN_CODE,false); | ||
tokenCode = conf.get(STS_TOKEN_CODE,null); | ||
specifyTags = conf.getBoolean(STS_SPECIFY_TAGS,false); | ||
specifyPolicyJson = conf.getBoolean(STS_SPECIFY_POLICY_JSON,false); | ||
policyJson = conf.get(STS_POLICY_JSON,null); | ||
specifyPolicyARNs = conf.getBoolean(STS_SPECIFY_POLICY_ARNS,false); | ||
tags = conf.get(STS_TAGS, null); | ||
policyARNs = conf.get(STS_POLICY_ARNS, null); | ||
} | ||
|
||
public AWSCredentials getSTSCredentials(AWSCredentials basicCredentials) { | ||
AWSSecurityTokenServiceClientBuilder stsClientBuilder = AWSSecurityTokenServiceClientBuilder.standard() | ||
.withCredentials(new AWSStaticCredentialsProvider(basicCredentials)); | ||
if (specifySTSEndpoint) { | ||
stsClientBuilder | ||
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(stsEndpoint, signingRegion)); | ||
} else { | ||
stsClientBuilder.withRegion(signingRegion); | ||
} | ||
|
||
AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleArn(roleARN).withRoleSessionName(roleSessionName); | ||
|
||
if (specifyRoleExternalId) { | ||
assumeRoleRequest.withExternalId(roleExternalId); | ||
} | ||
|
||
if (specifySessionDuration) { | ||
assumeRoleRequest.withDurationSeconds(sessionDuration * 60); | ||
} | ||
|
||
if (specifySerialNum) { | ||
assumeRoleRequest.withSerialNumber(serialNumber); | ||
} | ||
|
||
if (specifyTokenCode) { | ||
assumeRoleRequest.withTokenCode(tokenCode); | ||
} | ||
|
||
if (specifyTags) { | ||
List<Tag> tagList = new ArrayList<Tag>(); | ||
List<String> tranTagKeys = new ArrayList<String>(); | ||
|
||
String[] tagArray = tags.split(";"); | ||
|
||
for (String tagInfo : tagArray) { | ||
String[] t = tagInfo.split(","); | ||
Tag tag = new Tag().withKey(t[0]).withValue(t[1]); | ||
|
||
tagList.add(tag); | ||
|
||
if ("true".equalsIgnoreCase(t[2])) | ||
tranTagKeys.add(t[0]); | ||
} | ||
|
||
assumeRoleRequest.withTags(tagList); | ||
assumeRoleRequest.withTransitiveTagKeys(tranTagKeys); | ||
} | ||
|
||
if (specifyPolicyJson) { | ||
assumeRoleRequest.withPolicy(policyJson); | ||
} | ||
|
||
if (specifyPolicyARNs) { | ||
List<PolicyDescriptorType> policyARNList = new ArrayList<PolicyDescriptorType>(); | ||
String[] policyArray = policyARNs.split(","); | ||
|
||
for (String arn : policyArray) { | ||
policyARNList.add(new PolicyDescriptorType().withArn(arn)); | ||
} | ||
assumeRoleRequest.withPolicyArns(policyARNList); | ||
} | ||
|
||
AssumeRoleResult assumeRoleResult = stsClientBuilder.build().assumeRole(assumeRoleRequest); | ||
Credentials assumeRoleCred = assumeRoleResult.getCredentials(); | ||
BasicSessionCredentials roleSessionCred = new BasicSessionCredentials(assumeRoleCred.getAccessKeyId(), | ||
assumeRoleCred.getSecretAccessKey(), assumeRoleCred.getSessionToken()); | ||
|
||
return roleSessionCred; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ols/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/sts/STSCredentialsProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.apache.hadoop.fs.s3a.sts; | ||
|
||
import com.amazonaws.auth.AWSCredentials; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import static org.apache.hadoop.fs.s3a.sts.Constants4STS.*; | ||
|
||
@Ignore("ignore now as no accout in test env") | ||
public class STSCredentialsProviderTest { | ||
|
||
@Test | ||
public void testSTS() { | ||
Configuration conf = new Configuration(); | ||
conf.setBoolean(STS_SPECIFY, true); | ||
conf.set(STS_ROLE_ARN, System.getProperty("s3.roleARN")); | ||
conf.set(STS_ROLE_SESSION_NAME, "test_STS"); | ||
conf.setInt(STS_SESSION_DURATION, 20); | ||
conf.set(STS_SIGNING_REGION, "us-east-1"); | ||
conf.setBoolean(STS_SPECIFY_ENDPOINT, true); | ||
conf.set(STS_ENDPOINT, "sts.us-east-1.amazonaws.com"); | ||
conf.setBoolean(STS_SPECIFY_TAGS, true); | ||
conf.set(STS_TAGS, "key1,val1,true;key2,val2,false"); | ||
conf.setBoolean(STS_SPECIFY_POLICY_ARNS, true); | ||
conf.set(STS_POLICY_ARNS, "arn1,arn2,arn3"); | ||
|
||
STSCredentialsProvider stsCred = new STSCredentialsProvider(conf); | ||
|
||
AWSCredentials credentials = | ||
new BasicAWSCredentials(System.getProperty("s3.accesskey"), System.getProperty("s3.secretkey")); | ||
|
||
stsCred.getSTSCredentials(credentials); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
best to add mock test
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 here only a ignored IT test, can't auto test risk.