Skip to content

Commit f054b1c

Browse files
authored
Ensure GetConsoleSTSClient() is used correctly (#425)
1 parent 7a23582 commit f054b1c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

restapi/client-admin.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func newAdminFromClaims(claims *models.Principal) (*madmin.AdminClient, error) {
307307
if err != nil {
308308
return nil, err
309309
}
310-
adminClient.SetCustomTransport(getSTSClient().Transport)
310+
adminClient.SetCustomTransport(GetConsoleSTSClient().Transport)
311311
return adminClient, nil
312312
}
313313

@@ -316,17 +316,20 @@ var (
316316
consoleSecretKey = getSecretKey()
317317
)
318318

319-
// stsClient is an http.Client with Custom TLS Transport that loads certificates from .console/certs/CAs
319+
// stsClient is a custom http client, this client should not be called directly and instead be
320+
// called using GetConsoleSTSClient() to ensure is initialized and the certificates are loaded correctly
320321
var stsClient *http.Client
321-
var consoleLDAPAdminCreds consoleCredentials
322322

323-
func getSTSClient() *http.Client {
323+
// GetConsoleSTSClient will initialize the console STS Client with Custom TLS Transport that with loads certs at .console/certs/CAs
324+
func GetConsoleSTSClient() *http.Client {
324325
if stsClient == nil {
325326
stsClient = PrepareSTSClient(false)
326327
}
327328
return stsClient
328329
}
329330

331+
var consoleLDAPAdminCreds consoleCredentials
332+
330333
func newSuperMAdminClient() (*madmin.AdminClient, error) {
331334
accessKey := consoleAccessKey
332335
secretKey := consoleSecretKey
@@ -336,7 +339,7 @@ func newSuperMAdminClient() (*madmin.AdminClient, error) {
336339
if ldap.GetLDAPEnabled() {
337340
// initialize LDAP super Admin Credentials once
338341
if consoleLDAPAdminCreds.consoleCredentials == nil {
339-
consoleCredentialsFromLDAP, err := auth.GetCredentialsFromLDAP(getSTSClient(), MinioEndpoint, consoleAccessKey, consoleSecretKey)
342+
consoleCredentialsFromLDAP, err := auth.GetCredentialsFromLDAP(GetConsoleSTSClient(), MinioEndpoint, consoleAccessKey, consoleSecretKey)
340343
if err != nil {
341344
return nil, err
342345
}

restapi/client.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ func (s consoleSTSAssumeRole) IsExpired() bool {
266266
return s.stsAssumeRole.IsExpired()
267267
}
268268

269-
// STSClient contains http.client configuration need it by STSAssumeRole
270269
var (
271270
MinioEndpoint = getMinIOServer()
272271
)
@@ -289,7 +288,7 @@ func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.
289288
if MinioEndpoint == "" {
290289
return nil, errors.New("endpoint cannot be empty for AssumeRoleSTS")
291290
}
292-
creds, err := auth.GetCredentialsFromLDAP(stsClient, MinioEndpoint, accessKey, secretKey)
291+
creds, err := auth.GetCredentialsFromLDAP(GetConsoleSTSClient(), MinioEndpoint, accessKey, secretKey)
293292
if err != nil {
294293
return nil, err
295294
}
@@ -308,7 +307,7 @@ func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.
308307
DurationSeconds: xjwt.GetConsoleSTSDurationInSeconds(),
309308
}
310309
stsAssumeRole := &credentials.STSAssumeRole{
311-
Client: stsClient,
310+
Client: GetConsoleSTSClient(),
312311
STSEndpoint: MinioEndpoint,
313312
Options: opts,
314313
}
@@ -331,7 +330,7 @@ func newMinioClient(claims *models.Principal) (*minio.Client, error) {
331330
minioClient, err := minio.New(getMinIOEndpoint(), &minio.Options{
332331
Creds: creds,
333332
Secure: getMinIOEndpointIsSecure(),
334-
Transport: stsClient.Transport,
333+
Transport: GetConsoleSTSClient().Transport,
335334
})
336335
if err != nil {
337336
return nil, err

0 commit comments

Comments
 (0)