Skip to content

Commit 1c09330

Browse files
committed
return 500 error for invalid filters
Signed-off-by: Huabing Zhao <[email protected]>
1 parent 0623ca5 commit 1c09330

7 files changed

+105
-1
lines changed

internal/gatewayapi/route.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,13 @@ func (t *Translator) processHTTPRouteRules(httpRoute *HTTPRouteContext, parentRe
188188
// process each HTTPRouteRule, generate a unique Xds IR HTTPRoute per match of the rule
189189
for ruleIdx, rule := range httpRoute.Spec.Rules {
190190
// process HTTP Route filters first, so that the filters can be applied to the IR route later
191+
var processFilterError error
191192
httpFiltersContext, errs := t.ProcessHTTPFilters(parentRef, httpRoute, rule.Filters, ruleIdx, resources)
192193
if len(errs) > 0 {
193194
for _, err := range errs {
194195
errorCollector.Add(err)
196+
processFilterError = errors.Join(processFilterError, err)
195197
}
196-
continue
197198
}
198199

199200
// build the metadata for this route rule
@@ -267,6 +268,26 @@ func (t *Translator) processHTTPRouteRules(httpRoute *HTTPRouteContext, parentRe
267268
Metadata: routeRuleMetadata,
268269
}
269270
switch {
271+
case processFilterError != nil:
272+
routesWithDirectResponse := sets.New[string]()
273+
for _, irRoute := range ruleRoutes {
274+
// If the route already has a direct response or redirect configured, then it was from a filter so skip
275+
// the direct response from errors.
276+
if irRoute.DirectResponse != nil || irRoute.Redirect != nil {
277+
continue
278+
}
279+
irRoute.DirectResponse = &ir.CustomResponse{
280+
StatusCode: ptr.To(uint32(500)),
281+
}
282+
routesWithDirectResponse.Insert(irRoute.Name)
283+
}
284+
if len(routesWithDirectResponse) > 0 {
285+
t.Logger.Info(
286+
"setting 500 direct response in routes due to errors in processing filters",
287+
"routes", sets.List(routesWithDirectResponse),
288+
"error", processFilterError,
289+
)
290+
}
270291
// return 500 if no valid destination settings exist
271292
// the error is already added to the error list when processing the destination
272293
case processDestinationError != nil && destination.ToBackendWeights().Valid == 0:

internal/gatewayapi/testdata/extensions/httproute-with-custom-backend-invalid-group.out.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,20 @@ xdsIR:
142142
escapedSlashesAction: UnescapeAndRedirect
143143
mergeSlashes: true
144144
port: 10080
145+
routes:
146+
- directResponse:
147+
statusCode: 500
148+
hostname: gateway.envoyproxy.io
149+
isHTTP2: false
150+
metadata:
151+
kind: HTTPRoute
152+
name: httproute-1
153+
namespace: default
154+
name: httproute/default/httproute-1/rule/0/match/0/gateway_envoyproxy_io
155+
pathMatch:
156+
distinct: false
157+
name: ""
158+
prefix: /
145159
readyListener:
146160
address: 0.0.0.0
147161
ipFamily: IPv4

internal/gatewayapi/testdata/extensions/httproute-with-non-matching-extension-filter.out.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ xdsIR:
141141
escapedSlashesAction: UnescapeAndRedirect
142142
mergeSlashes: true
143143
port: 10080
144+
routes:
145+
- directResponse:
146+
statusCode: 500
147+
hostname: gateway.envoyproxy.io
148+
isHTTP2: false
149+
metadata:
150+
kind: HTTPRoute
151+
name: httproute-1
152+
namespace: default
153+
name: httproute/default/httproute-1/rule/0/match/0/gateway_envoyproxy_io
154+
pathMatch:
155+
distinct: false
156+
name: ""
157+
prefix: /
144158
readyListener:
145159
address: 0.0.0.0
146160
ipFamily: IPv4

internal/gatewayapi/testdata/httproute-with-direct-response.out.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,19 @@ xdsIR:
268268
mergeSlashes: true
269269
port: 10080
270270
routes:
271+
- directResponse:
272+
statusCode: 500
273+
hostname: '*.envoyproxy.io'
274+
isHTTP2: false
275+
metadata:
276+
kind: HTTPRoute
277+
name: direct-response-with-value-not-found
278+
namespace: default
279+
name: httproute/default/direct-response-with-value-not-found/rule/0/match/0/*_envoyproxy_io
280+
pathMatch:
281+
distinct: false
282+
name: ""
283+
prefix: /value-ref-not-found
271284
- addResponseHeaders:
272285
- append: false
273286
name: Content-Type

internal/gatewayapi/testdata/httproute-with-mirror-filter-service-no-port.out.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ xdsIR:
144144
escapedSlashesAction: UnescapeAndRedirect
145145
mergeSlashes: true
146146
port: 10080
147+
routes:
148+
- directResponse:
149+
statusCode: 500
150+
hostname: gateway.envoyproxy.io
151+
isHTTP2: false
152+
metadata:
153+
kind: HTTPRoute
154+
name: httproute-1
155+
namespace: default
156+
name: httproute/default/httproute-1/rule/0/match/0/gateway_envoyproxy_io
157+
pathMatch:
158+
distinct: false
159+
name: ""
160+
prefix: /
147161
readyListener:
148162
address: 0.0.0.0
149163
ipFamily: IPv4

internal/gatewayapi/testdata/httproute-with-mirror-filter-service-not-found.out.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ xdsIR:
145145
escapedSlashesAction: UnescapeAndRedirect
146146
mergeSlashes: true
147147
port: 10080
148+
routes:
149+
- directResponse:
150+
statusCode: 500
151+
hostname: gateway.envoyproxy.io
152+
isHTTP2: false
153+
metadata:
154+
kind: HTTPRoute
155+
name: httproute-1
156+
namespace: default
157+
name: httproute/default/httproute-1/rule/0/match/0/gateway_envoyproxy_io
158+
pathMatch:
159+
distinct: false
160+
name: ""
161+
prefix: /
148162
readyListener:
149163
address: 0.0.0.0
150164
ipFamily: IPv4

internal/gatewayapi/testdata/httproute-with-urlrewrite-filter-regex-match-replace-invalid.out.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,20 @@ xdsIR:
373373
escapedSlashesAction: UnescapeAndRedirect
374374
mergeSlashes: true
375375
port: 10080
376+
routes:
377+
- directResponse:
378+
statusCode: 500
379+
hostname: gateway.envoyproxy.io
380+
isHTTP2: false
381+
metadata:
382+
kind: HTTPRoute
383+
name: httproute-not-found
384+
namespace: default
385+
name: httproute/default/httproute-not-found/rule/0/match/0/gateway_envoyproxy_io
386+
pathMatch:
387+
distinct: false
388+
name: ""
389+
prefix: /notfound
376390
readyListener:
377391
address: 0.0.0.0
378392
ipFamily: IPv4

0 commit comments

Comments
 (0)