forked from Versent/saml2aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saml2aws.go
156 lines (141 loc) · 5.72 KB
/
saml2aws.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package saml2aws
import (
"fmt"
"sort"
"github.com/tinder-edwardowens/saml2aws/pkg/cfg"
"github.com/tinder-edwardowens/saml2aws/pkg/creds"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/aad"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/adfs"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/adfs2"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/f5apm"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/googleapps"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/jumpcloud"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/keycloak"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/okta"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/onelogin"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/pingfed"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/pingone"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/psu"
"github.com/tinder-edwardowens/saml2aws/pkg/provider/shibboleth"
)
// ProviderList list of providers with their MFAs
type ProviderList map[string][]string
// MFAsByProvider a list of providers with their respective supported MFAs
var MFAsByProvider = ProviderList{
"AzureAD": []string{"Auto", "PhoneAppOTP", "PhoneAppNotification", "OneWaySMS"},
"ADFS": []string{"Auto", "VIP"},
"ADFS2": []string{"Auto", "RSA"}, // nothing automatic about ADFS 2.x
"Ping": []string{"Auto"}, // automatically detects PingID
"PingOne": []string{"Auto"}, // automatically detects PingID
"JumpCloud": []string{"Auto"},
"Okta": []string{"Auto", "PUSH", "DUO", "SMS", "TOTP", "OKTA"}, // automatically detects DUO, SMS and ToTP
"OneLogin": []string{"Auto", "OLP", "SMS", "TOTP"}, // automatically detects OneLogin Protect, SMS and ToTP
"KeyCloak": []string{"Auto"}, // automatically detects ToTP
"GoogleApps": []string{"Auto"}, // automatically detects ToTP
"Shibboleth": []string{"Auto"},
"PSU": []string{"Auto"},
"F5APM": []string{"Auto"},
}
// Names get a list of provider names
func (mfbp ProviderList) Names() []string {
keys := []string{}
for k := range mfbp {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
// Mfas retrieve a sorted list of mfas from the provider list
func (mfbp ProviderList) Mfas(provider string) []string {
mfas := mfbp[provider]
sort.Strings(mfas)
return mfas
}
func (mfbp ProviderList) stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func invalidMFA(provider string, mfa string) bool {
supportedMfas := MFAsByProvider.Mfas(provider)
return !MFAsByProvider.stringInSlice(mfa, supportedMfas)
}
// SAMLClient client interface
type SAMLClient interface {
Authenticate(loginDetails *creds.LoginDetails) (string, error)
}
// NewSAMLClient create a new SAML client
func NewSAMLClient(idpAccount *cfg.IDPAccount) (SAMLClient, error) {
switch idpAccount.Provider {
case "AzureAD":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return aad.New(idpAccount)
case "ADFS":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return adfs.New(idpAccount)
case "ADFS2":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return adfs2.New(idpAccount)
case "Ping":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return pingfed.New(idpAccount)
case "PingOne":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return pingone.New(idpAccount)
case "JumpCloud":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return jumpcloud.New(idpAccount)
case "Okta":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return okta.New(idpAccount)
case "OneLogin":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return onelogin.New(idpAccount)
case "KeyCloak":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return keycloak.New(idpAccount)
case "GoogleApps":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return googleapps.New(idpAccount)
case "Shibboleth":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return shibboleth.New(idpAccount)
case "PSU":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return psu.New(idpAccount)
case "F5APM":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return f5apm.New(idpAccount)
default:
return nil, fmt.Errorf("Invalid provider: %v", idpAccount.Provider)
}
}