Skip to content

Commit d2fe6e8

Browse files
authored
Merge pull request #1342 from eldondevat/master
Implement assume-time policy limiting
2 parents 17ef4e6 + f4a0d2e commit d2fe6e8

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

cmd/saml2aws/commands/login.go

+16
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,22 @@ func loginToStsUsingRole(account *cfg.IDPAccount, role *saml2aws.AWSRole, samlAs
365365
DurationSeconds: aws.Int64(int64(account.SessionDuration)),
366366
}
367367

368+
if account.PolicyFile != "" {
369+
policy, err := os.ReadFile(account.PolicyFile)
370+
if err != nil {
371+
return nil, errors.Wrap(err, fmt.Sprintf("Failed to load supplimental policy file: %s", account.PolicyFile))
372+
}
373+
params.Policy = aws.String(string(policy))
374+
}
375+
376+
if account.PolicyARNs != "" {
377+
var arns []*sts.PolicyDescriptorType
378+
for _, arn := range strings.Split(account.PolicyARNs, ",") {
379+
arns = append(arns, &sts.PolicyDescriptorType{Arn: aws.String(arn)})
380+
}
381+
params.PolicyArns = arns
382+
}
383+
368384
log.Println("Requesting AWS credentials using SAML assertion.")
369385

370386
resp, err := svc.AssumeRoleWithSAML(params)

cmd/saml2aws/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func main() {
8383
app.Flag("password", "The password used to login. (env: SAML2AWS_PASSWORD)").Envar("SAML2AWS_PASSWORD").StringVar(&commonFlags.Password)
8484
app.Flag("mfa-token", "The current MFA token (supported in Keycloak, ADFS, GoogleApps). (env: SAML2AWS_MFA_TOKEN)").Envar("SAML2AWS_MFA_TOKEN").StringVar(&commonFlags.MFAToken)
8585
app.Flag("role", "The ARN of the role to assume. (env: SAML2AWS_ROLE)").Envar("SAML2AWS_ROLE").StringVar(&commonFlags.RoleArn)
86+
app.Flag("policyfile", "The file containing the supplemental AssumeRole policy. (env: SAML2AWS_POLICY_FILE)").Envar("SAML2AWS_POLICY_FILE").StringVar(&commonFlags.PolicyFile)
87+
app.Flag("policyarns", "The ARN of supplemental policies to restrict the token. (env: SAML2AWS_POLICY_ARNS)").Envar("SAML2AWS_POLICY_ARNS").StringVar(&commonFlags.PolicyARNs)
8688
app.Flag("aws-urn", "The URN used by SAML when you login. (env: SAML2AWS_AWS_URN)").Envar("SAML2AWS_AWS_URN").StringVar(&commonFlags.AmazonWebservicesURN)
8789
app.Flag("skip-prompt", "Skip prompting for parameters during login.").BoolVar(&commonFlags.SkipPrompt)
8890
app.Flag("session-duration", "The duration of your AWS Session. (env: SAML2AWS_SESSION_DURATION)").Envar("SAML2AWS_SESSION_DURATION").IntVar(&commonFlags.SessionDuration)

pkg/cfg/cfg.go

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type IDPAccount struct {
5252
ResourceID string `ini:"resource_id"` // used by F5APM
5353
Subdomain string `ini:"subdomain"` // used by OneLogin
5454
RoleARN string `ini:"role_arn"`
55+
PolicyFile string `ini:"policy_file"`
56+
PolicyARNs string `ini:"policy_arn_list"`
5557
Region string `ini:"region"`
5658
HttpAttemptsCount string `ini:"http_attempts_count"`
5759
HttpRetryDelay string `ini:"http_retry_delay"`

pkg/flags/flags.go

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type CommonFlags struct {
2222
Username string
2323
Password string
2424
RoleArn string
25+
PolicyFile string
26+
PolicyARNs string
2527
AmazonWebservicesURN string
2628
SessionDuration int
2729
SkipPrompt bool
@@ -115,6 +117,12 @@ func ApplyFlagOverrides(commonFlags *CommonFlags, account *cfg.IDPAccount) {
115117
if commonFlags.RoleArn != "" {
116118
account.RoleARN = commonFlags.RoleArn
117119
}
120+
if commonFlags.PolicyFile != "" {
121+
account.PolicyFile = commonFlags.PolicyFile
122+
}
123+
if commonFlags.PolicyARNs != "" {
124+
account.PolicyARNs = commonFlags.PolicyARNs
125+
}
118126
if commonFlags.ResourceID != "" {
119127
account.ResourceID = commonFlags.ResourceID
120128
}

0 commit comments

Comments
 (0)