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 f6c112e commit 34f4a9b
Show file tree
Hide file tree
Showing 12 changed files with 509 additions and 1 deletion.
38 changes: 38 additions & 0 deletions apis/projectcontour/v1/httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,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 @@ -537,10 +555,20 @@ type Route struct {
// +optional
PathRewritePolicy *PathRewritePolicy `json:"pathRewritePolicy,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. Note that
Expand Down Expand Up @@ -998,10 +1026,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
```
67 changes: 67 additions & 0 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7182,6 +7182,73 @@ spec:
- unit
type: object
type: object
requestHeadersPolicy:
description: The policy for managing request headers during proxying.
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.
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
67 changes: 67 additions & 0 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7395,6 +7395,73 @@ spec:
- unit
type: object
type: object
requestHeadersPolicy:
description: The policy for managing request headers during proxying.
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.
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
67 changes: 67 additions & 0 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7196,6 +7196,73 @@ spec:
- unit
type: object
type: object
requestHeadersPolicy:
description: The policy for managing request headers during proxying.
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.
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 34f4a9b

Please sign in to comment.