@@ -14,6 +14,8 @@ import (
14
14
"runtime"
15
15
"strings"
16
16
17
+ "github.com/aws/aws-sdk-go/aws/request"
18
+
17
19
"github.com/google/uuid"
18
20
qrcode "github.com/skip2/go-qrcode"
19
21
@@ -32,11 +34,13 @@ const (
32
34
// MFAOutputFormatQRCode represents showing the MFA details as a QR code
33
35
MFAOutputFormatQRCode = "qrcode"
34
36
// MFAOutputFormatText represents showing the MFA details as text
35
- MFAOutputFormatText = "text"
36
- defaultOneTimePasswordType = "TOTP"
37
- defaultOneTimePasswordDigits = 6
38
- defaultOneTimePasswordAlgorithm = "SHA1"
39
- defaultOneTimePasswordInterval = 30
37
+ MFAOutputFormatText = "text"
38
+ defaultOneTimePasswordType = "TOTP"
39
+ defaultOneTimePasswordDigits = 6
40
+ defaultOneTimePasswordAlgorithm = "SHA1"
41
+ defaultOneTimePasswordInterval = 30
42
+ defaultRelevantUserPoolClientKeyword = "argocd"
43
+ defaultQRCodePixelSize = 256
40
44
)
41
45
42
46
type userPoolClient struct {
@@ -127,24 +131,29 @@ func getRelevantUserPoolID(ctx context.Context, provider cognitoidentityprovider
127
131
return "" , fmt .Errorf ("no user pool found for cluster %s" , cluster .Metadata .Name )
128
132
}
129
133
130
- func getRelevantUserPoolClient (ctx context.Context , provider cognitoidentityprovideriface. CognitoIdentityProviderAPI , userPoolClientID string ) (
134
+ func getRelevantUserPoolClient (ctx context.Context , provider userpoolClientsLister , userPoolID string ) (
131
135
cognitoidentityprovider.UserPoolClientDescription ,
132
136
error ,
133
137
) {
134
138
var nextToken * string
135
139
136
140
for {
137
141
listUserPoolsResult , err := provider .ListUserPoolClientsWithContext (ctx , & cognitoidentityprovider.ListUserPoolClientsInput {
138
- MaxResults : aws .Int64 (1 ),
142
+ MaxResults : aws .Int64 (maximumMaximumUserPoolResults ),
139
143
NextToken : nextToken ,
140
- UserPoolId : aws .String (userPoolClientID ),
144
+ UserPoolId : aws .String (userPoolID ),
141
145
})
142
146
if err != nil {
143
147
return cognitoidentityprovider.UserPoolClientDescription {}, fmt .Errorf ("listing user pools: %w" , err )
144
148
}
145
149
146
150
for _ , client := range listUserPoolsResult .UserPoolClients {
147
- return * client , nil
151
+ // This should be any of the clients provisioned by okctl, but due to inconsistent naming of the Grafana client
152
+ // secret SSM parameter and the situation regarding golden path we'll settle on picking the ArgoCD client for
153
+ // now. This breaks MFA for environments without ArgoCD.
154
+ if strings .Contains (* client .ClientName , defaultRelevantUserPoolClientKeyword ) {
155
+ return * client , nil
156
+ }
148
157
}
149
158
150
159
if listUserPoolsResult .NextToken == nil {
@@ -154,7 +163,7 @@ func getRelevantUserPoolClient(ctx context.Context, provider cognitoidentityprov
154
163
nextToken = listUserPoolsResult .NextToken
155
164
}
156
165
157
- return cognitoidentityprovider.UserPoolClientDescription {}, fmt .Errorf ("no clients found for user pool %s" , userPoolClientID )
166
+ return cognitoidentityprovider.UserPoolClientDescription {}, fmt .Errorf ("no clients found for user pool %s" , userPoolID )
158
167
}
159
168
160
169
func getCognitoClientSecretForClient (ctx context.Context , provider ssmiface.SSMAPI , clientName string ) (string , error ) {
@@ -226,7 +235,7 @@ func generateDeviceSecretQRCode(cluster v1alpha1.Cluster, userEmail string, secr
226
235
defaultOneTimePasswordInterval ,
227
236
)
228
237
229
- err := qrcode .WriteFile (qrCodeURI , qrcode .Medium , 256 , qrCodePath )
238
+ err := qrcode .WriteFile (qrCodeURI , qrcode .Medium , defaultQRCodePixelSize , qrCodePath )
230
239
if err != nil {
231
240
return "" , fmt .Errorf ("writing QR code: %w" , err )
232
241
}
@@ -253,3 +262,11 @@ func openbrowser(url string) {
253
262
log .Fatal (err )
254
263
}
255
264
}
265
+
266
+ type userpoolClientsLister interface {
267
+ ListUserPoolClientsWithContext (
268
+ context.Context ,
269
+ * cognitoidentityprovider.ListUserPoolClientsInput ,
270
+ ... request.Option ,
271
+ ) (* cognitoidentityprovider.ListUserPoolClientsOutput , error )
272
+ }
0 commit comments