Basic Concepts
When a request is received, header modification allows adjusting request headers before forwarding to the backend.
Similarly, when a response is received, it allows adjusting response headers before they are returned to the client.
use annotations
Annotation values are JSON strings containing the config.
type RewriteRequestConfig struct {
Headers map[string]string `json:"headers,omitempty"` // set header
HeadersVar map[string]string `json:"headers_var,omitempty"` // set header, which values are variable name
HeadersRemove []string `json:"headers_remove,omitempty"` // remove header
HeadersAdd map[string][]string `json:"headers_add,omitempty"` // add header, which values could be multiple
HeadersAddVar map[string][]string `json:"headers_add_var,omitempty"` // add header, which values could be multiple and which values are variable name
}
type RewriteResponseConfig struct {
Headers map[string]string `json:"headers,omitempty"` // set header
HeadersRemove []string `json:"headers_remove,omitempty"` // remove header
HeadersAdd map[string][]string `json:"headers_add,omitempty"` // add header, which values could be multiple
}
Note: in *_var maps the key is the header name and the value is the ALB context variable name.
For example, add the following annotation to an Ingress:
alb.ingress.cpaas.io/rewrite-request: '{
"headers_var": {
"x-my-host": "http_host"
}
}'
will add key x-my-host and value of request host header to request header.
you can refer to the nginx variable for the variable names.
ALB provides additional variables:
examples
To add an Authorization header from a cookie, you can use:
alb.ingress.cpaas.io/rewrite-request: '{"headers_var":{"Authorization":"cookie_auth_token"}}'
To set HSTS, you can use:
alb.rule.cpaas.io/rewrite-response: |
{ "headers": { "Strict-Transport-Security": "max-age=63072000; includeSubDomains; preload"} }
Trademark Notice
NGINX® is a registered trademark of F5, Inc. in the U.S. and in other countries.
Alauda is an independent vendor. This product is not affiliated with, endorsed by, or sponsored by F5, Inc. All trademarks are the property of their respective owners and are used here for identification purposes only.