@@ -329,6 +329,25 @@ func (s consoleSTSAssumeRole) IsExpired() bool {
329
329
return s .stsAssumeRole .IsExpired ()
330
330
}
331
331
332
+ func stsCredentials (minioURL , accessKey , secretKey , location string ) (* credentials.Credentials , error ) {
333
+ if accessKey == "" || secretKey == "" {
334
+ return nil , errors .New ("credentials endpoint, access and secret key are mandatory for AssumeRoleSTS" )
335
+ }
336
+ opts := credentials.STSAssumeRoleOptions {
337
+ AccessKey : accessKey ,
338
+ SecretKey : secretKey ,
339
+ Location : location ,
340
+ DurationSeconds : int (xjwt .GetConsoleSTSDuration ().Seconds ()),
341
+ }
342
+ stsAssumeRole := & credentials.STSAssumeRole {
343
+ Client : GetConsoleHTTPClient (minioURL ),
344
+ STSEndpoint : minioURL ,
345
+ Options : opts ,
346
+ }
347
+ consoleSTSWrapper := consoleSTSAssumeRole {stsAssumeRole : stsAssumeRole }
348
+ return credentials .New (consoleSTSWrapper ), nil
349
+ }
350
+
332
351
func NewConsoleCredentials (accessKey , secretKey , location string ) (* credentials.Credentials , error ) {
333
352
minioURL := getMinIOServer ()
334
353
@@ -341,27 +360,37 @@ func NewConsoleCredentials(accessKey, secretKey, location string) (*credentials.
341
360
if err != nil {
342
361
return nil , err
343
362
}
363
+
364
+ // We verify if LDAP credentials are correct and no error is returned
365
+ _ , err = creds .Get ()
366
+
367
+ if err != nil && strings .Contains (strings .ToLower (err .Error ()), "not found" ) {
368
+ // We try to use STS Credentials in case LDAP credentials are incorrect.
369
+ stsCreds , errSTS := stsCredentials (minioURL , accessKey , secretKey , location )
370
+
371
+ // If there is an error with STS too, then we return the original LDAP error
372
+ if errSTS != nil {
373
+ LogError ("error in STS credentials for LDAP case: %v " , errSTS )
374
+
375
+ // We return LDAP result
376
+ return creds , nil
377
+ }
378
+
379
+ _ , err := stsCreds .Get ()
380
+ // There is an error with STS credentials, We return the result of LDAP as STS is not a priority in this case.
381
+ if err != nil {
382
+ return creds , nil
383
+ }
384
+
385
+ return stsCreds , nil
386
+ }
387
+
344
388
return creds , nil
345
389
}
346
390
// default authentication for Console is via STS (Security Token Service) against MinIO
347
391
default :
348
392
{
349
- if accessKey == "" || secretKey == "" {
350
- return nil , errors .New ("credentials endpoint, access and secret key are mandatory for AssumeRoleSTS" )
351
- }
352
- opts := credentials.STSAssumeRoleOptions {
353
- AccessKey : accessKey ,
354
- SecretKey : secretKey ,
355
- Location : location ,
356
- DurationSeconds : int (xjwt .GetConsoleSTSDuration ().Seconds ()),
357
- }
358
- stsAssumeRole := & credentials.STSAssumeRole {
359
- Client : GetConsoleHTTPClient (minioURL ),
360
- STSEndpoint : minioURL ,
361
- Options : opts ,
362
- }
363
- consoleSTSWrapper := consoleSTSAssumeRole {stsAssumeRole : stsAssumeRole }
364
- return credentials .New (consoleSTSWrapper ), nil
393
+ return stsCredentials (minioURL , accessKey , secretKey , location )
365
394
}
366
395
}
367
396
}
0 commit comments