Skip to content

Commit 2b57397

Browse files
committed
sync with upstream & little refactor
Signed-off-by: Gang Liu <[email protected]>
2 parents fef7a59 + b461e76 commit 2b57397

File tree

13 files changed

+268
-350
lines changed

13 files changed

+268
-350
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Gateway API: for routes, replace use of custom `NotImplemented` condition with the upstream `Accepted: false` condition with reason `UnsupportedValue` to match the spec.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`%REQ()` operator in request/response header policies now properly supports HTTP/2 pseudo-headers, header fallbacks, and truncating header values.

cmd/contour/serve.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ func (s *Server) doServe() error {
474474
"httpproxies": &contour_api_v1.HTTPProxy{},
475475
"tlscertificatedelegations": &contour_api_v1.TLSCertificateDelegation{},
476476
"extensionservices": &contour_api_v1alpha1.ExtensionService{},
477-
"contourconfigurations": &contour_api_v1alpha1.ContourConfiguration{},
478477
"services": &corev1.Service{},
479478
"ingresses": &networking_v1.Ingress{},
480479
} {

internal/dag/cache.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ func (kc *KubernetesCache) Insert(obj interface{}) bool {
202202
case *contour_api_v1alpha1.ExtensionService:
203203
kc.extensions[k8s.NamespacedNameOf(obj)] = obj
204204
return true
205-
case *contour_api_v1alpha1.ContourConfiguration:
206-
return false
207205
default:
208206
// not an interesting object
209207
kc.WithField("object", obj).Error("insert unknown object")
@@ -330,8 +328,6 @@ func (kc *KubernetesCache) remove(obj interface{}) bool {
330328
_, ok := kc.extensions[m]
331329
delete(kc.extensions, m)
332330
return ok
333-
case *contour_api_v1alpha1.ContourConfiguration:
334-
return false
335331
default:
336332
// not interesting
337333
kc.WithField("object", obj).Error("remove unknown object")

internal/dag/gatewayapi_processor.go

Lines changed: 127 additions & 137 deletions
Large diffs are not rendered by default.

internal/dag/policy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func escapeHeaderValue(value string, dynamicHeaders map[string]string) string {
318318
escapedValue = strings.ReplaceAll(escapedValue, "%%"+envoyVar+"%%", "%"+envoyVar+"%")
319319
}
320320
// REQ(header-name)
321-
var validReqEnvoyVar = regexp.MustCompile(`%(%REQ\([\w-]+\)%)%`)
321+
var validReqEnvoyVar = regexp.MustCompile(`%(%REQ\(:?[\w-]+(\?:?[\w-]+)?\)(:\d+)?%)%`)
322322
escapedValue = validReqEnvoyVar.ReplaceAllString(escapedValue, "$1")
323323
return escapedValue
324324
}

internal/dag/policy_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,90 @@ func TestHeadersPolicy(t *testing.T) {
414414
},
415415
},
416416
},
417+
"valid Envoy REQ header unescaped truncated": {
418+
hp: &contour_api_v1.HeadersPolicy{
419+
Set: []contour_api_v1.HeaderValue{{
420+
Name: "X-Request-Host",
421+
Value: "%REQ(Host):9%",
422+
}},
423+
},
424+
dhp: HeadersPolicy{},
425+
want: HeadersPolicy{
426+
Set: map[string]string{
427+
"X-Request-Host": "%REQ(Host):9%",
428+
},
429+
},
430+
},
431+
"valid Envoy REQ http/2 pseudo-header unescaped": {
432+
hp: &contour_api_v1.HeadersPolicy{
433+
Set: []contour_api_v1.HeaderValue{{
434+
Name: "X-Request-Path",
435+
Value: "%REQ(:PATH)%",
436+
}},
437+
},
438+
dhp: HeadersPolicy{},
439+
want: HeadersPolicy{
440+
Set: map[string]string{
441+
"X-Request-Path": "%REQ(:PATH)%",
442+
},
443+
},
444+
},
445+
"valid Envoy REQ header if not present": {
446+
hp: &contour_api_v1.HeadersPolicy{
447+
Set: []contour_api_v1.HeaderValue{{
448+
Name: "X-Request-Foo-Fallback",
449+
Value: "%REQ(X-Foo?X-Bar)%",
450+
}},
451+
},
452+
dhp: HeadersPolicy{},
453+
want: HeadersPolicy{
454+
Set: map[string]string{
455+
"X-Request-Foo-Fallback": "%REQ(X-Foo?X-Bar)%",
456+
},
457+
},
458+
},
459+
"valid Envoy REQ header if not present truncated": {
460+
hp: &contour_api_v1.HeadersPolicy{
461+
Set: []contour_api_v1.HeaderValue{{
462+
Name: "X-Request-Foo-Fallback",
463+
Value: "%REQ(X-Foo?X-Bar):10%",
464+
}},
465+
},
466+
dhp: HeadersPolicy{},
467+
want: HeadersPolicy{
468+
Set: map[string]string{
469+
"X-Request-Foo-Fallback": "%REQ(X-Foo?X-Bar):10%",
470+
},
471+
},
472+
},
473+
"Envoy REQ header if not present invalid truncation": {
474+
hp: &contour_api_v1.HeadersPolicy{
475+
Set: []contour_api_v1.HeaderValue{{
476+
Name: "X-Request-Foo-Fallback",
477+
Value: "%REQ(X-Foo?X-Bar):baz%",
478+
}},
479+
},
480+
dhp: HeadersPolicy{},
481+
want: HeadersPolicy{
482+
Set: map[string]string{
483+
"X-Request-Foo-Fallback": "%%REQ(X-Foo?X-Bar):baz%%",
484+
},
485+
},
486+
},
487+
"valid Envoy REQ header if not present http/2 pseudo-header": {
488+
hp: &contour_api_v1.HeadersPolicy{
489+
Set: []contour_api_v1.HeaderValue{{
490+
Name: "X-Request-Path-Fallback",
491+
Value: "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%",
492+
}},
493+
},
494+
dhp: HeadersPolicy{},
495+
want: HeadersPolicy{
496+
Set: map[string]string{
497+
"X-Request-Path-Fallback": "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%",
498+
},
499+
},
500+
},
417501
"invalid Envoy REQ header is escaped": {
418502
hp: &contour_api_v1.HeadersPolicy{
419503
Set: []contour_api_v1.HeaderValue{{

0 commit comments

Comments
 (0)