Skip to content

Commit c99725e

Browse files
Remove analytics and allow region selection
Add Okta server selection, choose server by selecting Okta region. Remove Okta password from storage. This may be paranoid but only store the session token and other details in the keychain. When the session expires the user will have to re-authenticate. Update the README and Makefile for FiveAI releases. Signed-off-by: Sean Jones <[email protected]>
1 parent 1d21ea0 commit c99725e

33 files changed

+68
-1868
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ LDFLAGS := -ldflags='-X "main.Version=$(VERSION)"'
44
release: gh-release govendor clean dist
55
github-release release \
66
--security-token $$GH_LOGIN \
7-
--user segmentio \
7+
--user fiveai \
88
--repo aws-okta \
99
--tag $(VERSION) \
1010
--name $(VERSION)
1111

1212
github-release upload \
1313
--security-token $$GH_LOGIN \
14-
--user segmentio \
14+
--user fiveai \
1515
--repo aws-okta \
1616
--tag $(VERSION) \
1717
--name aws-okta-$(VERSION)-linux-amd64 \
@@ -20,7 +20,7 @@ release: gh-release govendor clean dist
2020
release-mac: gh-release govendor clean dist-mac
2121
github-release upload \
2222
--security-token $$GH_LOGIN \
23-
--user segmentio \
23+
--user fiveai \
2424
--repo aws-okta \
2525
--tag $(VERSION) \
2626
--name aws-okta-$(VERSION)-darwin-amd64 \

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
You can install with:
88

99
```bash
10-
$ go get github.com/segmentio/aws-okta
10+
$ go get github.com/fiveai/aws-okta
1111
```
1212

1313
## Usage
@@ -109,10 +109,6 @@ $ export CIRCLE_TAG=`git describe --tags`
109109
$ make release-mac
110110
```
111111

112-
## Analytics
113-
114-
`aws-okta` includes some usage analytics code which Segment uses internally for tracking usage of internal tools. This analytics code is turned off by default, and can only be enabled via a linker flag at build time, which we do not set for public github releases.
115-
116112
## Internals
117113

118114
### Authentication process

cmd/add.go

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package cmd
22

33
import (
44
"encoding/json"
5-
"fmt"
65

76
log "github.com/Sirupsen/logrus"
87

98
"github.com/99designs/keyring"
10-
analytics "github.com/segmentio/analytics-go"
11-
"github.com/segmentio/aws-okta/lib"
9+
"github.com/fiveai/aws-okta/lib"
1210
"github.com/spf13/cobra"
1311
)
1412

@@ -23,49 +21,21 @@ func init() {
2321
RootCmd.AddCommand(addCmd)
2422
}
2523

26-
func add(cmd *cobra.Command, args []string) error {
27-
var allowedBackends []keyring.BackendType
28-
if backend != "" {
29-
allowedBackends = append(allowedBackends, keyring.BackendType(backend))
30-
}
31-
kr, err := lib.OpenKeyring(allowedBackends)
32-
33-
if err != nil {
34-
log.Fatal(err)
35-
}
36-
37-
if analyticsEnabled && analyticsClient != nil {
38-
analyticsClient.Enqueue(analytics.Track{
39-
UserId: username,
40-
Event: "Ran Command",
41-
Properties: analytics.NewProperties().
42-
Set("backend", backend).
43-
Set("aws-okta-version", version).
44-
Set("command", "add"),
45-
})
46-
}
47-
24+
func AddCredentials(kr keyring.Keyring) error {
4825
// Ask username password from prompt
49-
organization, err := lib.Prompt("Okta organization", false)
50-
if err != nil {
51-
return err
52-
}
53-
54-
username, err := lib.Prompt("Okta username", false)
26+
server, err := lib.Prompt("Okta Region (emea/us)", false)
5527
if err != nil {
5628
return err
5729
}
5830

59-
password, err := lib.Prompt("Okta password", true)
31+
organization, err := lib.Prompt("Okta organization", false)
6032
if err != nil {
6133
return err
6234
}
63-
fmt.Println()
6435

6536
creds := lib.OktaCreds{
37+
Server: server,
6638
Organization: organization,
67-
Username: username,
68-
Password: password,
6939
}
7040

7141
encoded, err := json.Marshal(creds)
@@ -83,6 +53,23 @@ func add(cmd *cobra.Command, args []string) error {
8353
if err := kr.Set(item); err != nil {
8454
return ErrFailedToSetCredentials
8555
}
56+
return nil
57+
}
58+
59+
func add(cmd *cobra.Command, args []string) error {
60+
var allowedBackends []keyring.BackendType
61+
if backend != "" {
62+
allowedBackends = append(allowedBackends, keyring.BackendType(backend))
63+
}
64+
kr, err := lib.OpenKeyring(allowedBackends)
65+
66+
if err != nil {
67+
log.Fatal(err)
68+
}
69+
70+
if err := AddCredentials(kr); err != nil {
71+
return err
72+
}
8673

8774
log.Infof("Added credentials for user %s", username)
8875
return nil

cmd/exec.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/99designs/keyring"
13-
analytics "github.com/segmentio/analytics-go"
14-
"github.com/segmentio/aws-okta/lib"
13+
"github.com/fiveai/aws-okta/lib"
1514
"github.com/spf13/cobra"
1615
)
1716

@@ -116,18 +115,6 @@ func execRun(cmd *cobra.Command, args []string) error {
116115
return err
117116
}
118117

119-
if analyticsEnabled && analyticsClient != nil {
120-
analyticsClient.Enqueue(analytics.Track{
121-
UserId: username,
122-
Event: "Ran Command",
123-
Properties: analytics.NewProperties().
124-
Set("backend", backend).
125-
Set("aws-okta-version", version).
126-
Set("profile", profile).
127-
Set("command", "exec"),
128-
})
129-
}
130-
131118
p, err := lib.NewProvider(kr, profile, opts)
132119
if err != nil {
133120
return err

cmd/login.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/99designs/keyring"
13-
analytics "github.com/segmentio/analytics-go"
14-
"github.com/segmentio/aws-okta/lib"
13+
"github.com/fiveai/aws-okta/lib"
1514
"github.com/skratchdot/open-golang/open"
1615
"github.com/spf13/cobra"
1716
)
@@ -83,18 +82,6 @@ func loginRun(cmd *cobra.Command, args []string) error {
8382
return err
8483
}
8584

86-
if analyticsEnabled && analyticsClient != nil {
87-
analyticsClient.Enqueue(analytics.Track{
88-
UserId: username,
89-
Event: "Ran Command",
90-
Properties: analytics.NewProperties().
91-
Set("backend", backend).
92-
Set("aws-okta-version", version).
93-
Set("profile", profile).
94-
Set("command", "login"),
95-
})
96-
}
97-
9885
p, err := lib.NewProvider(kr, profile, opts)
9986
if err != nil {
10087
return err

cmd/root.go

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/99designs/keyring"
99
log "github.com/Sirupsen/logrus"
10-
analytics "github.com/segmentio/analytics-go"
1110
"github.com/spf13/cobra"
1211
)
1312

@@ -21,31 +20,25 @@ var (
2120

2221
// global flags
2322
var (
24-
backend string
25-
debug bool
26-
version string
27-
analyticsWriteKey string
28-
analyticsEnabled bool
29-
analyticsClient analytics.Client
30-
username string
23+
backend string
24+
debug bool
25+
version string
26+
username string
3127
)
3228

3329
// RootCmd represents the base command when called without any subcommands
3430
var RootCmd = &cobra.Command{
35-
Use: "aws-okta",
36-
Short: "aws-okta allows you to authenticate with AWS using your okta credentials",
37-
SilenceUsage: true,
38-
SilenceErrors: true,
39-
PersistentPreRun: prerun,
40-
PersistentPostRun: postrun,
31+
Use: "aws-okta",
32+
Short: "aws-okta allows you to authenticate with AWS using your okta credentials",
33+
SilenceUsage: true,
34+
SilenceErrors: true,
35+
PersistentPreRun: prerun,
4136
}
4237

4338
// Execute adds all child commands to the root command sets flags appropriately.
4439
// This is called by main.main(). It only needs to happen once to the rootCmd.
45-
func Execute(vers string, writeKey string) {
40+
func Execute(vers string) {
4641
version = vers
47-
analyticsWriteKey = writeKey
48-
analyticsEnabled = analyticsWriteKey != ""
4942
if err := RootCmd.Execute(); err != nil {
5043
fmt.Fprintf(os.Stderr, "%s\n", err)
5144
switch err {
@@ -68,26 +61,6 @@ func prerun(cmd *cobra.Command, args []string) {
6861
if debug {
6962
log.SetLevel(log.DebugLevel)
7063
}
71-
72-
if analyticsEnabled {
73-
// set up analytics client
74-
analyticsClient, _ = analytics.NewWithConfig(analyticsWriteKey, analytics.Config{
75-
BatchSize: 1,
76-
})
77-
78-
username = os.Getenv("USER")
79-
analyticsClient.Enqueue(analytics.Identify{
80-
UserId: username,
81-
Traits: analytics.NewTraits().
82-
Set("aws-okta-version", version),
83-
})
84-
}
85-
}
86-
87-
func postrun(cmd *cobra.Command, args []string) {
88-
if analyticsEnabled && analyticsClient != nil {
89-
analyticsClient.Close()
90-
}
9164
}
9265

9366
func init() {

lib/okta.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import (
2020
"github.com/aws/aws-sdk-go/aws"
2121
"github.com/aws/aws-sdk-go/aws/session"
2222
"github.com/aws/aws-sdk-go/service/sts"
23-
"github.com/segmentio/aws-okta/lib/saml"
23+
"gitlab.corp.five.ai/infra/aws-okta/lib/saml"
2424
)
2525

26-
const (
27-
OktaServer = "okta.com"
28-
)
26+
var OktaServer = map[string]string{
27+
"emea": "okta-emea.com",
28+
"us": "okta.com",
29+
}
2930

3031
type OktaClient struct {
3132
Organization string
@@ -40,6 +41,7 @@ type OktaClient struct {
4041
OktaAwsSAMLUrl string
4142
CookieJar http.CookieJar
4243
BaseURL *url.URL
44+
OktaRegion string
4345
}
4446

4547
type SAMLAssertion struct {
@@ -48,14 +50,14 @@ type SAMLAssertion struct {
4850
}
4951

5052
type OktaCreds struct {
53+
Server string
5154
Organization string
5255
Username string
53-
Password string
5456
}
5557

5658
func NewOktaClient(creds OktaCreds, oktaAwsSAMLUrl string, sessionCookie string) (*OktaClient, error) {
5759
base, err := url.Parse(fmt.Sprintf(
58-
"https://%s.%s", creds.Organization, OktaServer,
60+
"https://%s.%s", creds.Organization, OktaServer[creds.Server],
5961
))
6062
if err != nil {
6163
return nil, err
@@ -75,13 +77,26 @@ func NewOktaClient(creds OktaCreds, oktaAwsSAMLUrl string, sessionCookie string)
7577
})
7678
}
7779

80+
fmt.Println()
81+
username, err := Prompt("Okta username", false)
82+
if err != nil {
83+
return nil, err
84+
}
85+
86+
password, err := Prompt("Okta password", true)
87+
if err != nil {
88+
return nil, err
89+
}
90+
fmt.Println()
91+
7892
return &OktaClient{
7993
Organization: creds.Organization,
80-
Username: creds.Username,
81-
Password: creds.Password,
94+
Username: username,
95+
Password: password,
8296
OktaAwsSAMLUrl: oktaAwsSAMLUrl,
8397
CookieJar: jar,
8498
BaseURL: base,
99+
OktaRegion: creds.Server,
85100
}, nil
86101
}
87102

@@ -107,6 +122,7 @@ func (o *OktaClient) AuthenticateProfile(profileARN string, duration time.Durati
107122
log.Debug("Step: 1")
108123
err = o.Get("POST", "api/v1/authn", payload, &oktaUserAuthn, "json")
109124
if err != nil {
125+
fmt.Println(err)
110126
return sts.Credentials{}, "", errors.New("Failed to authenticate with okta. Please check that your credentials have been set correctly with `aws-okta add`")
111127
}
112128

@@ -355,7 +371,7 @@ func (o *OktaClient) Get(method string, path string, data []byte, recv interface
355371
var client http.Client
356372

357373
url, err := url.Parse(fmt.Sprintf(
358-
"https://%s.%s/%s", o.Organization, OktaServer, path,
374+
"https://%s.%s/%s", o.Organization, OktaServer[o.OktaRegion], path,
359375
))
360376
if err != nil {
361377
return err

lib/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77
"strings"
88

9-
"github.com/segmentio/aws-okta/lib/saml"
9+
"gitlab.corp.five.ai/infra/aws-okta/lib/saml"
1010
"golang.org/x/net/html"
1111
)
1212

main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package main
22

33
import (
4-
"github.com/segmentio/aws-okta/cmd"
4+
"github.com/fiveai/aws-okta/cmd"
55
)
66

77
// These are set via linker flags
88
var (
9-
Version = "dev"
10-
AnalyticsWriteKey = ""
9+
Version = "dev"
1110
)
1211

1312
func main() {
1413
// vars set by linker flags must be strings...
15-
cmd.Execute(Version, AnalyticsWriteKey)
14+
cmd.Execute(Version)
1615
}

0 commit comments

Comments
 (0)