I am migrating from using an ingress to using the Gateway API. Part of this involves configuring our Content Security Policy headers in the HTTPRoute. One of the required headers is 'Report-To'. The value for this is a JSON string (See definition at https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/report-to )
It appears that this JSON content is not escaped properly when applying the configuration resulting in an error.
Using an example HTTPRoute:
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: testroute
namespace: default
spec:
hostnames:
- example.com
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: test-gateway
namespace: gateway
rules:
- backendRefs:
- group: ""
kind: Service
name: test-service
namespace: default
port: 8080
weight: 1
filters:
- responseHeaderModifier:
set:
- name: test-header
value: '{"foo":"bar"}'
type: ResponseHeaderModifier
matches:
- path:
type: PathPrefix
value: /testroute
I get the following error when inspecting the route with kubetctl get httproute testroute -o yaml:
Update: Invalid
value for field ''resource.pathMatchers[0].routeRules[0].headerAction.responseHeadersToAdd[0]'':
''{ "headerName": "test-header", "headerValue": "{\"foo\":\"bar\"}", "replace":
true}''. Invalid variable in header field value: "foo":"bar"'
Has anyone else encountered this and have they got a workaround?
Solved! Go to Solution.
Solved it by RTFM - at the bottom of
it says "In header values, leading whitespace and trailing whitespace are insignificant, and are not passed to the backend. To allow for curly braces in header values, the load balancer interprets two opening curly braces ({{) as a single opening brace ({), and two closing curly braces (}}) as a single closing brace (})."
Solved it by RTFM - at the bottom of
it says "In header values, leading whitespace and trailing whitespace are insignificant, and are not passed to the backend. To allow for curly braces in header values, the load balancer interprets two opening curly braces ({{) as a single opening brace ({), and two closing curly braces (}}) as a single closing brace (})."