HADOOP-13389 TestS3ATemporaryCredentials.testSTS error when using IAM credentials. Contributed by Steven K. Wong

This commit is contained in:
Steve Loughran 2016-07-23 17:58:46 +01:00
parent b79ba4fe96
commit 7052ca8804

View File

@ -19,10 +19,10 @@
package org.apache.hadoop.fs.s3a; package org.apache.hadoop.fs.s3a;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProviderChain; import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient; import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient;
import com.amazonaws.services.securitytoken.model.GetSessionTokenRequest; import com.amazonaws.services.securitytoken.model.GetSessionTokenRequest;
import com.amazonaws.services.securitytoken.model.GetSessionTokenResult; import com.amazonaws.services.securitytoken.model.GetSessionTokenResult;
@ -31,6 +31,7 @@
import org.apache.hadoop.fs.contract.AbstractFSContract; import org.apache.hadoop.fs.contract.AbstractFSContract;
import org.apache.hadoop.fs.contract.AbstractFSContractTestBase; import org.apache.hadoop.fs.contract.AbstractFSContractTestBase;
import org.apache.hadoop.fs.contract.s3a.S3AContract; import org.apache.hadoop.fs.contract.s3a.S3AContract;
import org.apache.hadoop.fs.s3native.S3xLoginHelper;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.junit.Test; import org.junit.Test;
@ -54,9 +55,6 @@ public class TestS3ATemporaryCredentials extends AbstractFSContractTestBase {
private static final Logger LOG = private static final Logger LOG =
LoggerFactory.getLogger(TestS3ATemporaryCredentials.class); LoggerFactory.getLogger(TestS3ATemporaryCredentials.class);
private S3AFileSystem fs;
private static final String PROVIDER_CLASS = private static final String PROVIDER_CLASS =
"org.apache.hadoop.fs.s3a.TemporaryAWSCredentialsProvider"; "org.apache.hadoop.fs.s3a.TemporaryAWSCredentialsProvider";
@ -84,15 +82,15 @@ public void testSTS() throws IOException {
skip("STS functional tests disabled"); skip("STS functional tests disabled");
} }
String parentAccessKey = conf.getTrimmed(ACCESS_KEY, null); S3xLoginHelper.Login login = S3AUtils.getAWSAccessKeys(
String parentSecretKey = conf.getTrimmed(SECRET_KEY, null); URI.create("s3a://foobar"), conf);
String stsEndpoint = conf.getTrimmed(TEST_STS_ENDPOINT, ""); if (!login.hasLogin()) {
AWSCredentialsProviderChain parentCredentials; skip("testSTS disabled because AWS credentials not configured");
parentCredentials = new AWSCredentialsProviderChain( }
new BasicAWSCredentialsProvider(parentAccessKey, parentSecretKey), AWSCredentialsProvider parentCredentials = new BasicAWSCredentialsProvider(
new InstanceProfileCredentialsProvider() login.getUser(), login.getPassword());
);
String stsEndpoint = conf.getTrimmed(TEST_STS_ENDPOINT, "");
AWSSecurityTokenServiceClient stsClient; AWSSecurityTokenServiceClient stsClient;
stsClient = new AWSSecurityTokenServiceClient(parentCredentials); stsClient = new AWSSecurityTokenServiceClient(parentCredentials);
if (!stsEndpoint.isEmpty()) { if (!stsEndpoint.isEmpty()) {