Skip to content

Commit e018fd8

Browse files
committed
fix: clean up
1 parent 50aa2c9 commit e018fd8

File tree

4 files changed

+64
-23
lines changed

4 files changed

+64
-23
lines changed

cmd/saml.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ func newSamlCmd(r *Root) {
7979
return err
8080
}
8181

82-
allRoles := credentialexchange.MergeRoleChain(flags.Role, r.rootFlags.RoleChain, flags.IsSso)
83-
84-
conf.BaseConfig.RoleChain = allRoles
85-
8682
// now we want to overwrite anything set via the command line
8783
saveRole := flags.Role
8884
if flags.IsSso {
@@ -93,6 +89,8 @@ func newSamlCmd(r *Root) {
9389
SsoCredsEndpointQuery, sc.ssoRoleAccount, sc.ssoRoleName)
9490
}
9591

92+
allRoles := credentialexchange.MergeRoleChain(conf.BaseConfig.Role, conf.BaseConfig.RoleChain, flags.IsSso)
93+
9694
if len(allRoles) > 0 {
9795
saveRole = allRoles[len(allRoles)-1]
9896
}
@@ -105,21 +103,23 @@ func newSamlCmd(r *Root) {
105103
}
106104

107105
// we want to remove any AWS_* env vars that could interfere with the default config
108-
for _, envVar := range []string{"AWS_PROFILE", "AWS_ACCESS_KEY_ID",
109-
"AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"} {
110-
os.Unsetenv(envVar)
111-
}
106+
// for _, envVar := range []string{"AWS_PROFILE", "AWS_ACCESS_KEY_ID",
107+
// "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"} {
108+
// os.Unsetenv(envVar)
109+
// }
112110

113111
awsConf, err := config.LoadDefaultConfig(ctx)
114112
if err != nil {
115113
return fmt.Errorf("failed to create session %s, %w", err, ErrUnableToCreateSession)
116114
}
117115

118116
svc := sts.NewFromConfig(awsConf)
119-
webConfig := web.NewWebConf(r.Datadir).WithTimeout(flags.SamlTimeout)
120-
webConfig.CustomChromeExecutable = flags.CustomExecutablePath
117+
webConfig := web.NewWebConf(r.Datadir).
118+
WithTimeout(flags.SamlTimeout).
119+
WithCustomExecutable(conf.BaseConfig.BrowserExecutablePath)
121120

122121
return cmdutils.GetCredsWebUI(ctx, svc, secretStore, *conf, webConfig)
122+
123123
},
124124
PreRunE: func(cmd *cobra.Command, args []string) error {
125125
if flags.ReloadBeforeTime != 0 && flags.ReloadBeforeTime > r.rootFlags.Duration {
@@ -183,11 +183,15 @@ func samlInitConfig(customPath string) (*ini.File, error) {
183183
}
184184

185185
func ConfigFromFlags(fileConfig *credentialexchange.CredentialConfig, rf *RootCmdFlags, sf *SamlCmdFlags, user string) error {
186-
186+
d := fileConfig.Duration
187+
// 900 is the default
188+
if rf.Duration != 900 {
189+
d = rf.Duration
190+
}
187191
flagSamlConf := &credentialexchange.CredentialConfig{
188192
ProviderUrl: sf.ProviderUrl,
189193
PrincipalArn: sf.PrincipalArn,
190-
Duration: rf.Duration,
194+
Duration: d,
191195
AcsUrl: sf.AcsUrl,
192196
IsSso: sf.IsSso,
193197
SsoRegion: sf.SsoRegion,
@@ -198,7 +202,7 @@ func ConfigFromFlags(fileConfig *credentialexchange.CredentialConfig, rf *RootCm
198202
StoreInProfile: rf.StoreInProfile,
199203
Role: sf.Role,
200204
// RoleChain is added in the command function
201-
// RoleChain: allRoles,
205+
RoleChain: rf.RoleChain,
202206
Username: user,
203207
CfgSectionName: rf.CfgSectionName,
204208
ReloadBeforeTime: sf.ReloadBeforeTime,
@@ -207,10 +211,13 @@ func ConfigFromFlags(fileConfig *credentialexchange.CredentialConfig, rf *RootCm
207211
if err := mergo.Merge(&fileConfig.BaseConfig, flagBaseConfig, mergo.WithOverride); err != nil {
208212
return err
209213
}
214+
210215
baseConf := fileConfig.BaseConfig
211216
if err := mergo.Merge(fileConfig, flagSamlConf, mergo.WithOverride, mergo.WithOverrideEmptySlice); err != nil {
212217
return err
213218
}
219+
214220
fileConfig.BaseConfig = baseConf
221+
fileConfig.Duration = d
215222
return nil
216223
}

docs/usage.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,45 @@ To give it a quick test.
101101
aws sts get-caller-identity --profile=nonprod_saml_admin
102102
```
103103

104+
### Configuration file
105+
106+
You can specify the same parameters through the INI config file.
107+
108+
```ini
109+
; global config will be applied to config sections
110+
[config]
111+
browser-executable-path = "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
112+
duration = 3600
113+
provider-url = https://my-idp-url.com
114+
;
115+
; you can specify the below on the top level config
116+
; NB: it does make more sense to have these in the specific sections
117+
; anything set in the specific section will overwrite the global property
118+
; anything set in the commandline will overwrite the conf file property
119+
;
120+
; role = main-assume-role
121+
; role-chain = chain-role1,chain-role2
122+
; principal =
123+
; is-sso =
124+
; sso-region =
125+
; sso-role =
126+
; is-sso-endpoint =
127+
128+
; Specific section overrides
129+
[config.cfg-section-name]
130+
role = arn:aws:iam::123456789101:role/IdP-admin
131+
role-chain = arn:aws:iam::123456789101:role/SSO-admin
132+
principal = arn:aws:iam::123456789101:saml-provider/GoogleIdP
133+
provider-url = https://accounts.google.com/o/saml2/initsso?idpid=abc123&spid=1234567&forceauthn=false
134+
; is-sso = false
135+
; sso-region = eu-west-1
136+
; sso-role =
137+
; is-sso-endpoint =
138+
139+
; generated by aws-cli-auth
140+
[role]
141+
```
142+
104143
## AWS SSO Portal
105144

106145
**NOW** Includes support for AWS User Portal, largely remains the same with a few exceptions/additions:

internal/credentialexchange/config.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,3 @@ type CredentialConfig struct {
2929
SsoUserEndpoint string `ini:"is-sso-endpoint"`
3030
SsoCredFedEndpoint string
3131
}
32-
33-
// --cfg-section aws_travelodge_ssvc
34-
// --store-profile
35-
// -p "https://accounts.google.com/o/saml2/initsso?idpid=C03uqod6r&spid=759219486523&forceauthn=false"
36-
// --principal "arn:aws:iam::881490129763:saml-provider/GoogleIdP"
37-
// --role "arn:aws:iam::881490129763:role/IdP-admin"
38-
// --role-chain "arn:aws:iam::881490129763:role/SSO-admin"
39-
// -d 3600
40-
// --reload-before 120
41-
// --executable-path="/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"

internal/web/web.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ func (wc *WebConfig) WithNoSandbox() *WebConfig {
5656
return wc
5757
}
5858

59+
func (wc *WebConfig) WithCustomExecutable(browserPath string) *WebConfig {
60+
wc.CustomChromeExecutable = browserPath
61+
return wc
62+
}
63+
5964
type Web struct {
6065
conf *WebConfig
6166
launcher *launcher.Launcher

0 commit comments

Comments
 (0)