Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for host_rewrite_header #9608

Merged
merged 21 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/v1.18.0-beta1/add-host-rewrite-header.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
changelog:
nfuden marked this conversation as resolved.
Show resolved Hide resolved
- type: NEW_FEATURE
issueLink: https://github.com/solo-io/gloo/issues/9579
resolvesIssue: false
description: Adds the `host_rewrite_header` to the route options to allow envoy to swapped the host header with the content of given downstream or custom header. Pay attention to the potential security implications of using this option. Provided header must come from trusted source.
davidjumani marked this conversation as resolved.
Show resolved Hide resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions install/helm/gloo/crds/gateway.solo.io_v1_RouteOption.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ spec:
type: object
hostRewrite:
type: string
hostRewriteHeader:
nullable: true
type: string
hostRewritePathRegex:
properties:
pattern:
Expand Down
3 changes: 3 additions & 0 deletions install/helm/gloo/crds/gateway.solo.io_v1_RouteTable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ spec:
type: object
hostRewrite:
type: string
hostRewriteHeader:
nullable: true
type: string
hostRewritePathRegex:
properties:
pattern:
Expand Down
3 changes: 3 additions & 0 deletions install/helm/gloo/crds/gateway.solo.io_v1_VirtualService.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3331,6 +3331,9 @@ spec:
type: object
hostRewrite:
type: string
hostRewriteHeader:
nullable: true
type: string
hostRewritePathRegex:
properties:
pattern:
Expand Down
12 changes: 11 additions & 1 deletion pkg/utils/api_conversion/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
envoy_type_v3 "github.com/envoyproxy/go-control-plane/envoy/type/v3"
envoytype_gloo "github.com/solo-io/gloo/projects/gloo/pkg/api/external/envoy/type"
v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
"github.com/solo-io/gloo/projects/gloo/pkg/plugins/utils/headers"
envoycore_sk "github.com/solo-io/solo-kit/pkg/api/external/envoy/api/v2/core"
"github.com/solo-io/solo-kit/pkg/errors"
)
Expand Down Expand Up @@ -71,6 +72,15 @@ func ToEnvoyHeaderValueOptionList(option []*envoycore_sk.HeaderValueOption, secr
return result, nil
}

// validateCustomHeaders checks whether the custom header is allowed to be modified as per https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#custom-request-response-headers
// and validates the whether the header will be accepted by envoy
func validateCustomHeaders(header envoycore_sk.HeaderValue) error {
if err := CheckForbiddenCustomHeaders(header); err != nil {
return err
}
return headers.ValidateHeaderKey(header.GetKey())
}

// CheckForbiddenCustomHeaders checks whether the custom header is allowed to be modified as per https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#custom-request-response-headers
func CheckForbiddenCustomHeaders(header envoycore_sk.HeaderValue) error {
davidjumani marked this conversation as resolved.
Show resolved Hide resolved
key := header.GetKey()
Expand All @@ -90,7 +100,7 @@ func ToEnvoyHeaderValueOptions(option *envoycore_sk.HeaderValueOption, secrets *

switch typedOption := option.GetHeaderOption().(type) {
case *envoycore_sk.HeaderValueOption_Header:
if err := CheckForbiddenCustomHeaders(*typedOption.Header); err != nil {
if err := validateCustomHeaders(*typedOption.Header); err != nil {
return nil, err
}
return []*envoy_config_core_v3.HeaderValueOption{
Expand Down
9 changes: 7 additions & 2 deletions projects/gloo/api/v1/options.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ message ListenerOptions {
ConnectionBalanceConfig connection_balance_config = 6;

// If enabled this sets up an early access logging service for the listener.
// Added initially to support listener level logging for HTTP listeners.
// Added initially to support listener level logging for HTTP listeners.
// For more info see https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/listener/v3/listener.proto#envoy-v3-api-field-config-listener-v3-listener-access-log
als.options.gloo.solo.io.AccessLoggingService listener_access_logging_service = 7;

}

// Configuration for listener connection balancing.
Expand Down Expand Up @@ -421,6 +421,11 @@ message RouteOptions {
// Indicates that during forwarding, the host header will be swapped with the result of the regex
// substitution executed on path value with query and fragment removed.
.solo.io.envoy.type.matcher.v3.RegexMatchAndSubstitute host_rewrite_path_regex = 101;

// Indicates that during forwarding, the host header will be swapped with the content of given downstream or custom header.
// If header value is empty, host header is left intact.
// Using this option will append the x-forwarded-host header if append_x_forwarded_host is set.
google.protobuf.StringValue host_rewrite_header = 147;
};
// If true and there is a host rewrite, appends the x-forwarded-host header to requests.
google.protobuf.BoolValue append_x_forwarded_host = 146;
Expand Down
12 changes: 12 additions & 0 deletions projects/gloo/pkg/api/v1/options.pb.clone.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions projects/gloo/pkg/api/v1/options.pb.equal.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading