mirror of https://github.com/status-im/consul.git
Auto Rewrite Host Headers for Terminating Gateways
Tries to partially address https://github.com/hashicorp/consul/issues/8707
This commit is contained in:
parent
1413e9ddca
commit
750e2921b0
|
@ -113,7 +113,7 @@ func (s *Server) routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap
|
|||
if resolver.LoadBalancer != nil {
|
||||
lb = resolver.LoadBalancer
|
||||
}
|
||||
route, err := makeNamedDefaultRouteWithLB(clusterName, lb)
|
||||
route, err := makeNamedDefaultRouteWithLB(clusterName, lb, true)
|
||||
if err != nil {
|
||||
logger.Error("failed to make route", "cluster", clusterName, "error", err)
|
||||
continue
|
||||
|
@ -123,7 +123,7 @@ func (s *Server) routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap
|
|||
// If there is a service-resolver for this service then also setup routes for each subset
|
||||
for name := range resolver.Subsets {
|
||||
clusterName = connect.ServiceSNI(svc.Name, name, svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain)
|
||||
route, err := makeNamedDefaultRouteWithLB(clusterName, lb)
|
||||
route, err := makeNamedDefaultRouteWithLB(clusterName, lb, true)
|
||||
if err != nil {
|
||||
logger.Error("failed to make route", "cluster", clusterName, "error", err)
|
||||
continue
|
||||
|
@ -135,13 +135,20 @@ func (s *Server) routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap
|
|||
return resources, nil
|
||||
}
|
||||
|
||||
func makeNamedDefaultRouteWithLB(clusterName string, lb *structs.LoadBalancer) (*envoy.RouteConfiguration, error) {
|
||||
func makeNamedDefaultRouteWithLB(clusterName string, lb *structs.LoadBalancer, autoHostRewrite bool) (*envoy.RouteConfiguration, error) {
|
||||
action := makeRouteActionFromName(clusterName)
|
||||
|
||||
if err := injectLBToRouteAction(lb, action.Route); err != nil {
|
||||
return nil, fmt.Errorf("failed to apply load balancer configuration to route action: %v", err)
|
||||
}
|
||||
|
||||
// Configure Envoy to rewrite Host header
|
||||
if autoHostRewrite {
|
||||
action.Route.HostRewriteSpecifier = &envoyroute.RouteAction_AutoHostRewrite{
|
||||
AutoHostRewrite: makeBoolValue(true),
|
||||
}
|
||||
}
|
||||
|
||||
return &envoy.RouteConfiguration{
|
||||
Name: clusterName,
|
||||
VirtualHosts: []*envoyroute.VirtualHost{
|
||||
|
|
Loading…
Reference in New Issue