Skip to content

Commit

Permalink
dag: configure 502 if include references another (#5016)
Browse files Browse the repository at this point in the history
Set 502 response if include references another root

Fixes #5016

Signed-off-by: Lan Liang <gcslyp@gmail.com>
  • Loading branch information
liangyuanpeng committed Mar 9, 2023
1 parent 36d6e45 commit 4514034
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions internal/dag/httpproxy_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,18 @@ func addRoutes(vhost vhost, routes []*Route) {
}
}

func addStatusBadGatewayRoute(routes []*Route, conds []contour_api_v1.MatchCondition) []*Route {
if len(conds) > 0 {
routes = append(routes, &Route{
PathMatchCondition: mergePathMatchConditions(conds),
HeaderMatchConditions: mergeHeaderMatchConditions(conds),
QueryParamMatchConditions: mergeQueryParamMatchConditions(conds),
DirectResponse: directResponse(http.StatusBadGateway, ""),
})
}
return routes
}

func (p *HTTPProxyProcessor) computeRoutes(
validCond *contour_api_v1.DetailedCondition,
rootProxy *contour_api_v1.HTTPProxy,
Expand Down Expand Up @@ -655,21 +667,15 @@ func (p *HTTPProxyProcessor) computeRoutes(
"include %s/%s not found", namespace, include.Name)

// Set 502 response when include was not found but include condition was valid.
if len(include.Conditions) > 0 {
routes = append(routes, &Route{
PathMatchCondition: mergePathMatchConditions(include.Conditions),
HeaderMatchConditions: mergeHeaderMatchConditions(include.Conditions),
QueryParamMatchConditions: mergeQueryParamMatchConditions(include.Conditions),
DirectResponse: directResponse(http.StatusBadGateway, ""),
})
}

routes = addStatusBadGatewayRoute(routes, include.Conditions)
continue
}

if includedProxy.Spec.VirtualHost != nil {
validCond.AddErrorf(contour_api_v1.ConditionTypeIncludeError, "RootIncludesRoot",
"root httpproxy cannot include another root httpproxy")
// Set 502 response if include references another root
routes = addStatusBadGatewayRoute(routes, include.Conditions)
continue
}

Expand Down

0 comments on commit 4514034

Please sign in to comment.