@@ -177,9 +177,19 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
177
177
return
178
178
}
179
179
180
+ clientIP := getSourceIPFromHeaders (req )
181
+ if clientIP == "" {
182
+ if ip , _ , err := net .SplitHostPort (conn .RemoteAddr ().String ()); err == nil {
183
+ clientIP = ip
184
+ } else {
185
+ // In case there's an error, return an empty string
186
+ LogError ("Invalid ws.RemoteAddr() = %v\n " , err )
187
+ }
188
+ }
189
+
180
190
switch {
181
191
case strings .HasPrefix (wsPath , `/trace` ):
182
- wsAdminClient , err := newWebSocketAdminClient (conn , session )
192
+ wsAdminClient , err := newWebSocketAdminClient (conn , session , clientIP )
183
193
if err != nil {
184
194
ErrorWithContext (ctx , err )
185
195
closeWsConn (conn )
@@ -216,7 +226,7 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
216
226
go wsAdminClient .trace (ctx , traceRequestItem )
217
227
case strings .HasPrefix (wsPath , `/console` ):
218
228
219
- wsAdminClient , err := newWebSocketAdminClient (conn , session )
229
+ wsAdminClient , err := newWebSocketAdminClient (conn , session , clientIP )
220
230
if err != nil {
221
231
ErrorWithContext (ctx , err )
222
232
closeWsConn (conn )
@@ -237,7 +247,7 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
237
247
closeWsConn (conn )
238
248
return
239
249
}
240
- wsAdminClient , err := newWebSocketAdminClient (conn , session )
250
+ wsAdminClient , err := newWebSocketAdminClient (conn , session , clientIP )
241
251
if err != nil {
242
252
ErrorWithContext (ctx , err )
243
253
closeWsConn (conn )
@@ -251,7 +261,7 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
251
261
closeWsConn (conn )
252
262
return
253
263
}
254
- wsS3Client , err := newWebSocketS3Client (conn , session , wOptions .BucketName , "" )
264
+ wsS3Client , err := newWebSocketS3Client (conn , session , wOptions .BucketName , "" , clientIP )
255
265
if err != nil {
256
266
ErrorWithContext (ctx , err )
257
267
closeWsConn (conn )
@@ -265,7 +275,7 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
265
275
closeWsConn (conn )
266
276
return
267
277
}
268
- wsAdminClient , err := newWebSocketAdminClient (conn , session )
278
+ wsAdminClient , err := newWebSocketAdminClient (conn , session , clientIP )
269
279
if err != nil {
270
280
ErrorWithContext (ctx , err )
271
281
closeWsConn (conn )
@@ -279,7 +289,7 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
279
289
closeWsConn (conn )
280
290
return
281
291
}
282
- wsAdminClient , err := newWebSocketAdminClient (conn , session )
292
+ wsAdminClient , err := newWebSocketAdminClient (conn , session , clientIP )
283
293
if err != nil {
284
294
ErrorWithContext (ctx , err )
285
295
closeWsConn (conn )
@@ -288,7 +298,7 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
288
298
go wsAdminClient .profile (ctx , pOptions )
289
299
290
300
case strings .HasPrefix (wsPath , `/objectManager` ):
291
- wsMinioClient , err := newWebSocketMinioClient (conn , session )
301
+ wsMinioClient , err := newWebSocketMinioClient (conn , session , clientIP )
292
302
if err != nil {
293
303
ErrorWithContext (ctx , err )
294
304
closeWsConn (conn )
@@ -303,12 +313,11 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
303
313
}
304
314
305
315
// newWebSocketAdminClient returns a wsAdminClient authenticated as an admin user
306
- func newWebSocketAdminClient (conn * websocket.Conn , autClaims * models.Principal ) (* wsAdminClient , error ) {
316
+ func newWebSocketAdminClient (conn * websocket.Conn , autClaims * models.Principal , clientIP string ) (* wsAdminClient , error ) {
307
317
// create a websocket connection interface implementation
308
318
// defining the connection to be used
309
319
wsConnection := wsConn {conn : conn }
310
320
311
- clientIP := wsConnection .remoteAddress ()
312
321
// Only start Websocket Interaction after user has been
313
322
// authenticated with MinIO
314
323
mAdmin , err := newAdminFromClaims (autClaims , clientIP )
@@ -326,15 +335,9 @@ func newWebSocketAdminClient(conn *websocket.Conn, autClaims *models.Principal)
326
335
}
327
336
328
337
// newWebSocketS3Client returns a wsAdminClient authenticated as Console admin
329
- func newWebSocketS3Client (conn * websocket.Conn , claims * models.Principal , bucketName , prefix string ) (* wsS3Client , error ) {
338
+ func newWebSocketS3Client (conn * websocket.Conn , claims * models.Principal , bucketName , prefix , clientIP string ) (* wsS3Client , error ) {
330
339
// Only start Websocket Interaction after user has been
331
340
// authenticated with MinIO
332
- clientIP , _ , err := net .SplitHostPort (conn .RemoteAddr ().String ())
333
- if err != nil {
334
- // In case there's an error, return an empty string
335
- log .Printf ("Invalid ws.clientIP = %s\n " , err )
336
- }
337
-
338
341
s3Client , err := newS3BucketClient (claims , bucketName , prefix , clientIP )
339
342
if err != nil {
340
343
LogError ("error creating S3Client:" , err )
@@ -351,14 +354,7 @@ func newWebSocketS3Client(conn *websocket.Conn, claims *models.Principal, bucket
351
354
return wsS3Client , nil
352
355
}
353
356
354
- func newWebSocketMinioClient (conn * websocket.Conn , claims * models.Principal ) (* wsMinioClient , error ) {
355
- // Only start Websocket Interaction after user has been
356
- // authenticated with MinIO
357
- clientIP , _ , err := net .SplitHostPort (conn .RemoteAddr ().String ())
358
- if err != nil {
359
- // In case there's an error, return an empty string
360
- log .Printf ("Invalid ws.clientIP = %s\n " , err )
361
- }
357
+ func newWebSocketMinioClient (conn * websocket.Conn , claims * models.Principal , clientIP string ) (* wsMinioClient , error ) {
362
358
mClient , err := newMinioClient (claims , clientIP )
363
359
if err != nil {
364
360
LogError ("error creating MinioClient:" , err )
0 commit comments