Skip to content

Commit 656d807

Browse files
update all deps to new changes (#3489)
1 parent 8b209a2 commit 656d807

File tree

7 files changed

+82
-87
lines changed

7 files changed

+82
-87
lines changed

api/client.go

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"io"
24+
"net/http"
2425
"path"
2526
"strings"
2627
"time"
@@ -288,6 +289,7 @@ type ConsoleCredentialsI interface {
288289
type ConsoleCredentials struct {
289290
ConsoleCredentials *credentials.Credentials
290291
AccountAccessKey string
292+
CredContext *credentials.CredContext
291293
}
292294

293295
func (c ConsoleCredentials) GetAccountAccessKey() string {
@@ -296,7 +298,7 @@ func (c ConsoleCredentials) GetAccountAccessKey() string {
296298

297299
// Get implements *Login.Get()
298300
func (c ConsoleCredentials) Get() (credentials.Value, error) {
299-
return c.ConsoleCredentials.Get()
301+
return c.ConsoleCredentials.GetWithContext(c.CredContext)
300302
}
301303

302304
// Expire implements *Login.Expire()
@@ -311,6 +313,10 @@ type consoleSTSAssumeRole struct {
311313
stsAssumeRole *credentials.STSAssumeRole
312314
}
313315

316+
func (s consoleSTSAssumeRole) RetrieveWithCredContext(cc *credentials.CredContext) (credentials.Value, error) {
317+
return s.stsAssumeRole.RetrieveWithCredContext(cc)
318+
}
319+
314320
func (s consoleSTSAssumeRole) Retrieve() (credentials.Value, error) {
315321
return s.stsAssumeRole.Retrieve()
316322
}
@@ -319,7 +325,7 @@ func (s consoleSTSAssumeRole) IsExpired() bool {
319325
return s.stsAssumeRole.IsExpired()
320326
}
321327

322-
func stsCredentials(minioURL, accessKey, secretKey, location, clientIP string) (*credentials.Credentials, error) {
328+
func stsCredentials(minioURL, accessKey, secretKey, location string, client *http.Client) (*credentials.Credentials, error) {
323329
if accessKey == "" || secretKey == "" {
324330
return nil, errors.New("credentials endpoint, access and secret key are mandatory for AssumeRoleSTS")
325331
}
@@ -330,59 +336,56 @@ func stsCredentials(minioURL, accessKey, secretKey, location, clientIP string) (
330336
DurationSeconds: int(xjwt.GetConsoleSTSDuration().Seconds()),
331337
}
332338
stsAssumeRole := &credentials.STSAssumeRole{
333-
Client: GetConsoleHTTPClient(clientIP),
339+
Client: client,
334340
STSEndpoint: minioURL,
335341
Options: opts,
336342
}
337343
consoleSTSWrapper := consoleSTSAssumeRole{stsAssumeRole: stsAssumeRole}
338344
return credentials.New(consoleSTSWrapper), nil
339345
}
340346

341-
func NewConsoleCredentials(accessKey, secretKey, location, clientIP string) (*credentials.Credentials, error) {
347+
func NewConsoleCredentials(accessKey, secretKey, location string, client *http.Client) (*credentials.Credentials, error) {
342348
minioURL := getMinIOServer()
343349

344-
// Future authentication methods can be added under this switch statement
345-
switch {
346350
// LDAP authentication for Console
347-
case ldap.GetLDAPEnabled():
348-
{
349-
creds, err := auth.GetCredentialsFromLDAP(GetConsoleHTTPClient(clientIP), minioURL, accessKey, secretKey)
350-
if err != nil {
351-
return nil, err
352-
}
351+
if ldap.GetLDAPEnabled() {
352+
creds, err := auth.GetCredentialsFromLDAP(client, minioURL, accessKey, secretKey)
353+
if err != nil {
354+
return nil, err
355+
}
353356

354-
// We verify if LDAP credentials are correct and no error is returned
355-
_, err = creds.Get()
357+
credContext := &credentials.CredContext{
358+
Client: client,
359+
}
356360

357-
if err != nil && strings.Contains(strings.ToLower(err.Error()), "not found") {
358-
// We try to use STS Credentials in case LDAP credentials are incorrect.
359-
stsCreds, errSTS := stsCredentials(minioURL, accessKey, secretKey, location, clientIP)
361+
// We verify if LDAP credentials are correct and no error is returned
362+
_, err = creds.GetWithContext(credContext)
360363

361-
// If there is an error with STS too, then we return the original LDAP error
362-
if errSTS != nil {
363-
LogError("error in STS credentials for LDAP case: %v ", errSTS)
364+
if err != nil && strings.Contains(strings.ToLower(err.Error()), "not found") {
365+
// We try to use STS Credentials in case LDAP credentials are incorrect.
366+
stsCreds, errSTS := stsCredentials(minioURL, accessKey, secretKey, location, client)
364367

365-
// We return LDAP result
366-
return creds, nil
367-
}
368+
// If there is an error with STS too, then we return the original LDAP error
369+
if errSTS != nil {
370+
LogError("error in STS credentials for LDAP case: %v ", errSTS)
368371

369-
_, err := stsCreds.Get()
370-
// There is an error with STS credentials, We return the result of LDAP as STS is not a priority in this case.
371-
if err != nil {
372-
return creds, nil
373-
}
372+
// We return LDAP result
373+
return creds, nil
374+
}
374375

375-
return stsCreds, nil
376+
_, err := stsCreds.GetWithContext(credContext)
377+
// There is an error with STS credentials, We return the result of LDAP as STS is not a priority in this case.
378+
if err != nil {
379+
return creds, nil
376380
}
377381

378-
return creds, nil
379-
}
380-
// default authentication for Console is via STS (Security Token Service) against MinIO
381-
default:
382-
{
383-
return stsCredentials(minioURL, accessKey, secretKey, location, clientIP)
382+
return stsCreds, nil
384383
}
384+
385+
return creds, nil
385386
}
387+
388+
return stsCredentials(minioURL, accessKey, secretKey, location, client)
386389
}
387390

388391
// getConsoleCredentialsFromSession returns the *consoleCredentials.Login associated to the

api/user_account.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func getChangePasswordResponse(session *models.Principal, params accountApi.Acco
5858
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
5959
defer cancel()
6060
clientIP := getClientIP(params.HTTPRequest)
61+
client := GetConsoleHTTPClient(clientIP)
6162

6263
// changePassword operations requires an AdminClient initialized with parent account credentials not
6364
// STS credentials
@@ -79,7 +80,7 @@ func getChangePasswordResponse(session *models.Principal, params accountApi.Acco
7980
}
8081
// user credentials are updated at this point, we need to generate a new admin client and authenticate using
8182
// the new credentials
82-
credentials, err := getConsoleCredentials(accessKey, newSecretKey, clientIP)
83+
credentials, err := getConsoleCredentials(accessKey, newSecretKey, client)
8384
if err != nil {
8485
return nil, ErrorWithContext(ctx, ErrInvalidLogin, nil, err)
8586
}

api/user_buckets.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/json"
2222
"errors"
2323
"fmt"
24+
"net/http"
2425
"strings"
2526
"time"
2627

@@ -29,6 +30,7 @@ import (
2930
"github.com/minio/madmin-go/v3"
3031
"github.com/minio/mc/cmd"
3132
"github.com/minio/mc/pkg/probe"
33+
"github.com/minio/minio-go/v7/pkg/credentials"
3234
"github.com/minio/minio-go/v7/pkg/sse"
3335
"github.com/minio/minio-go/v7/pkg/tags"
3436

@@ -1067,8 +1069,7 @@ func getMaxShareLinkExpirationResponse(session *models.Principal, params bucketA
10671069
// getMaxShareLinkExpirationSeconds returns the max share link expiration time in seconds which is the sts token expiration time
10681070
func getMaxShareLinkExpirationSeconds(session *models.Principal) (int64, error) {
10691071
creds := getConsoleCredentialsFromSession(session)
1070-
1071-
val, err := creds.Get()
1072+
val, err := creds.GetWithContext(&credentials.CredContext{Client: http.DefaultClient})
10721073
if err != nil {
10731074
return 0, err
10741075
}

api/user_login.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@ import (
2020
"context"
2121
"encoding/base64"
2222
"encoding/json"
23-
stderrors "errors"
2423
"fmt"
25-
"net"
2624
"net/http"
27-
"net/url"
2825
"strings"
2926

30-
"github.com/go-openapi/errors"
31-
3227
"github.com/go-openapi/runtime"
3328
"github.com/go-openapi/runtime/middleware"
3429
"github.com/minio/console/api/operations"
@@ -39,6 +34,7 @@ import (
3934
"github.com/minio/madmin-go/v3"
4035
"github.com/minio/minio-go/v7/pkg/credentials"
4136
"github.com/minio/pkg/v3/env"
37+
xnet "github.com/minio/pkg/v3/net"
4238
)
4339

4440
func registerLoginHandlers(api *operations.ConsoleAPI) {
@@ -114,14 +110,17 @@ func getAccountInfo(ctx context.Context, client MinioAdmin) (*madmin.AccountInfo
114110
}
115111

116112
// getConsoleCredentials will return ConsoleCredentials interface
117-
func getConsoleCredentials(accessKey, secretKey, clientIP string) (*ConsoleCredentials, error) {
118-
creds, err := NewConsoleCredentials(accessKey, secretKey, GetMinIORegion(), clientIP)
113+
func getConsoleCredentials(accessKey, secretKey string, client *http.Client) (*ConsoleCredentials, error) {
114+
creds, err := NewConsoleCredentials(accessKey, secretKey, GetMinIORegion(), client)
119115
if err != nil {
120116
return nil, err
121117
}
122118
return &ConsoleCredentials{
123119
ConsoleCredentials: creds,
124120
AccountAccessKey: accessKey,
121+
CredContext: &credentials.CredContext{
122+
Client: client,
123+
},
125124
}, nil
126125
}
127126

@@ -130,25 +129,24 @@ func getLoginResponse(params authApi.LoginParams) (*models.LoginResponse, *Coded
130129
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
131130
defer cancel()
132131
lr := params.Body
132+
133+
clientIP := getClientIP(params.HTTPRequest)
134+
client := GetConsoleHTTPClient(clientIP)
135+
133136
var err error
134137
var consoleCreds *ConsoleCredentials
135138
// if we receive an STS we use that instead of the credentials
136139
if lr.Sts != "" {
137-
creds := credentials.NewStaticV4(lr.AccessKey, lr.SecretKey, lr.Sts)
138140
consoleCreds = &ConsoleCredentials{
139-
ConsoleCredentials: creds,
141+
ConsoleCredentials: credentials.NewStaticV4(lr.AccessKey, lr.SecretKey, lr.Sts),
140142
AccountAccessKey: lr.AccessKey,
141-
}
142-
143-
credsVerificate, _ := creds.Get()
144-
145-
if credsVerificate.SessionToken == "" || credsVerificate.SecretAccessKey == "" || credsVerificate.AccessKeyID == "" {
146-
return nil, ErrorWithContext(ctx, errors.New(401, "Invalid STS Params"))
143+
CredContext: &credentials.CredContext{
144+
Client: client,
145+
},
147146
}
148147
} else {
149-
clientIP := getClientIP(params.HTTPRequest)
150148
// prepare console credentials
151-
consoleCreds, err = getConsoleCredentials(lr.AccessKey, lr.SecretKey, clientIP)
149+
consoleCreds, err = getConsoleCredentials(lr.AccessKey, lr.SecretKey, client)
152150
if err != nil {
153151
return nil, ErrorWithContext(ctx, err, ErrInvalidLogin)
154152
}
@@ -160,11 +158,8 @@ func getLoginResponse(params authApi.LoginParams) (*models.LoginResponse, *Coded
160158
}
161159
sessionID, err := login(consoleCreds, sf)
162160
if err != nil {
163-
var urlErr *url.Error
164-
if stderrors.As(err, &urlErr) {
165-
if _, isNetErr := urlErr.Err.(net.Error); isNetErr {
166-
return nil, ErrorWithContext(ctx, ErrNetworkError)
167-
}
161+
if xnet.IsNetworkOrHostDown(err, true) {
162+
return nil, ErrorWithContext(ctx, ErrNetworkError)
168163
}
169164
return nil, ErrorWithContext(ctx, err, ErrInvalidLogin)
170165
}
@@ -265,6 +260,7 @@ func getLoginOauth2AuthResponse(params authApi.LoginOauth2AuthParams, openIDProv
265260
r := params.HTTPRequest
266261
lr := params.Body
267262

263+
client := GetConsoleHTTPClient(getClientIP(params.HTTPRequest))
268264
if len(openIDProviders) > 0 {
269265
// we read state
270266
rState := *lr.State
@@ -288,8 +284,7 @@ func getLoginOauth2AuthResponse(params authApi.LoginOauth2AuthParams, openIDProv
288284
}
289285

290286
// Initialize new identity provider with new oauth2Client per IDPName
291-
oauth2Client, err := providerCfg.GetOauth2Provider(IDPName, nil, r,
292-
GetConsoleHTTPClient(getClientIP(params.HTTPRequest)))
287+
oauth2Client, err := providerCfg.GetOauth2Provider(IDPName, nil, r, client)
293288
if err != nil {
294289
return nil, ErrorWithContext(ctx, err)
295290
}
@@ -309,6 +304,7 @@ func getLoginOauth2AuthResponse(params authApi.LoginOauth2AuthParams, openIDProv
309304
token, err := login(&ConsoleCredentials{
310305
ConsoleCredentials: userCredentials,
311306
AccountAccessKey: "",
307+
CredContext: &credentials.CredContext{Client: client},
312308
}, nil)
313309
if err != nil {
314310
return nil, ErrorWithContext(ctx, err)

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ require (
2121
github.com/minio/cli v1.24.2
2222
github.com/minio/highwayhash v1.0.3
2323
github.com/minio/kes v0.23.0
24-
github.com/minio/madmin-go/v3 v3.0.81
24+
github.com/minio/madmin-go/v3 v3.0.85
2525
github.com/minio/mc v0.0.0-20241215225040-f4dd5e4a07ff
26-
github.com/minio/minio-go/v7 v7.0.82
26+
github.com/minio/minio-go/v7 v7.0.83-0.20241230094935-5757f2c8544a
2727
github.com/minio/selfupdate v0.6.0
2828
github.com/minio/websocket v1.6.0
2929
github.com/mitchellh/go-homedir v1.1.0
@@ -33,15 +33,15 @@ require (
3333
github.com/tidwall/gjson v1.17.3 // indirect
3434
github.com/unrolled/secure v1.15.0
3535
golang.org/x/crypto v0.31.0
36-
golang.org/x/net v0.32.0
36+
golang.org/x/net v0.33.0
3737
golang.org/x/oauth2 v0.24.0
3838
// Added to include security fix for
3939
// https://github.com/golang/go/issues/56152
4040
golang.org/x/text v0.21.0 // indirect
4141
gopkg.in/yaml.v2 v2.4.0 // indirect
4242
)
4343

44-
require github.com/minio/pkg/v3 v3.0.24
44+
require github.com/minio/pkg/v3 v3.0.25
4545

4646
require (
4747
aead.dev/mem v0.2.0 // indirect

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,18 @@ github.com/minio/kes v0.23.0 h1:T0zHtyDoI3JdKrVvzdM4xwVryYYyh5pKwNUVBoqxsNs=
179179
github.com/minio/kes v0.23.0/go.mod h1:vvXVGcgu9mYLkbVWlEvFFl6bYR196RQlOU2Q+rHApl8=
180180
github.com/minio/kes-go v0.2.1 h1:KnqS+p6xoSFJZbQhmJaz/PbxeA6nQyRqT/ywrn5lU2o=
181181
github.com/minio/kes-go v0.2.1/go.mod h1:76xf7l41Wrh+IifisABXK2S8uZWYgWV1IGBKC3GdOJk=
182-
github.com/minio/madmin-go/v3 v3.0.81 h1:sEGhX3gEHciUT6H5O2qyOJ4Nr31vssQUikDcygMcPms=
183-
github.com/minio/madmin-go/v3 v3.0.81/go.mod h1:QAZPX3xx4gdZbZ8t85SieFSwXMOQhFx7bVjldhyc6Bk=
182+
github.com/minio/madmin-go/v3 v3.0.85 h1:bP63oKd5YclvjuUw58BtE8cME0VAoZwvwUV50lEvES4=
183+
github.com/minio/madmin-go/v3 v3.0.85/go.mod h1:pMLdj9OtN0CANNs5tdm6opvOlDFfj0WhbztboZAjRWE=
184184
github.com/minio/mc v0.0.0-20241215225040-f4dd5e4a07ff h1:KOiKIGERKan7dcg8T9hSFj1/DFSw3X1r7p+NFGFsGBo=
185185
github.com/minio/mc v0.0.0-20241215225040-f4dd5e4a07ff/go.mod h1:kKjtUlsNcehsP5f2ji9SicURHyTdlZ9kY2/sCwHKOVk=
186186
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
187187
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
188-
github.com/minio/minio-go/v7 v7.0.82 h1:tWfICLhmp2aFPXL8Tli0XDTHj2VB/fNf0PC1f/i1gRo=
189-
github.com/minio/minio-go/v7 v7.0.82/go.mod h1:84gmIilaX4zcvAWWzJ5Z1WI5axN+hAbM5w25xf8xvC0=
188+
github.com/minio/minio-go/v7 v7.0.83-0.20241230094935-5757f2c8544a h1:nPw29aor4WGYpmBZy5jQT/cW5wtFrG8tEOCNeltMcq8=
189+
github.com/minio/minio-go/v7 v7.0.83-0.20241230094935-5757f2c8544a/go.mod h1:57YXpvc5l3rjPdhqNrDsvVlY0qPI6UTk1bflAe+9doY=
190190
github.com/minio/mux v1.9.0 h1:dWafQFyEfGhJvK6AwLOt83bIG5bxKxKJnKMCi0XAaoA=
191191
github.com/minio/mux v1.9.0/go.mod h1:1pAare17ZRL5GpmNL+9YmqHoWnLmMZF9C/ioUCfy0BQ=
192-
github.com/minio/pkg/v3 v3.0.24 h1:DyaUMvPYueuEn3Tx0kDlU3qFHx/Ygfw9q/2bEp3erR8=
193-
github.com/minio/pkg/v3 v3.0.24/go.mod h1:mIaN552nu0D2jiSk5BQC8LB25f44ytbOBJCuLtksX7Q=
192+
github.com/minio/pkg/v3 v3.0.25 h1:bfxBcxN77uLNiI+qY4/0fxXF4lVdJulwkcJNZcvc1xg=
193+
github.com/minio/pkg/v3 v3.0.25/go.mod h1:mIaN552nu0D2jiSk5BQC8LB25f44ytbOBJCuLtksX7Q=
194194
github.com/minio/selfupdate v0.6.0 h1:i76PgT0K5xO9+hjzKcacQtO7+MjJ4JKA8Ak8XQ9DDwU=
195195
github.com/minio/selfupdate v0.6.0/go.mod h1:bO02GTIPCMQFTEvE5h4DjYB58bCoZ35XLeBf0buTDdM=
196196
github.com/minio/websocket v1.6.0 h1:CPvnQvNvlVaQmvw5gtJNyYQhg4+xRmrPNhBbv8BdpAE=
@@ -326,8 +326,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
326326
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
327327
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
328328
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
329-
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
330-
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
329+
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
330+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
331331
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
332332
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
333333
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

0 commit comments

Comments
 (0)