Merge branch 'pr/19556-use-DefaultAWSCredentialsProviderChain'

This commit is contained in:
David Pilato 2016-07-28 17:38:52 +02:00
parent 0d2ccf0989
commit 3adccd4560
6 changed files with 12 additions and 44 deletions

View File

@ -45,10 +45,6 @@ dependencyLicenses {
test {
// this is needed for insecure plugins, remove if possible!
systemProperty 'tests.artifact', project.name
// this could be needed by AwsEc2ServiceImplTests#testAWSCredentialsWithSystemProviders()
// As it's marked as Ignored for now, we can comment those
// systemProperty 'aws.accessKeyId', 'DUMMY_ACCESS_KEY'
// systemProperty 'aws.secretKey', 'DUMMY_SECRET_KEY'
}
thirdPartyAudit.excludes = [

View File

@ -23,11 +23,8 @@ import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSCredentialsProviderChain;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.auth.SystemPropertiesCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.http.IdleConnectionReaper;
import com.amazonaws.internal.StaticCredentialsProvider;
import com.amazonaws.retry.RetryPolicy;
@ -81,16 +78,10 @@ public class AwsEc2ServiceImpl extends AbstractLifecycleComponent implements Aws
String secret = CLOUD_EC2.SECRET_SETTING.get(settings);
if (key.isEmpty() && secret.isEmpty()) {
logger.debug("Using either environment variables, system properties or instance profile credentials");
credentials = new AWSCredentialsProviderChain(
new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
new InstanceProfileCredentialsProvider()
);
credentials = new DefaultAWSCredentialsProviderChain();
} else {
logger.debug("Using basic key/secret credentials");
credentials = new AWSCredentialsProviderChain(
new StaticCredentialsProvider(new BasicAWSCredentials(key, secret))
);
credentials = new StaticCredentialsProvider(new BasicAWSCredentials(key, secret));
}
return credentials;

View File

@ -23,22 +23,20 @@ import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESTestCase;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
public class AwsEc2ServiceImplTests extends ESTestCase {
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/19556")
public void testAWSCredentialsWithSystemProviders() {
AWSCredentialsProvider credentialsProvider = AwsEc2ServiceImpl.buildCredentials(logger, Settings.EMPTY);
AWSCredentials credentials = credentialsProvider.getCredentials();
assertThat(credentials.getAWSAccessKeyId(), is("DUMMY_ACCESS_KEY"));
assertThat(credentials.getAWSSecretKey(), is("DUMMY_SECRET_KEY"));
assertThat(credentialsProvider, instanceOf(DefaultAWSCredentialsProviderChain.class));
}
public void testAWSCredentialsWithElasticsearchAwsSettings() {

View File

@ -51,10 +51,6 @@ dependencyLicenses {
test {
// this is needed for insecure plugins, remove if possible!
systemProperty 'tests.artifact', project.name
// this could be needed by AwsS3ServiceImplTests#testAWSCredentialsWithSystemProviders()
// As it's marked as Ignored for now, we can comment those
// systemProperty 'aws.accessKeyId', 'DUMMY_ACCESS_KEY'
// systemProperty 'aws.secretKey', 'DUMMY_SECRET_KEY'
}
thirdPartyAudit.excludes = [

View File

@ -22,11 +22,8 @@ package org.elasticsearch.cloud.aws;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSCredentialsProviderChain;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.auth.SystemPropertiesCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.http.IdleConnectionReaper;
import com.amazonaws.internal.StaticCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
@ -36,7 +33,6 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.settings.Settings;
@ -122,19 +118,12 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent implements
public static AWSCredentialsProvider buildCredentials(ESLogger logger, String key, String secret) {
AWSCredentialsProvider credentials;
if (key.isEmpty() && secret.isEmpty()) {
logger.debug("Using either environment variables, system properties or instance profile credentials");
credentials = new AWSCredentialsProviderChain(
new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
new InstanceProfileCredentialsProvider()
);
credentials = new DefaultAWSCredentialsProviderChain();
} else {
logger.debug("Using basic key/secret credentials");
credentials = new AWSCredentialsProviderChain(
new StaticCredentialsProvider(new BasicAWSCredentials(key, secret))
);
credentials = new StaticCredentialsProvider(new BasicAWSCredentials(key, secret));
}
return credentials;

View File

@ -23,22 +23,20 @@ import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.repositories.s3.S3Repository;
import org.elasticsearch.test.ESTestCase;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
public class AwsS3ServiceImplTests extends ESTestCase {
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/19556")
public void testAWSCredentialsWithSystemProviders() {
AWSCredentialsProvider credentialsProvider = InternalAwsS3Service.buildCredentials(logger, "", "");
AWSCredentials credentials = credentialsProvider.getCredentials();
assertThat(credentials.getAWSAccessKeyId(), is("DUMMY_ACCESS_KEY"));
assertThat(credentials.getAWSSecretKey(), is("DUMMY_SECRET_KEY"));
assertThat(credentialsProvider, instanceOf(DefaultAWSCredentialsProviderChain.class));
}
public void testAWSCredentialsWithElasticsearchAwsSettings() {