Skip to content

Commit

Permalink
envoyconfig: add authority header to outbound gRPC requests (#3545)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdoxsey committed Aug 24, 2022
1 parent f07c912 commit ce818b3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/envoyconfig/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
envoy_config_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
envoy_http_connection_manager "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/wrapperspb"

"github.com/pomerium/pomerium/config"
)
Expand Down Expand Up @@ -122,6 +123,10 @@ func (b *Builder) buildOutboundRoutes() []*envoy_config_route_v3.Route {
ClusterSpecifier: &envoy_config_route_v3.RouteAction_Cluster{
Cluster: def.Cluster,
},
// rewrite the host header
HostRewriteSpecifier: &envoy_config_route_v3.RouteAction_AutoHostRewrite{
AutoHostRewrite: wrapperspb.Bool(true),
},
// disable the timeout to support grpc streaming
Timeout: durationpb.New(0),
IdleTimeout: durationpb.New(0),
Expand Down
79 changes: 79 additions & 0 deletions config/envoyconfig/outbound_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package envoyconfig

import (
"testing"

"github.com/pomerium/pomerium/internal/testutil"
)

func Test_buildOutboundRoutes(t *testing.T) {
b := New("local-grpc", "local-http", "local-metrics", nil, nil)
routes := b.buildOutboundRoutes()
testutil.AssertProtoJSONEqual(t, `[
{
"match": {
"grpc": {},
"prefix": "/envoy.service.auth.v3.Authorization/"
},
"name": "pomerium-authorize",
"route": {
"autoHostRewrite": true,
"cluster": "pomerium-authorize",
"idleTimeout": "0s",
"timeout": "0s"
}
},
{
"match": {
"grpc": {},
"prefix": "/databroker.DataBrokerService/"
},
"name": "pomerium-databroker",
"route": {
"autoHostRewrite": true,
"cluster": "pomerium-databroker",
"idleTimeout": "0s",
"timeout": "0s"
}
},
{
"match": {
"grpc": {},
"prefix": "/directory.DirectoryService/"
},
"name": "pomerium-databroker",
"route": {
"autoHostRewrite": true,
"cluster": "pomerium-databroker",
"idleTimeout": "0s",
"timeout": "0s"
}
},
{
"match": {
"grpc": {},
"prefix": "/registry.Registry/"
},
"name": "pomerium-databroker",
"route": {
"autoHostRewrite": true,
"cluster": "pomerium-databroker",
"idleTimeout": "0s",
"timeout": "0s"
}
},
{
"match": {
"grpc": {},
"prefix": "/"
},
"name": "pomerium-control-plane-grpc",
"route": {
"autoHostRewrite": true,
"cluster": "pomerium-control-plane-grpc",
"idleTimeout": "0s",
"timeout": "0s"
}
}
]`, routes)
}

0 comments on commit ce818b3

Please sign in to comment.