Skip to content

Commit

Permalink
Fix config-profiles with multiple SSO instances
Browse files Browse the repository at this point in the history
- Generate multiple SSO config blocks, one for each instances
- fix fish autocomplete for profile names

Fixes: #740, #696
  • Loading branch information
synfinatic committed Jun 8, 2024
1 parent f12c501 commit 19f8157
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

## [v1.16.0] - XXXX-XX-XX

### Changes
### Bug Fixes

* Fix tab completion for --profile flag with fish
* `config-profiles` now works for multiple AWS SSO instances #696, #740

### Changes

* `config-profiles` command now uses the name of the SSO for the block #696
* update to AWS ssooidc v1.24.5

### New Features

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
)

require (
github.com/aws/aws-sdk-go-v2 v1.27.1
github.com/aws/aws-sdk-go-v2 v1.27.2
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab
golang.org/x/term v0.21.0
gopkg.in/ini.v1 v1.67.0
Expand Down Expand Up @@ -73,16 +73,16 @@ require (
github.com/aws/aws-sdk-go-v2/credentials v1.13.43
github.com/aws/aws-sdk-go-v2/service/iam v1.24.0
github.com/aws/aws-sdk-go-v2/service/sso v1.20.10
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.4
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.5
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2
golang.org/x/net v0.23.0
)

require (
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.8 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.8 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aws/aws-sdk-go-v2 v1.9.2/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4=
github.com/aws/aws-sdk-go-v2 v1.21.2/go.mod h1:ErQhvNuEMhJjweavOYhxVkn2RUx7kQXVATHrjKtxIpM=
github.com/aws/aws-sdk-go-v2 v1.27.1 h1:xypCL2owhog46iFxBKKpBcw+bPTX/RJzwNj8uSilENw=
github.com/aws/aws-sdk-go-v2 v1.27.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
github.com/aws/aws-sdk-go-v2 v1.27.2 h1:pLsTXqX93rimAOZG2FIYraDQstZaaGVVN4tNw65v0h8=
github.com/aws/aws-sdk-go-v2 v1.27.2/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
github.com/aws/aws-sdk-go-v2/config v1.8.3/go.mod h1:4AEiLtAb8kLs7vgw2ZV3p2VZ1+hBavOc84hqxVNpCyw=
github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs=
github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE=
Expand All @@ -46,11 +46,11 @@ github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.6.0/go.mod h1:gqlclDEZp4aqJOanc
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43/go.mod h1:auo+PiyLl0n1l8A0e8RIeR8tOzYPfZZH/JNlrJ8igTQ=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.8 h1:RnLB7p6aaFMRfyQkD6ckxR7myCC9SABIqSz4czYUUbU=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.8/go.mod h1:XH7dQJd+56wEbP1I4e4Duo+QhSMxNArE8VP7NuUOTeM=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.9 h1:cy8ahBJuhtM8GTTSyOkfy6WVPV1IE+SS5/wfXUYuulw=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.9/go.mod h1:CZBXGLaJnEZI6EVNcPd7a6B5IC5cA/GkRWtu9fp3S6Y=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37/go.mod h1:Qe+2KtKml+FEsQF/DHmDV+xjtche/hwoF75EG4UlHW8=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.8 h1:jzApk2f58L9yW9q1GEab3BMMFWUkkiZhyrRUtbwUbKU=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.8/go.mod h1:WqO+FftfO3tGePUtQxPXM6iODVfqMwsVMgTbG/ZXIdQ=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.9 h1:A4SYk07ef04+vxZToz9LWvAXl9LW0NClpPpMsi31cz0=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.9/go.mod h1:5jJcHuwDagxN+ErjQ3PU3ocf6Ylc/p9x+BLO/+X4iXw=
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.4/go.mod h1:ZcBrrI3zBKlhGFNYWvju0I3TR93I7YIgAfy82Fh4lcQ=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE=
Expand All @@ -65,8 +65,8 @@ github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBp
github.com/aws/aws-sdk-go-v2/service/sso v1.20.10 h1:ItKVmFwbyb/ZnCWf+nu3XBVmUirpO9eGEQd7urnBA0s=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.10/go.mod h1:5XKooCTi9VB/xZmJDvh7uZ+v3uQ7QdX6diOyhvPA+/w=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.4 h1:QMSCYDg3Iyls0KZc/dk3JtS2c1lFfqbmYO10qBPPkJk=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.4/go.mod h1:MZ/PVYU/mRbmSF6WK3ybCYHjA2mig8utVokDEVLDgE0=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.5 h1:iXjh3uaH3vsVcnyZX7MqCoCfcyxIrVE9iOQruRaWPrQ=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.5/go.mod h1:5ZXesEuy/QcO0WUnt+4sDkxhdXRHTu2yG0uCSH8B6os=
github.com/aws/aws-sdk-go-v2/service/sts v1.7.2/go.mod h1:8EzeIqfWt2wWT4rJVu3f21TfrhJ8AEMzVybRNSb/b4g=
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU=
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ=
Expand Down
1 change: 1 addition & 0 deletions internal/helper/aws-sso.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ function __complete_aws-sso
set -lx COMP_LINE (commandline -cp)
test -z (commandline -ct)
and set COMP_LINE "$COMP_LINE "
export __NO_ESCAPE_COLONS=1
{{ .Executable }}
end
complete -f -c aws-sso -a "(__complete_aws-sso)"
Expand Down
1 change: 1 addition & 0 deletions internal/helper/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function __complete_aws-sso
set -lx COMP_LINE (commandline -cp)
test -z (commandline -ct)
and set COMP_LINE "$COMP_LINE "
export __NO_ESCAPE_COLONS=1
/bin/aws-sso-cli
end
complete -f -c aws-sso -a "(__complete_aws-sso)"
Expand Down
7 changes: 6 additions & 1 deletion internal/predictor/predictor.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ func (p *Predictor) ProfileComplete() complete.Predictor {
// The `:` character is considered a word delimiter by bash complete
// so we need to escape them
for _, x := range p.profiles {
profiles = append(profiles, strings.ReplaceAll(x, ":", "\\:"))
if os.Getenv("__NO_ESCAPE_COLONS") == "" {
profiles = append(profiles, strings.ReplaceAll(x, ":", "\\:"))
} else {
// fish doesn't treat colons as word delimiters
profiles = append(profiles, x)

Check warning on line 178 in internal/predictor/predictor.go

View check run for this annotation

Codecov / codecov/patch

internal/predictor/predictor.go#L178

Added line #L178 was not covered by tests
}
}

return complete.PredictSet(profiles...)
Expand Down
8 changes: 6 additions & 2 deletions sso/awssso_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ func (as *AWSSSO) reauthenticate() error {

log.Tracef("reauthenticate() for %s", as.StoreKey())
err := as.registerClient(false)
log.Tracef("<- reauthenticate()")
if err != nil {
return fmt.Errorf("unable to register client with AWS SSO: %s", err.Error())
}
log.Tracef("<- reauthenticate()")

err = as.startDeviceAuthorization()
log.Tracef("<- reauthenticate()")
Expand Down Expand Up @@ -150,21 +150,25 @@ const (
func (as *AWSSSO) registerClient(force bool) error {
log.Tracef("registerClient()")
if !force {
log.Trace("Checking cache for RegisterClientData")
err := as.store.GetRegisterClientData(as.StoreKey(), &as.ClientData)
if err == nil && !as.ClientData.Expired() {
log.Debugf("Using RegisterClient cache for %s", as.StoreKey())
return nil
}
}

log.Trace("Registering new client with AWS SSO")
input := ssooidc.RegisterClientInput{
ClientName: aws.String(as.ClientName),
ClientType: aws.String(as.ClientType),
// docs say this is optional, but it's required?
GrantTypes: []string{"refresh_token"},
Scopes: nil,
}
resp, err := as.ssooidc.RegisterClient(context.TODO(), &input)
if err != nil {
return err
return fmt.Errorf("registerClient: %s", err.Error())
}

as.ClientData = storage.RegisterClientData{
Expand Down

0 comments on commit 19f8157

Please sign in to comment.