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

feature/use-aws-user-id-sso #665

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions pkg/assume/assume.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func AssumeCommand(c *cli.Context) error {
MFATokenCode: assumeFlags.String("mfa-token"),
Args: assumeFlags.StringSlice("pass-through"),
DisableCache: assumeFlags.Bool("no-cache"),
UseUserId: assumeFlags.Bool("use-user-id"),
}

// attempt to get session duration from profile
Expand Down
1 change: 1 addition & 0 deletions pkg/assume/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func GlobalFlags() []cli.Flag {
&cli.BoolFlag{Name: "wait", Usage: "When using Granted with Common Fate the assume will halt while waiting for the access request to be approved."},
&cli.BoolFlag{Name: "no-cache", Usage: "Disables caching of session credentials and forces a refresh", EnvVars: []string{"GRANTED_NO_CACHE"}},
&cli.StringSliceFlag{Name: "browser-launch-template-arg", Usage: "Additional arguments to provide to the browser launch template command in key=value format, e.g. '--browser-launch-template-arg foo=bar"},
&cli.BoolFlag{Name: "use-user-id", Aliases: []string{"uu"}, Usage: "Whether to use the AWS user ID", DefaultText: "false" },
}
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/cfaws/assumer_aws_sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"os"
"strings"
"time"

Expand Down Expand Up @@ -101,6 +102,7 @@ func (c *Profile) SSOLoginWithToken(ctx context.Context, cfg *aws.Config, access

if requiresAssuming {
// return creds, nil
useUserId := os.Getenv("GRANTED_USE_USER_ID") == "true"
toAssume := append([]*Profile{}, c.Parents[1:]...)
toAssume = append(toAssume, c)
for i, p := range toAssume {
Expand All @@ -114,6 +116,13 @@ func (c *Profile) SSOLoginWithToken(ctx context.Context, cfg *aws.Config, access
// all configuration goes in here for this profile
if p.AWSConfig.RoleSessionName != "" {
aro.RoleSessionName = p.AWSConfig.RoleSessionName
} else if configOpts.UseUserId || useUserId {
caller, err := stsClient.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
if err != nil {
return
}
userId := strings.Split(*caller.UserId, ":")[1]
aro.RoleSessionName = userId
} else {
aro.RoleSessionName = sessionName()
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cfaws/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ConfigOpts struct {
ShouldRetryAssuming *bool
MFATokenCode string
DisableCache bool
UseUserId bool
}

type Profile struct {
Expand Down