Skip to content

Commit 39aa5ab

Browse files
authored
fix: address some minor issues (#13)
* fix: address some minor issues * fix: windows domain joined user removes `\` from domain name +semver: feature * fix: remove needless output * fix: remove commented out [revert]: once able to capture the PPID of chromium then should delete it
1 parent 645d1bf commit 39aa5ab

File tree

7 files changed

+44
-15
lines changed

7 files changed

+44
-15
lines changed

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ clean:
3232

3333
.PHONY: cross-build
3434

35-
cross-build:
36-
for os in darwin linux windows; do \
35+
build-win:
36+
for arch in amd64 386; do \
37+
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 go build -mod=readonly -buildvcs=false $(LDFLAGS) -o dist/$(NAME)-$$os-$$arch .; \
38+
done
39+
40+
cross-build: build-win
41+
for os in darwin linux; do \
3742
GOOS=$$os CGO_ENABLED=0 go build -mod=readonly -buildvcs=false $(LDFLAGS) -o dist/$(NAME)-$$os .; \
3843
done
3944

cmd/clear.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ func init() {
2626

2727
func clear(cmd *cobra.Command, args []string) error {
2828

29-
web := web.New(web.NewWebConf(datadir))
30-
3129
secretStore, err := credentialexchange.NewSecretStore("",
3230
fmt.Sprintf("%s-%s", credentialexchange.SELF_NAME, credentialexchange.RoleKeyConverter("")),
3331
os.TempDir(), "")
@@ -36,11 +34,14 @@ func clear(cmd *cobra.Command, args []string) error {
3634
}
3735

3836
if force {
39-
if err := web.ClearCache(); err != nil {
37+
w := &web.Web{}
38+
w.WithConfig(web.NewWebConf(datadir))
39+
if err := w.ClearCache(); err != nil {
4040
return err
4141
}
4242
fmt.Fprint(os.Stderr, "Chromium Cache cleared")
4343
}
44+
4445
secretStore.ClearAll()
4546

4647
if err := os.Remove(credentialexchange.ConfigIniFile("")); err != nil {

cmd/saml.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func getSaml(cmd *cobra.Command, args []string) error {
6969
if err != nil {
7070
return err
7171
}
72-
72+
allRoles := credentialexchange.InsertRoleIntoChain(role, roleChain)
7373
conf := credentialexchange.CredentialConfig{
7474
ProviderUrl: providerUrl,
7575
PrincipalArn: principalArn,
@@ -81,28 +81,35 @@ func getSaml(cmd *cobra.Command, args []string) error {
8181
BaseConfig: credentialexchange.BaseConfig{
8282
StoreInProfile: storeInProfile,
8383
Role: role,
84-
RoleChain: credentialexchange.InsertRoleIntoChain(role, roleChain),
84+
RoleChain: allRoles,
8585
Username: user.Username,
8686
CfgSectionName: cfgSectionName,
8787
DoKillHangingProcess: killHangingProcess,
8888
ReloadBeforeTime: reloadBeforeTime,
8989
},
9090
}
9191

92+
saveRole := ""
9293
if isSso {
9394
sr := strings.Split(ssoRole, ":")
9495
if len(sr) != 2 {
9596
return fmt.Errorf("incorrectly formatted role for AWS SSO - must only be ACCOUNT:ROLE_NAME")
9697
}
98+
saveRole = ssoRole
99+
97100
conf.SsoUserEndpoint = fmt.Sprintf("https://portal.sso.%s.amazonaws.com/user", conf.SsoRegion)
98101
conf.SsoCredFedEndpoint = fmt.Sprintf("https://portal.sso.%s.amazonaws.com/federation/credentials/", conf.SsoRegion) + fmt.Sprintf("?account_id=%s&role_name=%s&debug=true", sr[0], sr[1])
99102
}
100103

101104
datadir := path.Join(credentialexchange.HomeDir(), fmt.Sprintf(".%s-data", credentialexchange.SELF_NAME))
102105
os.MkdirAll(datadir, 0755)
103106

104-
secretStore, err := credentialexchange.NewSecretStore(conf.BaseConfig.Role,
105-
fmt.Sprintf("%s-%s", credentialexchange.SELF_NAME, credentialexchange.RoleKeyConverter(conf.BaseConfig.Role)),
107+
if len(allRoles) > 0 {
108+
saveRole = allRoles[len(allRoles)-1]
109+
}
110+
111+
secretStore, err := credentialexchange.NewSecretStore(saveRole,
112+
fmt.Sprintf("%s-%s", credentialexchange.SELF_NAME, credentialexchange.RoleKeyConverter(saveRole)),
106113
os.TempDir(), user.Username)
107114
if err != nil {
108115
return err

internal/credentialexchange/credentialexchange.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func assumeRoleWithCreds(ctx context.Context, currentCreds *AWSCredentials, svc
176176
})
177177

178178
if err != nil {
179-
return nil, fmt.Errorf("failed to retrieve STS credentials using Role Provided, %w", ErrUnableAssume)
179+
return nil, fmt.Errorf("failed to retrieve STS credentials using Role Provided: %s, %w", err, ErrUnableAssume)
180180
}
181181

182182
return &AWSCredentials{

internal/credentialexchange/helper.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"os"
99
"path"
10+
"strings"
1011
"time"
1112

1213
ini "gopkg.in/ini.v1"
@@ -36,7 +37,7 @@ func ConfigIniFile(basePath string) string {
3637
}
3738

3839
func SessionName(username, selfName string) string {
39-
return fmt.Sprintf("%s-%s", username, selfName)
40+
return fmt.Sprintf("%s-%s", strings.ReplaceAll(username, `\`, "--"), selfName)
4041
}
4142

4243
func InsertRoleIntoChain(role string, roleChain []string) []string {

internal/credentialexchange/secret.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ func (s *SecretStore) save() error {
140140
if err != nil {
141141
return err
142142
}
143+
143144
defer release()
144145

146+
if err := WriteIniSection(s.roleArn); err != nil {
147+
return err
148+
}
149+
145150
return s.keyring.Set(s.secretService, s.secretUser, s.AWSCredJson)
146151
}
147152

@@ -154,8 +159,6 @@ func (s *SecretStore) AWSCredential() (*AWSCredentials, error) {
154159
return nil, nil
155160
}
156161

157-
fmt.Fprintf(os.Stderr, "Got credential from OS secret store for %s", s.roleArn)
158-
159162
return s.AWSCredentials, nil
160163
}
161164

internal/web/web.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,17 @@ func New(conf *WebConfig) *Web {
7474
}
7575
}
7676

77+
func (web *Web) WithConfig(conf *WebConfig) *Web {
78+
web.conf = conf
79+
return web
80+
}
81+
7782
// GetSamlLogin performs a saml login for a given
7883
func (web *Web) GetSamlLogin(conf credentialexchange.CredentialConfig) (string, error) {
7984

8085
// close browser even on error
8186
// should cover most cases even with leakless: false
82-
defer web.browser.MustClose()
87+
defer web.MustClose()
8388

8489
web.browser.MustPage(conf.ProviderUrl)
8590

@@ -116,7 +121,7 @@ func (web *Web) GetSamlLogin(conf credentialexchange.CredentialConfig) (string,
116121
// GetSSOCredentials
117122
func (web *Web) GetSSOCredentials(conf credentialexchange.CredentialConfig) (string, error) {
118123

119-
defer web.browser.MustClose()
124+
defer web.MustClose()
120125

121126
web.browser.MustPage(conf.ProviderUrl)
122127

@@ -163,6 +168,13 @@ func (web *Web) GetSSOCredentials(conf credentialexchange.CredentialConfig) (str
163168
}
164169
}
165170

171+
func (web *Web) MustClose() {
172+
err := web.browser.Close()
173+
if err != nil {
174+
fmt.Fprintf(os.Stderr, "%s", err)
175+
}
176+
}
177+
166178
func (web *Web) ClearCache() error {
167179
errs := []error{}
168180

0 commit comments

Comments
 (0)