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 Jan 17, 2024
1 parent 61b6fae commit da12bda
Show file tree
Hide file tree
Showing 15 changed files with 921 additions and 29 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
```
115 changes: 111 additions & 4 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6363,6 +6363,11 @@ spec:
Provided header must come from trusted source.
**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.
properties:
remove:
description: Remove specifies a list of HTTP header names
Expand Down Expand Up @@ -6452,6 +6457,11 @@ spec:
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
Expand Down Expand Up @@ -6653,8 +6663,13 @@ spec:
- tls
type: string
requestHeadersPolicy:
description: The policy for managing request headers during
proxying.
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
Expand Down Expand Up @@ -6689,6 +6704,11 @@ spec:
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 @@ -7061,8 +7081,13 @@ spec:
- tls
type: string
requestHeadersPolicy:
description: The policy for managing request headers during
proxying.
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
Expand Down Expand Up @@ -7097,6 +7122,11 @@ spec:
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 @@ -7795,6 +7825,83 @@ 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
Expand Down

0 comments on commit da12bda

Please sign in to comment.