@@ -329,6 +329,25 @@ func (s consoleSTSAssumeRole) IsExpired() bool {
329329 return s .stsAssumeRole .IsExpired ()
330330}
331331
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+
332351func NewConsoleCredentials (accessKey , secretKey , location string ) (* credentials.Credentials , error ) {
333352 minioURL := getMinIOServer ()
334353
@@ -341,27 +360,37 @@ func NewConsoleCredentials(accessKey, secretKey, location string) (*credentials.
341360 if err != nil {
342361 return nil , err
343362 }
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+
344388 return creds , nil
345389 }
346390 // default authentication for Console is via STS (Security Token Service) against MinIO
347391 default :
348392 {
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 )
365394 }
366395 }
367396}
0 commit comments