Skip to content

Commit 2e1c6e5

Browse files
committed
fix: allow for credential process
1 parent 385ed8a commit 2e1c6e5

File tree

11 files changed

+665
-444
lines changed

11 files changed

+665
-444
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
NAME := aws-cli-auth
2-
VERSION := v0.1.0
2+
VERSION := v0.2.0
33
REVISION := $(shell git rev-parse --short HEAD)
44

55
LDFLAGS := -ldflags="-s -w -X \"github.com/dnitsch/aws-cli-auth/version.Version=$(VERSION)\" -X \"github.com/dnitsch/aws-cli-auth/version.Revision=$(REVISION)\" -extldflags -static"

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,19 @@ To give it a quick test.
105105
aws sts get-caller-identity --profile=nonprod_saml_admin
106106
```
107107

108-
<!-- ### Integrate aws-cli
108+
### Integrate aws-cli
109109

110110
[Sourcing credentials with an external process](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sourcing-external.html) describes how to integrate aws-cli with external tool.
111111
You can use `aws-cli-auth` as the external process. Add the following lines to your `.aws/config` file.
112112

113113
```
114-
[profile ]
115-
credential_process=aws-cli-auth get-cred -p myop -r arn:aws:iam::123456789012:role/developer -j -s -d 43200
114+
[profile test_nonprod_iag]
115+
region = eu-west-1
116+
credential_process=aws-cli-auth saml -p https://your-idp.com/idp/foo?PARTNER=urn:amazon:webservices --principal arn:aws:iam::XXXXXXXXXX:saml-provider/IDP_ENTITY_ID -r arn:aws:iam::XXXXXXXXXX:role/Developer -d 3600
116117
```
117118

118-
Caution: The AWS temporary credentials will be saved into your OS secret store by using `-s` option to reduce authentication each time you use `aws-cli` tool.
119-
-->
119+
Notice the missing `-s` | `--store-profile` flag
120+
120121
## Licence
121122
WFTPL
122123

cmd/saml.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package cmd
22

33
import (
4-
"fmt"
5-
"os/user"
6-
74
"github.com/dnitsch/aws-cli-auth/internal/config"
85
"github.com/dnitsch/aws-cli-auth/internal/saml"
9-
"github.com/dnitsch/aws-cli-auth/internal/util"
10-
"github.com/dnitsch/aws-cli-auth/internal/web"
116
"github.com/spf13/cobra"
127
)
138

@@ -35,26 +30,14 @@ func init() {
3530
}
3631

3732
func getSaml(cmd *cobra.Command, args []string) {
38-
if cfgSectionName == "" {
39-
util.Writeln("The SAML provider name is required")
40-
util.Exit(nil)
41-
}
42-
43-
t, err := web.GetSamlLogin(providerUrl, acsUrl)
44-
if err != nil {
45-
fmt.Printf("Err: %v", err)
33+
conf := config.SamlConfig{
34+
ProviderUrl: providerUrl,
35+
PrincipalArn: principalArn,
36+
Duration: duration,
37+
AcsUrl: acsUrl,
38+
BaseConfig: config.BaseConfig{StoreInProfile: storeInProfile, Role: role, CfgSectionName: cfgSectionName},
4639
}
47-
user, err := user.Current()
48-
if err != nil {
49-
fmt.Errorf(err.Error())
50-
}
51-
52-
roleObj := &util.AWSRole{RoleARN: role, PrincipalARN: principalArn, Name: util.SessionName(user.Username, config.SELF_NAME), Duration: duration}
5340

54-
creds, err := saml.LoginStsSaml(t, roleObj)
55-
if err != nil {
56-
fmt.Printf("%v", err)
57-
}
41+
saml.GetSamlCreds(conf)
5842

59-
util.SetCredentials(creds, cfgSectionName, storeInProfile)
6043
}

go.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ require (
88
github.com/pkg/errors v0.9.1
99
github.com/spf13/cobra v1.3.0
1010
github.com/spf13/viper v1.10.1
11+
github.com/zalando/go-keyring v0.2.0
1112
)
1213

1314
require (
15+
github.com/alessio/shellescape v1.4.1 // indirect
16+
github.com/danieljoos/wincred v1.1.0 // indirect
17+
github.com/godbus/dbus/v5 v5.0.6 // indirect
18+
github.com/gofrs/flock v0.7.1 // indirect
19+
github.com/google/uuid v1.1.2 // indirect
20+
github.com/spaolacci/murmur3 v1.1.0 // indirect
1421
github.com/ysmood/goob v0.3.1 // indirect
1522
github.com/ysmood/gson v0.6.4 // indirect
1623
github.com/ysmood/leakless v0.7.0 // indirect
24+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
1725
)
1826

1927
require (
@@ -30,6 +38,7 @@ require (
3038
github.com/spf13/jwalterweatherman v1.1.0 // indirect
3139
github.com/spf13/pflag v1.0.5 // indirect
3240
github.com/subosito/gotenv v1.2.0 // indirect
41+
github.com/werf/lockgate v0.0.0-20211004100849-f85d5325b201
3342
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
3443
golang.org/x/text v0.3.7 // indirect
3544
gopkg.in/ini.v1 v1.66.2

go.sum

Lines changed: 342 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)