@@ -391,16 +391,97 @@ func (c Config) RenderDefaultFilterChain() (*pbEnvoyListenerV3.FilterChain, erro
391
391
}
392
392
393
393
func (c Config ) RenderSecondaryFilterChains () ([]* pbEnvoyListenerV3.FilterChain , error ) {
394
- if len (c .SNI ) == 0 {
394
+ var r []* pbEnvoyListenerV3.FilterChain
395
+
396
+ if chain , err := c .HttpToHttpsChain (); err != nil {
397
+ return nil , err
398
+ } else if chain != nil {
399
+ r = append (r , chain )
400
+ }
401
+
402
+ if len (c .SNI ) > 0 {
403
+ filters , err := c .RenderFilters ()
404
+ if err != nil {
405
+ return nil , err
406
+ }
407
+
408
+ chain , err := c .SNI .RenderFilterChain (filters )
409
+ if err != nil {
410
+ return nil , err
411
+ }
412
+
413
+ r = append (r , chain ... )
414
+ }
415
+
416
+ return r , nil
417
+ }
418
+
419
+ func (c Config ) HttpToHttpsChain () (* pbEnvoyListenerV3.FilterChain , error ) {
420
+ if c .DefaultTLS == nil {
395
421
return nil , nil
396
422
}
397
423
398
- filters , err := c . RenderFilters ( )
424
+ httpFilterConfigType , err := anypb . New ( & routerAPI. Router {} )
399
425
if err != nil {
400
- return nil , err
426
+ return nil , errors . Wrapf ( err , "Unable to create router filter configuration for HTTP to HTTPS redirect" )
401
427
}
402
428
403
- return c .SNI .RenderFilterChain (filters )
429
+ filterConfigType , err := anypb .New (& httpConnectionManagerAPI.HttpConnectionManager {
430
+ StatPrefix : "ingress_http" ,
431
+ CodecType : httpConnectionManagerAPI .HttpConnectionManager_AUTO ,
432
+ RouteSpecifier : & httpConnectionManagerAPI.HttpConnectionManager_RouteConfig {
433
+ RouteConfig : & pbEnvoyRouteV3.RouteConfiguration {
434
+ Name : "local_http" ,
435
+ VirtualHosts : []* pbEnvoyRouteV3.VirtualHost {
436
+ {
437
+ Name : "local_http" ,
438
+ Domains : []string {"*" },
439
+ Routes : []* pbEnvoyRouteV3.Route {
440
+ {
441
+ Match : & pbEnvoyRouteV3.RouteMatch {
442
+ PathSpecifier : & pbEnvoyRouteV3.RouteMatch_Prefix {
443
+ Prefix : "/" ,
444
+ },
445
+ },
446
+ Action : & pbEnvoyRouteV3.Route_Redirect {
447
+ Redirect : & pbEnvoyRouteV3.RedirectAction {
448
+ SchemeRewriteSpecifier : & pbEnvoyRouteV3.RedirectAction_HttpsRedirect {
449
+ HttpsRedirect : true ,
450
+ },
451
+ },
452
+ },
453
+ },
454
+ },
455
+ },
456
+ },
457
+ },
458
+ },
459
+ HttpFilters : []* httpConnectionManagerAPI.HttpFilter {
460
+ {
461
+ Name : "envoy.filters.http.router" ,
462
+ ConfigType : & httpConnectionManagerAPI.HttpFilter_TypedConfig {
463
+ TypedConfig : httpFilterConfigType ,
464
+ },
465
+ },
466
+ },
467
+ })
468
+ if err != nil {
469
+ return nil , errors .Wrapf (err , "Unable to create HTTP connection manager configuration for HTTP to HTTPS redirect" )
470
+ }
471
+
472
+ return & pbEnvoyListenerV3.FilterChain {
473
+ FilterChainMatch : & pbEnvoyListenerV3.FilterChainMatch {
474
+ TransportProtocol : "raw_buffer" ,
475
+ },
476
+ Filters : []* pbEnvoyListenerV3.Filter {
477
+ {
478
+ Name : "envoy.filters.network.http_connection_manager" ,
479
+ ConfigType : & pbEnvoyListenerV3.Filter_TypedConfig {
480
+ TypedConfig : filterConfigType ,
481
+ },
482
+ },
483
+ },
484
+ }, nil
404
485
}
405
486
406
487
func (c Config ) RenderListener () (* pbEnvoyListenerV3.Listener , error ) {
0 commit comments