Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--aws-iam-idp and --aws-iam-role alias values #178

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions internal/webssoauth/webssoauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,15 @@ func (w *WebSSOAuthentication) selectFedApp(apps []*okta.Application) (string, e
for i, app := range apps {
choiceLabel := w.choiceFriendlyLabelIDP(app.Label, app.Settings.App.IdentityProviderARN, configIDPs)

// when OKTA_AWSCLI_IAM_IDP / --aws-iam-idp is set
if w.config.AWSIAMIdP() == app.Settings.App.IdentityProviderARN {
// reverse case when
// when choiceLabel == w.configAWSIAMIfP()
// --aws-iam-idp "S3 IdP"
idpARN := w.config.AWSIAMIdP()
if choiceLabel == w.config.AWSIAMIdP() {
idpARN = app.Settings.App.IdentityProviderARN
}

if idpARN == app.Settings.App.IdentityProviderARN {
if !w.config.IsProcessCredentialsFormat() {
idpData := idpTemplateData{
IDP: choiceLabel,
Expand Down Expand Up @@ -377,6 +384,7 @@ func (w *WebSSOAuthentication) awsAssumeRoleWithSAML(iar *idpAndRole, assertion,
}
sess, err := session.NewSession(awsCfg)
if err != nil {
err = fmt.Errorf("AWS API session error: %w", err)
return
}
svc := sts.New(sess)
Expand All @@ -388,6 +396,7 @@ func (w *WebSSOAuthentication) awsAssumeRoleWithSAML(iar *idpAndRole, assertion,
}
svcResp, err := svc.AssumeRoleWithSAML(input)
if err != nil {
err = fmt.Errorf("STS Assume Role With SAML API error; given idp: %q, role: %q, error: %w", iar.idp, iar.role, err)
return
}

Expand Down Expand Up @@ -443,6 +452,14 @@ func (w *WebSSOAuthentication) choiceFriendlyLabelRole(arn string, roles map[str
return label
}

// reverse case when friendly role name is given
// --aws-iam-role "OK S3 Read"
for _, roleLabel := range roles {
if arn == roleLabel {
return roleLabel
}
}

// treat ARN values as regexps
for arnRegexp, label := range roles {
if ok, _ := regexp.MatchString(arnRegexp, arn); ok {
Expand Down Expand Up @@ -478,6 +495,18 @@ func (w *WebSSOAuthentication) promptForRole(idp string, roleARNs []string) (rol
roleData := roleTemplateData{
Role: roleLabel,
}

// reverse case when friendly role name alias is given as the input value
// --aws-iam-role "OK S3 Read"
if roleLabel == roleARN {
for rARN, rLbl := range configRoles {
if roleARN == rLbl {
roleARN = rARN
break
}
}
}

if !w.config.IsProcessCredentialsFormat() {
rich, _, err := core.RunTemplate(roleSelectedTemplate, roleData)
if err != nil {
Expand Down
Loading