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

Add service option initially implemented by @maishsk #291

Merged
merged 2 commits into from
Oct 12, 2018
Merged
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
24 changes: 18 additions & 6 deletions cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type LoginCommandInput struct {
FederationTokenDuration time.Duration
AssumeRoleDuration time.Duration
Region string
Path string
}

func ConfigureLoginCommand(app *kingpin.Application) {
Expand All @@ -46,6 +47,9 @@ func ConfigureLoginCommand(app *kingpin.Application) {
Short('t').
StringVar(&input.MfaToken)

cmd.Flag("path", "The AWS service you would like access").
StringVar(&input.Path)

cmd.Flag("federation-token-ttl", "Expiration time for aws console session").
Default("12h").
OverrideDefaultFromEnvar("AWS_FEDERATION_TOKEN_TTL").
Expand Down Expand Up @@ -80,6 +84,7 @@ func LoginCommand(app *kingpin.Application, input LoginCommandInput) {
AssumeRoleDuration: input.AssumeRoleDuration,
MfaToken: input.MfaToken,
MfaPrompt: input.MfaPrompt,
Path: input.Path,
NoSession: true,
Config: awsConfig,
Region: profile.Region,
Expand Down Expand Up @@ -124,7 +129,7 @@ func LoginCommand(app *kingpin.Application, input LoginCommandInput) {
return
}

loginURLPrefix, destination := generateLoginURL(provider.Region)
loginURLPrefix, destination := generateLoginURL(provider.Region, input.Path)

req, err := http.NewRequest("GET", loginURLPrefix, nil)
if err != nil {
Expand Down Expand Up @@ -218,7 +223,7 @@ func getFederationToken(creds credentials.Value, d time.Duration, region string)
return resp.Credentials, nil
}

func generateLoginURL(region string) (string, string) {
func generateLoginURL(region string, path string) (string, string) {
loginURLPrefix := "https://signin.aws.amazon.com/federation"
destination := "https://console.aws.amazon.com/"

Expand All @@ -232,10 +237,17 @@ func generateLoginURL(region string) (string, string) {
loginURLPrefix = "https://signin.amazonaws-us-gov.com/federation"
destinationDomain = "console.amazonaws-us-gov.com"
}
destination = fmt.Sprintf(
"https://%s.%s/console/home?region=%s",
region, destinationDomain, region,
)
if path != "" {
destination = fmt.Sprintf(
"https://%s.%s/%s?region=%s",
region, destinationDomain, path, region,
)
} else {
destination = fmt.Sprintf(
"https://%s.%s/console/home?region=%s",
region, destinationDomain, region,
)
}
}
return loginURLPrefix, destination
}
1 change: 1 addition & 0 deletions vault/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type VaultOptions struct {
Config *Config
MasterCreds *credentials.Value
Region string
Path string
}

func (o VaultOptions) Validate() error {
Expand Down