-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
113 lines (100 loc) · 2.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"log"
"os"
"os/exec"
"github.com/urfave/cli/v2"
)
func main() {
auth := AwsJumpCloudAuth{
MFAToken: "",
SessionTimeout: 3600,
}
app := &cli.App{
Name: "aws-saml",
Usage: "Authenticate awscli with AWS JumpCloud saml assertion",
UsageText: "aws-saml --email <email> --password <password> [...flags]",
Flags: []cli.Flag{
&cli.StringFlag{
Aliases: []string{"e"},
Destination: &auth.Email,
Name: "email",
Required: true,
Usage: "JumpCloud email",
},
&cli.StringFlag{
Aliases: []string{"p"},
Destination: &auth.Password,
Name: "password",
Required: true,
Usage: "JumpCloud password",
},
&cli.StringFlag{
Destination: &auth.PrincipalArn,
Name: "principal-arn",
Required: true,
Usage: "AWS SAML-provider ARN",
Value: auth.PrincipalArn,
},
&cli.StringFlag{
Destination: &auth.RoleArn,
Name: "role-arn",
Required: true,
Usage: "AWS role ARN",
Value: auth.RoleArn,
},
&cli.IntFlag{
Destination: &auth.SessionTimeout,
Name: "session-timeout",
Usage: "AWS session timeout in seconds",
Value: auth.SessionTimeout,
},
&cli.StringFlag{
Aliases: []string{"t"},
Destination: &auth.MFAToken,
Name: "mfa-token",
Usage: "Time-based One Time Password (TOTP)",
Value: auth.MFAToken,
},
},
Action: func(c *cli.Context) error {
auth.shell()
return nil
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
type AwsJumpCloudAuth struct {
Email string
Password string
PrincipalArn string
RoleArn string
SessionTimeout int
MFAToken string
}
func (auth *AwsJumpCloudAuth) shell() {
iexec(auth.env())
}
func (auth *AwsJumpCloudAuth) env() []string {
saml := NewJumpCloudSession().
Login(auth.Email, auth.Password, auth.MFAToken).
getSamlRequest()
credentials := AwsSamlSession(AwsSamlSessionInput{
auth.PrincipalArn,
auth.RoleArn,
saml,
int32(auth.SessionTimeout),
})
return credentials.toEnv()
}
func iexec(env []string) {
cmd := exec.Command("bash", "-i")
cmd.Env = append(os.Environ(), env...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
}