Skip to content

Commit 2bf24c4

Browse files
committed
Add parameter SourceIdentity
The parameter `SourceIdentity` can be used to track the original principal that was used when assuming IAM roles. It can be set only once during a session and is also preserved if you do IAM role chaining.
1 parent 642ff69 commit 2bf24c4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

credentials.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func webIdentityCredentialsProvider(ctx context.Context, awsConfig aws.Config, c
193193
func assumeRoleCredentialsProvider(ctx context.Context, awsConfig aws.Config, c *Config) (aws.CredentialsProvider, error) {
194194
ar := c.AssumeRole
195195
// When assuming a role, we need to first authenticate the base credentials above, then assume the desired role
196-
log.Printf("[INFO] Assuming IAM Role %q (SessionName: %q, ExternalId: %q)", ar.RoleARN, ar.SessionName, ar.ExternalID)
196+
log.Printf("[INFO] Assuming IAM Role %q (SessionName: %q, ExternalId: %q, SourceIdentity: %q)", ar.RoleARN, ar.SessionName, ar.ExternalID, ar.SourceIdentity)
197197

198198
client := stsClient(awsConfig, c)
199199

@@ -229,6 +229,10 @@ func assumeRoleCredentialsProvider(ctx context.Context, awsConfig aws.Config, c
229229
if len(ar.TransitiveTagKeys) > 0 {
230230
opts.TransitiveTagKeys = ar.TransitiveTagKeys
231231
}
232+
233+
if ar.SourceIdentity != "" {
234+
opts.SourceIdentity = aws.String(ar.SourceIdentity)
235+
}
232236
})
233237
_, err := appCreds.Retrieve(ctx)
234238
if err != nil {

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type AssumeRole struct {
4848
Policy string
4949
PolicyARNs []string
5050
SessionName string
51+
SourceIdentity string
5152
Tags map[string]string
5253
TransitiveTagKeys []string
5354
}

0 commit comments

Comments
 (0)