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 partitions support for saml2aws console #557

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 36 additions & 4 deletions cmd/saml2aws/commands/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"net/url"
"strings"
"time"

"github.com/pkg/errors"
Expand All @@ -17,8 +18,26 @@ import (
)

const (
federationURL = "https://signin.aws.amazon.com/federation"
issuer = "saml2aws"
defaultFederationURL = "https://signin.aws.amazon.com/federation"
defaultDestination = "https://console.aws.amazon.com/console/home"
issuer = "saml2aws"
)

var (
altFederationURLs = map[string]string{
"us-gov-" : "https://signin.amazonaws-us-gov.com/federation",
"cn-north-" : "https://signin.amazonaws.cn/federation",
"cn-northwest-" : "https://signin.amazonaws.cn/federation",
}

altDestinations = map[string]string{
"us-gov-" : "https://console.amazonaws-us-gov.com/console/home",
"cn-north-" : "https://console.amazonaws.cn/console/home",
"cn-northwest-" : "https://console.amazonaws.cn/console/home",
}

federationURL string
destination string
)

// Console open the aws console from the CLI
Expand All @@ -29,6 +48,21 @@ func Console(consoleFlags *flags.ConsoleFlags) error {
return errors.Wrap(err, "error building login details")
}

for region, url := range altFederationURLs {
if strings.HasPrefix(account.Region, region) {
federationURL = url
destination = altDestinations[region]
}
}
if federationURL == "" {
federationURL = defaultFederationURL
destination = defaultDestination
}

if account.Region != "" {
destination = destination + "?region=" + account.Region
}

sharedCreds := awsconfig.NewSharedCredentials(account.Profile)

// this checks if the credentials file has been created yet
Expand Down Expand Up @@ -155,8 +189,6 @@ func federatedLogin(creds *awsconfig.AWSCredentials, consoleFlags *flags.Console
return err
}

destination := "https://console.aws.amazon.com/"

loginURL := fmt.Sprintf(
"%s?Action=login&Issuer=%s&Destination=%s&SigninToken=%s",
federationURL,
Expand Down