@@ -424,38 +424,48 @@ func (s *Server) newGateway(opts *Options) error {
424
424
func (g * srvGateway ) updateRemotesTLSConfig (opts * Options ) {
425
425
g .Lock ()
426
426
defer g .Unlock ()
427
-
428
- for _ , ro := range opts .Gateway .Gateways {
429
- if ro .Name == g .name {
427
+ // Instead of going over opts.Gateway.Gateways, which would include only
428
+ // explicit remotes, we are going to go through g.remotes.
429
+ for name , cfg := range g .remotes {
430
+ if name == g .name {
430
431
continue
431
432
}
432
- if cfg , ok := g .remotes [ro .Name ]; ok {
433
- cfg .Lock ()
434
- // If TLS config is in remote, use that one, otherwise,
435
- // use the TLS config from the main block.
436
- if ro .TLSConfig != nil {
437
- cfg .TLSConfig = ro .TLSConfig .Clone ()
438
- } else if opts .Gateway .TLSConfig != nil {
439
- cfg .TLSConfig = opts .Gateway .TLSConfig .Clone ()
433
+ var ro * RemoteGatewayOpts
434
+ // We now need to go back and find the RemoteGatewayOpts but only if
435
+ // this remote is explicit (otherwise it won't be found).
436
+ if ! cfg .isImplicit () {
437
+ for _ , r := range opts .Gateway .Gateways {
438
+ if r .Name == name {
439
+ ro = r
440
+ break
441
+ }
440
442
}
441
-
442
- // Ensure that OCSP callbacks are always setup after a reload if needed.
443
- mustStaple := opts .OCSPConfig != nil && opts .OCSPConfig .Mode == OCSPModeAlways
444
- if mustStaple && opts .Gateway .TLSConfig != nil {
445
- clientCB := opts .Gateway .TLSConfig .GetClientCertificate
446
- verifyCB := opts .Gateway .TLSConfig .VerifyConnection
447
- if mustStaple && cfg .TLSConfig != nil {
448
- if clientCB != nil && cfg .TLSConfig .GetClientCertificate == nil {
449
- cfg .TLSConfig .GetClientCertificate = clientCB
450
- }
451
- if verifyCB != nil && cfg .TLSConfig .VerifyConnection == nil {
452
- cfg .TLSConfig .VerifyConnection = verifyCB
453
- }
443
+ }
444
+ cfg .Lock ()
445
+ // If we have an `ro` (that means an explicitly defined remote gateway)
446
+ // and it has an explicit TLS config, use that one, otherwise (no explicit
447
+ // TLS config in the remote, or implicit remote), use the TLS config from
448
+ // the main block.
449
+ if ro != nil && ro .TLSConfig != nil {
450
+ cfg .TLSConfig = ro .TLSConfig .Clone ()
451
+ } else if opts .Gateway .TLSConfig != nil {
452
+ cfg .TLSConfig = opts .Gateway .TLSConfig .Clone ()
453
+ }
454
+ // Ensure that OCSP callbacks are always setup after a reload if needed.
455
+ mustStaple := opts .OCSPConfig != nil && opts .OCSPConfig .Mode == OCSPModeAlways
456
+ if mustStaple && opts .Gateway .TLSConfig != nil {
457
+ clientCB := opts .Gateway .TLSConfig .GetClientCertificate
458
+ verifyCB := opts .Gateway .TLSConfig .VerifyConnection
459
+ if mustStaple && cfg .TLSConfig != nil {
460
+ if clientCB != nil && cfg .TLSConfig .GetClientCertificate == nil {
461
+ cfg .TLSConfig .GetClientCertificate = clientCB
462
+ }
463
+ if verifyCB != nil && cfg .TLSConfig .VerifyConnection == nil {
464
+ cfg .TLSConfig .VerifyConnection = verifyCB
454
465
}
455
466
}
456
-
457
- cfg .Unlock ()
458
467
}
468
+ cfg .Unlock ()
459
469
}
460
470
}
461
471
0 commit comments