|
38 | 38 | import org.springframework.vault.authentication.AppRoleAuthenticationOptions.RoleId; |
39 | 39 | import org.springframework.vault.authentication.AppRoleAuthenticationOptions.SecretId; |
40 | 40 | import org.springframework.vault.authentication.AwsEc2AuthenticationOptions.AwsEc2AuthenticationOptionsBuilder; |
| 41 | +import org.springframework.vault.authentication.AwsIamAuthenticationOptions.AwsIamAuthenticationOptionsBuilder; |
41 | 42 | import org.springframework.vault.authentication.AzureMsiAuthenticationOptions.AzureMsiAuthenticationOptionsBuilder; |
42 | 43 | import org.springframework.vault.authentication.CubbyholeAuthenticationOptions.CubbyholeAuthenticationOptionsBuilder; |
43 | 44 | import org.springframework.vault.authentication.KubernetesAuthenticationOptions.KubernetesAuthenticationOptionsBuilder; |
|
46 | 47 | import org.springframework.vault.support.SslConfiguration.KeyStoreConfiguration; |
47 | 48 | import org.springframework.vault.support.VaultToken; |
48 | 49 | import org.springframework.web.client.RestOperations; |
| 50 | +import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; |
49 | 51 |
|
50 | 52 | /** |
51 | 53 | * Configuration using Spring's {@link org.springframework.core.env.Environment} to |
|
162 | 164 | * @author Raoof Mohammed |
163 | 165 | * @author Justin Bertrand |
164 | 166 | * @author Ryan Gow |
| 167 | + * @author Nick Tan |
165 | 168 | * @see org.springframework.core.env.Environment |
166 | 169 | * @see org.springframework.core.env.PropertySource |
167 | 170 | * @see VaultEndpoint |
168 | 171 | * @see AppIdAuthentication |
169 | 172 | * @see AppRoleAuthentication |
170 | 173 | * @see AwsEc2Authentication |
| 174 | + * @see AwsIamAuthentication |
171 | 175 | * @see AzureMsiAuthentication |
172 | 176 | * @see ClientCertificateAuthentication |
173 | 177 | * @see CubbyholeAuthentication |
@@ -264,6 +268,8 @@ public ClientAuthentication clientAuthentication() { |
264 | 268 | return appRoleAuthentication(); |
265 | 269 | case AWS_EC2: |
266 | 270 | return awsEc2Authentication(); |
| 271 | + case AWS_IAM: |
| 272 | + return awsIamAuthentication(); |
267 | 273 | case AZURE: |
268 | 274 | return azureMsiAuthentication(); |
269 | 275 | case CERT: |
@@ -369,6 +375,17 @@ protected ClientAuthentication awsEc2Authentication() { |
369 | 375 | return new AwsEc2Authentication(builder.build(), restOperations(), restOperations()); |
370 | 376 | } |
371 | 377 |
|
| 378 | + protected ClientAuthentication awsIamAuthentication() { |
| 379 | + String role = getProperty("vault.aws-iam.role"); |
| 380 | + Assert.isTrue(StringUtils.hasText(role), |
| 381 | + "Vault AWS-IAM authentication: Role (vault.aws-iam.role) must not be empty"); |
| 382 | + |
| 383 | + AwsIamAuthenticationOptionsBuilder builder = AwsIamAuthenticationOptions.builder().role(role) |
| 384 | + .credentialsProvider(DefaultCredentialsProvider.create()); |
| 385 | + |
| 386 | + return new AwsIamAuthentication(builder.build(), restOperations()); |
| 387 | + } |
| 388 | + |
372 | 389 | protected ClientAuthentication azureMsiAuthentication() { |
373 | 390 |
|
374 | 391 | String role = getProperty("vault.azure-msi.role"); |
@@ -454,7 +471,7 @@ enum AppIdUserId { |
454 | 471 |
|
455 | 472 | enum AuthenticationMethod { |
456 | 473 |
|
457 | | - TOKEN, APPID, APPROLE, AWS_EC2, AZURE, CERT, CUBBYHOLE, KUBERNETES; |
| 474 | + TOKEN, APPID, APPROLE, AWS_EC2, AWS_IAM, AZURE, CERT, CUBBYHOLE, KUBERNETES; |
458 | 475 |
|
459 | 476 | } |
460 | 477 |
|
|
0 commit comments