Skip to content

Commit

Permalink
internal/contour: Add Support for custom headers on HTTPProxy level
Browse files Browse the repository at this point in the history
Introduces support for request and repsonse headers on http proxy level

Fixes: projectcontour#5576
Signed-off-by: Devesh Kumar <vrshu112@gmail.com>
  • Loading branch information
deveshk0 committed Dec 27, 2023
1 parent 7dd40af commit 27e4ac7
Show file tree
Hide file tree
Showing 13 changed files with 704 additions and 31 deletions.
38 changes: 38 additions & 0 deletions apis/projectcontour/v1/httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,24 @@ type VirtualHost struct {
// +optional
JWTProviders []JWTProvider `json:"jwtProviders,omitempty"`

// The policy for managing request headers during proxying.
// Headers are appended to requests in the following order,
// weighted cluster level headers,
// route level headers,
// virtual host level headers,
// global level headers.
// +optional
RequestHeadersPolicy *HeadersPolicy `json:"requestHeadersPolicy,omitempty"`
// The policy for managing response headers during proxying.
// Rewriting the 'Host' header is not supported.
// Headers are appended to responses in the following order,
// weighted cluster level headers,
// route level headers,
// virtual host level headers,
// global level headers.
// +optional
ResponseHeadersPolicy *HeadersPolicy `json:"responseHeadersPolicy,omitempty"`

// IPAllowFilterPolicy is a list of ipv4/6 filter rules for which matching
// requests should be allowed. All other requests will be denied.
// Only one of IPAllowFilterPolicy and IPDenyFilterPolicy can be defined.
Expand Down Expand Up @@ -563,10 +581,20 @@ type Route struct {
// **NOTE: The header rewrite is only done while forwarding and has no bearing
// on the routing decision.
//
// Headers are appended to requests in the following order,
// weighted cluster level headers,
// route level headers,
// virtual host level headers,
// global level headers.
// +optional
RequestHeadersPolicy *HeadersPolicy `json:"requestHeadersPolicy,omitempty"`
// The policy for managing response headers during proxying.
// Rewriting the 'Host' header is not supported.
// Headers are appended to responses in the following order,
// weighted cluster level headers,
// route level headers,
// virtual host level headers,
// global level headers.
// +optional
ResponseHeadersPolicy *HeadersPolicy `json:"responseHeadersPolicy,omitempty"`
// The policies for rewriting Set-Cookie header attributes. Note that
Expand Down Expand Up @@ -1024,10 +1052,20 @@ type Service struct {
// values
Mirror bool `json:"mirror,omitempty"`
// The policy for managing request headers during proxying.
// Headers are appended to requests in the following order,
// weighted cluster level headers,
// route level headers,
// virtual host level headers,
// global level headers.
// +optional
RequestHeadersPolicy *HeadersPolicy `json:"requestHeadersPolicy,omitempty"`
// The policy for managing response headers during proxying.
// Rewriting the 'Host' header is not supported.
// Headers are appended to responses in the following order,
// weighted cluster level headers,
// route level headers,
// virtual host level headers,
// global level headers.
// +optional
ResponseHeadersPolicy *HeadersPolicy `json:"responseHeadersPolicy,omitempty"`
// The policies for rewriting Set-Cookie header attributes.
Expand Down
10 changes: 10 additions & 0 deletions apis/projectcontour/v1/zz_generated.deepcopy.go

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

27 changes: 27 additions & 0 deletions changelogs/unreleased/5586-deveshk0-minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## HTTPProxy: Allow custom host header on HttpProxy level.

This Change allows you set custom host headers on httpProxy level, Please note headers are appended to requests/responses in the following order: weighted cluster level headers, route level headers, virtual host level headers and finally global level headers.

#### Example
```yaml
apiVersion: projectcontour.io/v1
kind: HTTPProxy
metadata:
name: custom-host-header
spec:
fqdn: local.projectcontour.io
requestHeadersPolicy:
set:
- name: x-header
value: somevalue
responseHeadersPolicy:
set:
- name: x-powered-by
value: contour
routes:
- conditions:
- prefix: /
services:
- name: s1
port: 80
```
98 changes: 93 additions & 5 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6211,7 +6211,9 @@ spec:
to the potential security implications of using this option.
Provided header must come from trusted source. \n **NOTE:
The header rewrite is only done while forwarding and has no
bearing on the routing decision."
bearing on the routing decision. Headers are appended to requests in the following
order, weighted cluster level headers, route level headers,
virtual host level headers, global level headers."
properties:
remove:
description: Remove specifies a list of HTTP header names
Expand Down Expand Up @@ -6295,7 +6297,10 @@ spec:
type: object
responseHeadersPolicy:
description: The policy for managing response headers during
proxying. Rewriting the 'Host' header is not supported.
proxying. Rewriting the 'Host' header is not supported. Headers
are appended to responses in the following order, weighted
cluster level headers, route level headers, virtual host level
headers, global level headers.
properties:
remove:
description: Remove specifies a list of HTTP header names
Expand Down Expand Up @@ -6488,7 +6493,9 @@ spec:
type: string
requestHeadersPolicy:
description: The policy for managing request headers during
proxying.
proxying. Headers are appended to requests in the following
order, weighted cluster level headers, route level headers,
virtual host level headers, global level headers.
properties:
remove:
description: Remove specifies a list of HTTP header
Expand Down Expand Up @@ -6523,7 +6530,10 @@ spec:
responseHeadersPolicy:
description: The policy for managing response headers
during proxying. Rewriting the 'Host' header is not
supported.
supported. Headers are appended to responses in the
following order, weighted cluster level headers, route
level headers, virtual host level headers, global level
headers.
properties:
remove:
description: Remove specifies a list of HTTP header
Expand Down Expand Up @@ -6885,7 +6895,9 @@ spec:
type: string
requestHeadersPolicy:
description: The policy for managing request headers during
proxying.
proxying. Headers are appended to requests in the following
order, weighted cluster level headers, route level headers,
virtual host level headers, global level headers.
properties:
remove:
description: Remove specifies a list of HTTP header
Expand Down Expand Up @@ -6920,6 +6932,9 @@ spec:
responseHeadersPolicy:
description: The policy for managing response headers during
proxying. Rewriting the 'Host' header is not supported.
Headers are appended to responses in the following order,
weighted cluster level headers, route level headers, virtual
host level headers, global level headers.
properties:
remove:
description: Remove specifies a list of HTTP header
Expand Down Expand Up @@ -7587,6 +7602,79 @@ spec:
- unit
type: object
type: object
requestHeadersPolicy:
description: The policy for managing request headers during proxying.
Headers are appended to requests in the following order, weighted
cluster level headers, route level headers, virtual host level
headers, global level headers.
properties:
remove:
description: Remove specifies a list of HTTP header names
to remove.
items:
type: string
type: array
set:
description: Set specifies a list of HTTP header values that
will be set in the HTTP header. If the header does not exist
it will be added, otherwise it will be overwritten with
the new value.
items:
description: HeaderValue represents a header name/value
pair
properties:
name:
description: Name represents a key of a header
minLength: 1
type: string
value:
description: Value represents the value of a header
specified by a key
minLength: 1
type: string
required:
- name
- value
type: object
type: array
type: object
responseHeadersPolicy:
description: The policy for managing response headers during proxying.
Rewriting the 'Host' header is not supported. Headers are appended
to responses in the following order, weighted cluster level
headers, route level headers, virtual host level headers, global
level headers.
properties:
remove:
description: Remove specifies a list of HTTP header names
to remove.
items:
type: string
type: array
set:
description: Set specifies a list of HTTP header values that
will be set in the HTTP header. If the header does not exist
it will be added, otherwise it will be overwritten with
the new value.
items:
description: HeaderValue represents a header name/value
pair
properties:
name:
description: Name represents a key of a header
minLength: 1
type: string
value:
description: Value represents the value of a header
specified by a key
minLength: 1
type: string
required:
- name
- value
type: object
type: array
type: object
tls:
description: If present the fields describes TLS properties of
the virtual host. The SNI names that will be matched on are
Expand Down

0 comments on commit 27e4ac7

Please sign in to comment.