Skip to content

Commit

Permalink
AWS: Allow STS AssumeRole with external_id
Browse files Browse the repository at this point in the history
Allow users to provide an external_id at assumerole creds generation time.
  • Loading branch information
bpineau committed Sep 7, 2018
1 parent 8575f8f commit 2087459
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion builtin/logical/aws/path_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func pathUser(b *backend) *framework.Path {
Description: "Lifetime of the returned credentials in seconds",
Default: 3600,
},
"external_id": &framework.FieldSchema{
Type: framework.TypeString,
Description: "STS external ID",
},
},

Callbacks: map[logical.Operation]framework.OperationFunc{
Expand Down Expand Up @@ -58,6 +62,7 @@ func (b *backend) pathCredsRead(ctx context.Context, req *logical.Request, d *fr

ttl := int64(d.Get("ttl").(int))
roleArn := d.Get("role_arn").(string)
externalId := d.Get("external_id").(string)

var credentialType string
switch {
Expand Down Expand Up @@ -103,7 +108,7 @@ func (b *backend) pathCredsRead(ctx context.Context, req *logical.Request, d *fr
case !strutil.StrListContains(role.RoleArns, roleArn):
return logical.ErrorResponse(fmt.Sprintf("role_arn %q not in allowed role arns for Vault role %q", roleArn, roleName)), nil
}
return b.assumeRole(ctx, req.Storage, req.DisplayName, roleName, roleArn, role.PolicyDocument, ttl)
return b.assumeRole(ctx, req.Storage, req.DisplayName, roleName, roleArn, role.PolicyDocument, externalId, ttl)
case federationTokenCred:
return b.secretTokenCreate(ctx, req.Storage, req.DisplayName, roleName, role.PolicyDocument, ttl)
default:
Expand Down
5 changes: 4 additions & 1 deletion builtin/logical/aws/secret_access_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (b *backend) secretTokenCreate(ctx context.Context, s logical.Storage,
}

func (b *backend) assumeRole(ctx context.Context, s logical.Storage,
displayName, roleName, roleArn, policy string,
displayName, roleName, roleArn, policy, externalId string,
lifeTimeInSeconds int64) (*logical.Response, error) {
STSClient, err := clientSTS(ctx, s)
if err != nil {
Expand All @@ -127,6 +127,9 @@ func (b *backend) assumeRole(ctx context.Context, s logical.Storage,
if policy != "" {
assumeRoleInput.SetPolicy(policy)
}
if externalId != "" {
assumeRoleInput.SetExternalId(externalId)
}
tokenResp, err := STSClient.AssumeRole(assumeRoleInput)

if err != nil {
Expand Down

0 comments on commit 2087459

Please sign in to comment.