This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
forked from Versent/saml2aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saml2aws.go
198 lines (184 loc) · 7.64 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package saml2aws
import (
"fmt"
"sort"
"github.com/versent/saml2aws/v2/pkg/cfg"
"github.com/versent/saml2aws/v2/pkg/creds"
"github.com/versent/saml2aws/v2/pkg/provider/aad"
"github.com/versent/saml2aws/v2/pkg/provider/adfs"
"github.com/versent/saml2aws/v2/pkg/provider/adfs2"
"github.com/versent/saml2aws/v2/pkg/provider/akamai"
"github.com/versent/saml2aws/v2/pkg/provider/auth0"
"github.com/versent/saml2aws/v2/pkg/provider/authentik"
"github.com/versent/saml2aws/v2/pkg/provider/browser"
"github.com/versent/saml2aws/v2/pkg/provider/f5apm"
"github.com/versent/saml2aws/v2/pkg/provider/googleapps"
"github.com/versent/saml2aws/v2/pkg/provider/jumpcloud"
"github.com/versent/saml2aws/v2/pkg/provider/keycloak"
"github.com/versent/saml2aws/v2/pkg/provider/netiq"
"github.com/versent/saml2aws/v2/pkg/provider/okta"
"github.com/versent/saml2aws/v2/pkg/provider/onelogin"
"github.com/versent/saml2aws/v2/pkg/provider/pingfed"
"github.com/versent/saml2aws/v2/pkg/provider/pingntlm"
"github.com/versent/saml2aws/v2/pkg/provider/pingone"
"github.com/versent/saml2aws/v2/pkg/provider/shell"
"github.com/versent/saml2aws/v2/pkg/provider/shibboleth"
"github.com/versent/saml2aws/v2/pkg/provider/shibbolethecp"
)
// 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", "Azure", "Defender"},
"ADFS2": []string{"Auto", "RSA"}, // nothing automatic about ADFS 2.x
"Ping": []string{"Auto"}, // automatically detects PingID
"PingNTLM": []string{"Auto"}, // automatically detects PingID
"PingOne": []string{"Auto"}, // automatically detects PingID
"JumpCloud": []string{"Auto", "TOTP", "WEBAUTHN", "DUO", "PUSH"},
"Okta": []string{"Auto", "PUSH", "DUO", "SMS", "TOTP", "OKTA", "FIDO", "YUBICO TOKEN:HARDWARE", "SYMANTEC"}, // automatically detects DUO, SMS, ToTP, and FIDO
"OneLogin": []string{"Auto", "OLP", "SMS", "TOTP", "YUBIKEY", "DUO TOTP"}, // automatically detects OneLogin Protect, SMS and ToTP
"Authentik": []string{"Auto"},
"KeyCloak": []string{"Auto"}, // automatically detects ToTP
"GoogleApps": []string{"Auto"}, // automatically detects ToTP
"Shibboleth": []string{"Auto", "None"},
"F5APM": []string{"Auto"},
"Akamai": []string{"Auto", "DUO", "SMS", "EMAIL", "TOTP"},
"ShibbolethECP": []string{"auto", "phone", "push", "passcode"},
"NetIQ": []string{"Auto", "Privileged"},
"Browser": []string{"Auto"},
"Auth0": []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)
Validate(loginDetails *creds.LoginDetails) 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 "PingNTLM":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return pingntlm.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 "Authentik":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return authentik.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 "ShibbolethECP":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return shibbolethecp.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)
case "Akamai":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return akamai.New(idpAccount)
case "Shell":
return shell.New(idpAccount)
case "NetIQ":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return netiq.New(idpAccount, idpAccount.MFA)
case "Browser":
return browser.New(idpAccount)
case "Auth0":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return auth0.New(idpAccount)
default:
return nil, fmt.Errorf("Invalid provider: %v", idpAccount.Provider)
}
}