|
25 | 25 |
|
26 | 26 | import com.amazonaws.ClientConfiguration; |
27 | 27 | import com.amazonaws.Protocol; |
| 28 | +import com.amazonaws.auth.AWSCredentials; |
28 | 29 | import com.amazonaws.auth.AWSCredentialsProvider; |
29 | 30 | import com.amazonaws.auth.BasicAWSCredentials; |
30 | 31 | import com.amazonaws.auth.InstanceProfileCredentialsProvider; |
|
35 | 36 | import com.amazonaws.services.s3.S3ClientOptions; |
36 | 37 | import org.apache.logging.log4j.Logger; |
37 | 38 | import org.elasticsearch.ElasticsearchException; |
| 39 | +import org.elasticsearch.cloud.aws.util.SocketAccess; |
38 | 40 | import org.elasticsearch.common.Strings; |
39 | 41 | import org.elasticsearch.common.collect.Tuple; |
40 | 42 | import org.elasticsearch.common.component.AbstractLifecycleComponent; |
@@ -141,22 +143,30 @@ static ClientConfiguration buildConfiguration(Logger logger, Settings repository |
141 | 143 |
|
142 | 144 | public static AWSCredentialsProvider buildCredentials(Logger logger, DeprecationLogger deprecationLogger, |
143 | 145 | Settings settings, Settings repositorySettings, String clientName) { |
144 | | - AWSCredentialsProvider credentials; |
145 | 146 | try (SecureString key = getConfigValue(repositorySettings, settings, clientName, S3Repository.ACCESS_KEY_SETTING, |
146 | 147 | S3Repository.Repository.KEY_SETTING, S3Repository.Repositories.KEY_SETTING); |
147 | 148 | SecureString secret = getConfigValue(repositorySettings, settings, clientName, S3Repository.SECRET_KEY_SETTING, |
148 | 149 | S3Repository.Repository.SECRET_SETTING, S3Repository.Repositories.SECRET_SETTING)) { |
149 | 150 |
|
150 | 151 | if (key.length() == 0 && secret.length() == 0) { |
151 | 152 | logger.debug("Using instance profile credentials"); |
152 | | - credentials = new InstanceProfileCredentialsProvider(); |
| 153 | + AWSCredentialsProvider credentials = new InstanceProfileCredentialsProvider(); |
| 154 | + return new AWSCredentialsProvider() { |
| 155 | + @Override |
| 156 | + public AWSCredentials getCredentials() { |
| 157 | + return SocketAccess.doPrivileged(credentials::getCredentials); |
| 158 | + } |
| 159 | + |
| 160 | + @Override |
| 161 | + public void refresh() { |
| 162 | + SocketAccess.doPrivilegedVoid(credentials::refresh); |
| 163 | + } |
| 164 | + }; |
153 | 165 | } else { |
154 | 166 | logger.debug("Using basic key/secret credentials"); |
155 | | - credentials = new StaticCredentialsProvider(new BasicAWSCredentials(key.toString(), secret.toString())); |
| 167 | + return new StaticCredentialsProvider(new BasicAWSCredentials(key.toString(), secret.toString())); |
156 | 168 | } |
157 | 169 | } |
158 | | - |
159 | | - return credentials; |
160 | 170 | } |
161 | 171 |
|
162 | 172 | // pkg private for tests |
|
0 commit comments