@@ -20,15 +20,10 @@ import (
20
20
"context"
21
21
"encoding/base64"
22
22
"encoding/json"
23
- stderrors "errors"
24
23
"fmt"
25
- "net"
26
24
"net/http"
27
- "net/url"
28
25
"strings"
29
26
30
- "github.com/go-openapi/errors"
31
-
32
27
"github.com/go-openapi/runtime"
33
28
"github.com/go-openapi/runtime/middleware"
34
29
"github.com/minio/console/api/operations"
@@ -39,6 +34,7 @@ import (
39
34
"github.com/minio/madmin-go/v3"
40
35
"github.com/minio/minio-go/v7/pkg/credentials"
41
36
"github.com/minio/pkg/v3/env"
37
+ xnet "github.com/minio/pkg/v3/net"
42
38
)
43
39
44
40
func registerLoginHandlers (api * operations.ConsoleAPI ) {
@@ -114,14 +110,17 @@ func getAccountInfo(ctx context.Context, client MinioAdmin) (*madmin.AccountInfo
114
110
}
115
111
116
112
// 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 )
119
115
if err != nil {
120
116
return nil , err
121
117
}
122
118
return & ConsoleCredentials {
123
119
ConsoleCredentials : creds ,
124
120
AccountAccessKey : accessKey ,
121
+ CredContext : & credentials.CredContext {
122
+ Client : client ,
123
+ },
125
124
}, nil
126
125
}
127
126
@@ -130,25 +129,24 @@ func getLoginResponse(params authApi.LoginParams) (*models.LoginResponse, *Coded
130
129
ctx , cancel := context .WithCancel (params .HTTPRequest .Context ())
131
130
defer cancel ()
132
131
lr := params .Body
132
+
133
+ clientIP := getClientIP (params .HTTPRequest )
134
+ client := GetConsoleHTTPClient (clientIP )
135
+
133
136
var err error
134
137
var consoleCreds * ConsoleCredentials
135
138
// if we receive an STS we use that instead of the credentials
136
139
if lr .Sts != "" {
137
- creds := credentials .NewStaticV4 (lr .AccessKey , lr .SecretKey , lr .Sts )
138
140
consoleCreds = & ConsoleCredentials {
139
- ConsoleCredentials : creds ,
141
+ ConsoleCredentials : credentials . NewStaticV4 ( lr . AccessKey , lr . SecretKey , lr . Sts ) ,
140
142
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
+ },
147
146
}
148
147
} else {
149
- clientIP := getClientIP (params .HTTPRequest )
150
148
// prepare console credentials
151
- consoleCreds , err = getConsoleCredentials (lr .AccessKey , lr .SecretKey , clientIP )
149
+ consoleCreds , err = getConsoleCredentials (lr .AccessKey , lr .SecretKey , client )
152
150
if err != nil {
153
151
return nil , ErrorWithContext (ctx , err , ErrInvalidLogin )
154
152
}
@@ -160,11 +158,8 @@ func getLoginResponse(params authApi.LoginParams) (*models.LoginResponse, *Coded
160
158
}
161
159
sessionID , err := login (consoleCreds , sf )
162
160
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 )
168
163
}
169
164
return nil , ErrorWithContext (ctx , err , ErrInvalidLogin )
170
165
}
@@ -265,6 +260,7 @@ func getLoginOauth2AuthResponse(params authApi.LoginOauth2AuthParams, openIDProv
265
260
r := params .HTTPRequest
266
261
lr := params .Body
267
262
263
+ client := GetConsoleHTTPClient (getClientIP (params .HTTPRequest ))
268
264
if len (openIDProviders ) > 0 {
269
265
// we read state
270
266
rState := * lr .State
@@ -288,8 +284,7 @@ func getLoginOauth2AuthResponse(params authApi.LoginOauth2AuthParams, openIDProv
288
284
}
289
285
290
286
// 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 )
293
288
if err != nil {
294
289
return nil , ErrorWithContext (ctx , err )
295
290
}
@@ -309,6 +304,7 @@ func getLoginOauth2AuthResponse(params authApi.LoginOauth2AuthParams, openIDProv
309
304
token , err := login (& ConsoleCredentials {
310
305
ConsoleCredentials : userCredentials ,
311
306
AccountAccessKey : "" ,
307
+ CredContext : & credentials.CredContext {Client : client },
312
308
}, nil )
313
309
if err != nil {
314
310
return nil , ErrorWithContext (ctx , err )
0 commit comments