Skip to content

Commit 5ac1412

Browse files
committed
feat(translator): ext-proc attributes
Signed-off-by: Guy Daich <[email protected]>
1 parent 98457b5 commit 5ac1412

File tree

11 files changed

+124
-6
lines changed

11 files changed

+124
-6
lines changed

examples/grpc-ext-proc/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ func (s *extProcServer) Process(srv envoy_service_proc_v3.ExternalProcessor_Proc
210210
resp := &envoy_service_proc_v3.ProcessingResponse{}
211211
switch v := req.Request.(type) {
212212
case *envoy_service_proc_v3.ProcessingRequest_RequestHeaders:
213+
xdsRouteName := ""
214+
215+
if req.Attributes != nil {
216+
if epa, ok := req.Attributes["envoy.filters.http.ext_proc"]; ok {
217+
if rqa, ok := epa.Fields["xds.route_name"]; ok {
218+
xdsRouteName = rqa.GetStringValue()
219+
}
220+
}
221+
}
222+
213223
xrch := ""
214224
if v.RequestHeaders != nil {
215225
hdrs := v.RequestHeaders.Headers.GetHeaders()
@@ -230,6 +240,12 @@ func (s *extProcServer) Process(srv envoy_service_proc_v3.ExternalProcessor_Proc
230240
RawValue: []byte("true"),
231241
},
232242
},
243+
{
244+
Header: &envoy_api_v3_core.HeaderValue{
245+
Key: "x-request-xds-route-name",
246+
RawValue: []byte(xdsRouteName),
247+
},
248+
},
233249
},
234250
},
235251
},
@@ -257,8 +273,19 @@ func (s *extProcServer) Process(srv envoy_service_proc_v3.ExternalProcessor_Proc
257273
RequestHeaders: rhq,
258274
},
259275
}
276+
260277
break
261278
case *envoy_service_proc_v3.ProcessingRequest_ResponseHeaders:
279+
280+
respXDSRouteName := ""
281+
282+
if req.Attributes != nil {
283+
if epa, ok := req.Attributes["envoy.filters.http.ext_proc"]; ok {
284+
if rsa, ok := epa.Fields["xds.route_name"]; ok {
285+
respXDSRouteName = rsa.GetStringValue()
286+
}
287+
}
288+
}
262289
rhq := &envoy_service_proc_v3.HeadersResponse{
263290
Response: &envoy_service_proc_v3.CommonResponse{
264291
HeaderMutation: &envoy_service_proc_v3.HeaderMutation{
@@ -269,6 +296,12 @@ func (s *extProcServer) Process(srv envoy_service_proc_v3.ExternalProcessor_Proc
269296
RawValue: []byte("true"),
270297
},
271298
},
299+
{
300+
Header: &envoy_api_v3_core.HeaderValue{
301+
Key: "x-response-xds-route-name",
302+
RawValue: []byte(respXDSRouteName),
303+
},
304+
},
272305
},
273306
},
274307
},

internal/gatewayapi/envoyextensionpolicy.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,21 @@ func (t *Translator) buildExtProc(
481481
if extProc.ProcessingMode.Request.Body != nil {
482482
extProcIR.RequestBodyProcessingMode = ptr.To(ir.ExtProcBodyProcessingMode(*extProc.ProcessingMode.Request.Body))
483483
}
484+
485+
if extProc.ProcessingMode.Request.Attributes != nil {
486+
extProcIR.RequestAttributes = append(extProcIR.RequestAttributes, extProc.ProcessingMode.Request.Attributes...)
487+
}
484488
}
485489

486490
if extProc.ProcessingMode.Response != nil {
487491
extProcIR.ResponseHeaderProcessing = true
488492
if extProc.ProcessingMode.Response.Body != nil {
489493
extProcIR.ResponseBodyProcessingMode = ptr.To(ir.ExtProcBodyProcessingMode(*extProc.ProcessingMode.Response.Body))
490494
}
495+
496+
if extProc.ProcessingMode.Response.Attributes != nil {
497+
extProcIR.ResponseAttributes = append(extProcIR.ResponseAttributes, extProc.ProcessingMode.Response.Attributes...)
498+
}
491499
}
492500
}
493501

internal/gatewayapi/testdata/envoyextensionpolicy-with-extproc-with-backendtlspolicy.in.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,13 @@ envoyExtensionPolicies:
203203
processingMode:
204204
request:
205205
body: Buffered
206+
attributes:
207+
- request.path
206208
response:
207209
body: Streamed
210+
attributes:
211+
- xds.route_metadata
212+
- connection.requested_server_name
208213
messageTimeout: 5s
209214
failOpen: true
210215
- apiVersion: gateway.envoyproxy.io/v1alpha1

internal/gatewayapi/testdata/envoyextensionpolicy-with-extproc-with-backendtlspolicy.out.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,13 @@ envoyExtensionPolicies:
113113
messageTimeout: 5s
114114
processingMode:
115115
request:
116+
attributes:
117+
- request.path
116118
body: Buffered
117119
response:
120+
attributes:
121+
- xds.route_metadata
122+
- connection.requested_server_name
118123
body: Streamed
119124
targetRef:
120125
group: gateway.networking.k8s.io
@@ -363,8 +368,13 @@ xdsIR:
363368
failOpen: true
364369
messageTimeout: 5s
365370
name: envoyextensionpolicy/default/policy-for-gateway/extproc/0
371+
requestAttributes:
372+
- request.path
366373
requestBodyProcessingMode: Buffered
367374
requestHeaderProcessing: true
375+
responseAttributes:
376+
- xds.route_metadata
377+
- connection.requested_server_name
368378
responseBodyProcessingMode: Streamed
369379
responseHeaderProcessing: true
370380
hostname: www.bar.com

internal/ir/xds.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,6 +2602,14 @@ type ExtProc struct {
26022602

26032603
// ResponseBodyProcessingMode Defines response body processing
26042604
ResponseBodyProcessingMode *ExtProcBodyProcessingMode `json:"responseBodyProcessingMode,omitempty" yaml:"responseBodyProcessingMode,omitempty"`
2605+
2606+
// RequestAttributes defines which envoy attributes are provided as context to external processor
2607+
// when processing requests
2608+
RequestAttributes []string `json:"requestAttributes,omitempty" yaml:"requestAttributes,omitempty"`
2609+
2610+
// ResponseAttributes defines which envoy attributes are provided as context to external processor
2611+
// when processing responses
2612+
ResponseAttributes []string `json:"responseAttributes,omitempty" yaml:"responseAttributes,omitempty"`
26052613
}
26062614

26072615
// Wasm holds the information associated with the Wasm extensions.

internal/ir/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/xds/translator/extproc.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ func extProcConfig(extProc ir.ExtProc) *extprocv3.ExternalProcessor {
137137
config.ProcessingMode.ResponseHeaderMode = extprocv3.ProcessingMode_SEND
138138
}
139139

140+
if extProc.RequestAttributes != nil {
141+
var attrs []string
142+
attrs = append(attrs, extProc.RequestAttributes...)
143+
config.RequestAttributes = attrs
144+
}
145+
146+
if extProc.ResponseAttributes != nil {
147+
var attrs []string
148+
attrs = append(attrs, extProc.ResponseAttributes...)
149+
config.ResponseAttributes = attrs
150+
}
151+
140152
return config
141153
}
142154

internal/xds/translator/testdata/in/xds-ir/ext-proc.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ http:
2323
- name: envoyextensionpolicy/default/policy-for-route-2/extproc/0
2424
failOpen: true
2525
messageTimeout: 5s
26+
requestAttributes:
27+
- xds.route_metadata
28+
- connection.requested_server_name
2629
requestHeaderProcessing: true
2730
requestBodyProcessingMode: Buffered
31+
responseAttributes:
32+
- request.path
2833
responseBodyProcessingMode: Streamed
2934
authority: grpc-backend-4.default:4000
3035
destination:
@@ -71,6 +76,11 @@ http:
7176
- name: envoyextensionpolicy/envoy-gateway/policy-for-gateway-1/extproc/0
7277
failOpen: false
7378
messageTimeout: 15s
79+
requestAttributes:
80+
- xds.route_metadata
81+
- connection.requested_server_name
82+
responseAttributes:
83+
- request.path
7484
authority: grpc-backend.envoy-gateway:9000
7585
destination:
7686
name: envoyextensionpolicy/envoy-gateway/policy-for-gateway-1/0/grpc-backend

internal/xds/translator/testdata/out/xds-ir/ext-proc.listeners.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
responseBodyMode: STREAMED
3434
responseHeaderMode: SKIP
3535
responseTrailerMode: SKIP
36+
requestAttributes:
37+
- xds.route_metadata
38+
- connection.requested_server_name
39+
responseAttributes:
40+
- request.path
3641
- disabled: true
3742
name: envoy.filters.http.ext_proc/envoyextensionpolicy/default/policy-for-route-1/extproc/0
3843
typedConfig:
@@ -79,6 +84,11 @@
7984
requestTrailerMode: SKIP
8085
responseHeaderMode: SKIP
8186
responseTrailerMode: SKIP
87+
requestAttributes:
88+
- xds.route_metadata
89+
- connection.requested_server_name
90+
responseAttributes:
91+
- request.path
8292
- name: envoy.filters.http.router
8393
typedConfig:
8494
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

test/e2e/testdata/ext-proc-envoyextensionpolicy.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ spec:
5151
namespace: gateway-conformance-infra
5252
port: 9002
5353
processingMode:
54-
request: {}
55-
response: {}
54+
request:
55+
attributes:
56+
- xds.route_name
57+
response:
58+
attributes:
59+
- xds.route_name
5660
---
5761
apiVersion: gateway.envoyproxy.io/v1alpha1
5862
kind: EnvoyExtensionPolicy

0 commit comments

Comments
 (0)