-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for host_rewrite_header (#9608)
* add it to the proto * add plugin * add changelog * Adding changelog file to new location * Deleting changelog file from old location * add validation * remove old entry * Adding changelog file to new location * Deleting changelog file from old location * dont remove exposed method * update changelog * update changelog * Update changelog/v1.18.0-beta1/add-host-rewrite-header.yaml Co-authored-by: Nathan Fudenberg <nathan.fudenberg@solo.io> * update changelog * update changelog * address comments --------- Co-authored-by: changelog-bot <changelog-bot> Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Nathan Fudenberg <nathan.fudenberg@solo.io>
- Loading branch information
1 parent
a6cd15b
commit e2ebdeb
Showing
16 changed files
with
224 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
changelog: | ||
- 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. | ||
- type: FIX | ||
issueLink: https://github.com/solo-io/gloo/issues/9622 | ||
resolvesIssue: true | ||
description: >- | ||
Previously, header names consisting of invalid characters such as '()[]:;,<=>' were accepted when passed via the healthCheck or headerManipulation `requestHeadersToAdd` parameter. This resulted in envoy throwing an `invalid header name` error. Now, header names are validated according to RFC 9110, which is the same validation used by envoy. If a header name consisting of invalid characters is passed via the aforementioned parameters, it is caught and rejected in edge and does not propagate to envoy. |
8 changes: 5 additions & 3 deletions
8
.../reference/api/github.com/solo-io/gloo/projects/gloo/api/v1/options.proto.sk.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
projects/gloo/pkg/plugins/utils/headers/headers_suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package headers_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestHeaders(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Headers Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package headers | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
var ( | ||
// Regex to check that header names consists of only valid ASCII characters | ||
// https://github.com/envoyproxy/envoy/blob/b0f4332867267913d9aa80c5c0befda14a00d826/source/common/http/character_set_validation.h#L24-L35 | ||
validHeaderNameRegex = regexp.MustCompile("^([a-zA-Z0-9!#$%&'*+.^_`|~-])+$") | ||
) | ||
|
||
// ValidateHeaderKey checks whether a header is valid based on the RFC and envoy's regex to accept a header key | ||
func ValidateHeaderKey(key string) error { | ||
if len(key) == 0 { | ||
return fmt.Errorf("empty HTTP header names are not allowed") | ||
} | ||
if !validHeaderNameRegex.MatchString(key) { | ||
return fmt.Errorf("'%s' is an invalid HTTP header key", key) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package headers_test | ||
|
||
import ( | ||
"fmt" | ||
"unicode" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/solo-io/gloo/projects/gloo/pkg/plugins/utils/headers" | ||
) | ||
|
||
var _ = Describe("Validate header keys", func() { | ||
|
||
generateInvalidEntries := func(character rune) []TableEntry { | ||
var entries []TableEntry | ||
entries = append(entries, Entry(fmt.Sprintf("just '%s'", string(character)), fmt.Sprintf("%s", string(character)), true)) | ||
entries = append(entries, Entry(fmt.Sprintf("contains leading '%s'", string(character)), fmt.Sprintf("%sreserved", string(character)), true)) | ||
entries = append(entries, Entry(fmt.Sprintf("contains trailing '%s'", string(character)), fmt.Sprintf("reserved%s", string(character)), true)) | ||
entries = append(entries, Entry(fmt.Sprintf("contains '%s'", string(character)), fmt.Sprintf("rese%srved", string(character)), true)) | ||
return entries | ||
} | ||
|
||
DescribeTable("Validates header keys", func(key string, errored bool) { | ||
Expect(headers.ValidateHeaderKey(key) != nil).To(Equal(errored)) | ||
}, | ||
generateInvalidEntries(':'), | ||
generateInvalidEntries('"'), | ||
generateInvalidEntries(' '), | ||
generateInvalidEntries('('), | ||
generateInvalidEntries(')'), | ||
generateInvalidEntries(','), | ||
generateInvalidEntries('/'), | ||
generateInvalidEntries(':'), | ||
generateInvalidEntries(';'), | ||
generateInvalidEntries('<'), | ||
generateInvalidEntries('='), | ||
generateInvalidEntries('>'), | ||
generateInvalidEntries('?'), | ||
generateInvalidEntries('@'), | ||
generateInvalidEntries('['), | ||
generateInvalidEntries('\\'), | ||
generateInvalidEntries(']'), | ||
generateInvalidEntries('{'), | ||
generateInvalidEntries('}'), | ||
generateInvalidEntries('>'), | ||
generateInvalidEntries(unicode.MaxASCII), | ||
Entry("valid header", "valid-header", false), | ||
) | ||
}) |