Skip to content

Commit 40a22fc

Browse files
authored
Add PolicyArns to stscreds role providers (#540)
* Add PolicyArns to stscreds role providers * Correcting PolicyArns' type
1 parent a72ac10 commit 40a22fc

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

CHANGELOG_PENDING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ SDK Features
66

77
SDK Enhancements
88
---
9+
* `aws/stscreds`: `PolicyArns` can now be passed in to `stscreds.AssumeRoleProvider` and `stscreds.WebIdentityRoleProvider` in the same way as `sts.AssumeRoleInput`.
910

1011
SDK Bugs
1112
---

aws/stscreds/provider.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,29 @@ type AssumeRoleProviderOptions struct {
162162
// size.
163163
Policy *string
164164

165+
// The ARNs of IAM managed policies you want to use as managed session policies.
166+
// The policies must exist in the same account as the role.
167+
//
168+
// This parameter is optional. You can provide up to 10 managed policy ARNs.
169+
// However, the plain text that you use for both inline and managed session
170+
// policies can't exceed 2,048 characters.
171+
//
172+
// An AWS conversion compresses the passed session policies and session tags
173+
// into a packed binary format that has a separate limit. Your request can fail
174+
// for this limit even if your plain text meets the other requirements. The
175+
// PackedPolicySize response element indicates by percentage how close the policies
176+
// and tags for your request are to the upper size limit.
177+
//
178+
// Passing policies to this operation returns new temporary credentials. The
179+
// resulting session's permissions are the intersection of the role's identity-based
180+
// policy and the session policies. You can use the role's temporary credentials
181+
// in subsequent AWS API calls to access resources in the account that owns
182+
// the role. You cannot use session policies to grant more permissions than
183+
// those allowed by the identity-based policy of the role that is being assumed.
184+
// For more information, see Session Policies (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
185+
// in the IAM User Guide.
186+
PolicyArns []sts.PolicyDescriptorType
187+
165188
// The identification number of the MFA device that is associated with the user
166189
// who is making the AssumeRole call. Specify this value if the trust policy
167190
// of the role being assumed includes a condition that requires MFA authentication.
@@ -223,6 +246,7 @@ func (p *AssumeRoleProvider) retrieveFn() (aws.Credentials, error) {
223246
}
224247
input := &sts.AssumeRoleInput{
225248
DurationSeconds: aws.Int64(int64(p.options.Duration / time.Second)),
249+
PolicyArns: p.options.PolicyArns,
226250
RoleArn: aws.String(p.roleARN),
227251
RoleSessionName: aws.String(p.options.RoleSessionName),
228252
ExternalId: p.options.ExternalID,

aws/stscreds/web_identity_provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type WebIdentityRoleProvider struct {
4141
// WebIdentityRoleProviderOptions is a structure of configurable options for WebIdentityRoleProvider
4242
type WebIdentityRoleProviderOptions struct {
4343
ExpiryWindow time.Duration
44+
PolicyArns []sts.PolicyDescriptorType
4445
}
4546

4647
// IdentityTokenRetriever is an interface for retrieving a JWT
@@ -96,6 +97,7 @@ func (p *WebIdentityRoleProvider) retrieveFn() (aws.Credentials, error) {
9697
sessionName = strconv.FormatInt(sdk.NowTime().UnixNano(), 10)
9798
}
9899
req := p.client.AssumeRoleWithWebIdentityRequest(&sts.AssumeRoleWithWebIdentityInput{
100+
PolicyArns: p.options.PolicyArns,
99101
RoleArn: &p.roleARN,
100102
RoleSessionName: &sessionName,
101103
WebIdentityToken: aws.String(string(b)),

0 commit comments

Comments
 (0)