@@ -84,7 +84,7 @@ func (b *backend) getRawClientConfig(ctx context.Context, s logical.Storage, reg
84
84
// It uses getRawClientConfig to obtain config for the runtime environment, and if
85
85
// stsRole is a non-empty string, it will use AssumeRole to obtain a set of assumed
86
86
// credentials. The credentials will expire after 15 minutes but will auto-refresh.
87
- func (b * backend ) getClientConfig (ctx context.Context , s logical.Storage , region , stsRole , accountID , clientType string ) (* aws.Config , error ) {
87
+ func (b * backend ) getClientConfig (ctx context.Context , s logical.Storage , region , stsRole , externalID , accountID , clientType string ) (* aws.Config , error ) {
88
88
config , err := b .getRawClientConfig (ctx , s , region , clientType )
89
89
if err != nil {
90
90
return nil , err
@@ -105,7 +105,7 @@ func (b *backend) getClientConfig(ctx context.Context, s logical.Storage, region
105
105
if err != nil {
106
106
return nil , err
107
107
}
108
- assumedCredentials := stscreds .NewCredentials (sess , stsRole )
108
+ assumedCredentials := stscreds .NewCredentials (sess , stsRole , func ( p * stscreds. AssumeRoleProvider ) { p . ExternalID = aws . String ( externalID ) } )
109
109
// Test that we actually have permissions to assume the role
110
110
if _ , err = assumedCredentials .Get (); err != nil {
111
111
return nil , err
@@ -180,22 +180,22 @@ func (b *backend) setCachedUserId(userId, arn string) {
180
180
}
181
181
}
182
182
183
- func (b * backend ) stsRoleForAccount (ctx context.Context , s logical.Storage , accountID string ) (string , error ) {
183
+ func (b * backend ) stsRoleForAccount (ctx context.Context , s logical.Storage , accountID string ) (string , string , error ) {
184
184
// Check if an STS configuration exists for the AWS account
185
185
sts , err := b .lockedAwsStsEntry (ctx , s , accountID )
186
186
if err != nil {
187
- return "" , fmt .Errorf ("error fetching STS config for account ID %q: %w" , accountID , err )
187
+ return "" , "" , fmt .Errorf ("error fetching STS config for account ID %q: %w" , accountID , err )
188
188
}
189
189
// An empty STS role signifies the master account
190
190
if sts != nil {
191
- return sts .StsRole , nil
191
+ return sts .StsRole , sts . ExternalID , nil
192
192
}
193
- return "" , nil
193
+ return "" , "" , nil
194
194
}
195
195
196
196
// clientEC2 creates a client to interact with AWS EC2 API
197
197
func (b * backend ) clientEC2 (ctx context.Context , s logical.Storage , region , accountID string ) (* ec2.EC2 , error ) {
198
- stsRole , err := b .stsRoleForAccount (ctx , s , accountID )
198
+ stsRole , stsExternalID , err := b .stsRoleForAccount (ctx , s , accountID )
199
199
if err != nil {
200
200
return nil , err
201
201
}
@@ -218,7 +218,7 @@ func (b *backend) clientEC2(ctx context.Context, s logical.Storage, region, acco
218
218
219
219
// Create an AWS config object using a chain of providers
220
220
var awsConfig * aws.Config
221
- awsConfig , err = b .getClientConfig (ctx , s , region , stsRole , accountID , "ec2" )
221
+ awsConfig , err = b .getClientConfig (ctx , s , region , stsRole , stsExternalID , accountID , "ec2" )
222
222
if err != nil {
223
223
return nil , err
224
224
}
@@ -247,7 +247,7 @@ func (b *backend) clientEC2(ctx context.Context, s logical.Storage, region, acco
247
247
248
248
// clientIAM creates a client to interact with AWS IAM API
249
249
func (b * backend ) clientIAM (ctx context.Context , s logical.Storage , region , accountID string ) (* iam.IAM , error ) {
250
- stsRole , err := b .stsRoleForAccount (ctx , s , accountID )
250
+ stsRole , stsExternalID , err := b .stsRoleForAccount (ctx , s , accountID )
251
251
if err != nil {
252
252
return nil , err
253
253
}
@@ -277,7 +277,7 @@ func (b *backend) clientIAM(ctx context.Context, s logical.Storage, region, acco
277
277
278
278
// Create an AWS config object using a chain of providers
279
279
var awsConfig * aws.Config
280
- awsConfig , err = b .getClientConfig (ctx , s , region , stsRole , accountID , "iam" )
280
+ awsConfig , err = b .getClientConfig (ctx , s , region , stsRole , stsExternalID , accountID , "iam" )
281
281
if err != nil {
282
282
return nil , err
283
283
}
0 commit comments