Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: huabing zhao <[email protected]>
  • Loading branch information
zhaohuabing committed Mar 12, 2024
1 parent 5d8f2b9 commit 70b29a2
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 14 deletions.
10 changes: 8 additions & 2 deletions internal/gatewayapi/testdata/securitypolicy-with-extauth.in.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ httpRoutes:
rules:
- matches:
- path:
value: /foo
value: /foo1
backendRefs:
- name: service-1
port: 8080
- matches:
- path:
value: /foo2
backendRefs:
- name: service-2
port: 8080
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
Expand All @@ -50,7 +56,7 @@ httpRoutes:
- path:
value: /bar
backendRefs:
- name: service-1
- name: service-3
port: 8080
services:
- apiVersion: v1
Expand Down
47 changes: 44 additions & 3 deletions internal/gatewayapi/testdata/securitypolicy-with-extauth.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ httpRoutes:
port: 8080
matches:
- path:
value: /foo
value: /foo1
- backendRefs:
- name: service-2
port: 8080
matches:
- path:
value: /foo2
status:
parents:
- conditions:
Expand Down Expand Up @@ -93,7 +99,7 @@ httpRoutes:
sectionName: http
rules:
- backendRefs:
- name: service-1
- name: service-3
port: 8080
matches:
- path:
Expand Down Expand Up @@ -245,7 +251,42 @@ xdsIR:
pathMatch:
distinct: false
name: ""
prefix: /foo
prefix: /foo1
- backendWeights:
invalid: 0
valid: 0
destination:
name: httproute/default/httproute-1/rule/1
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 8080
protocol: HTTP
weight: 1
extAuth:
grpc:
authority: grpc-backend.default:9000
destination:
name: securitypolicy/default/policy-for-http-route/grpc-backend
settings:
- addressType: IP
endpoints:
- host: 8.8.8.8
port: 9000
protocol: GRPC
weight: 1
headersToExtAuth:
- header1
- header2
name: default/httproute-1
hostname: www.foo.com
isHTTP2: false
name: httproute/default/httproute-1/rule/1/match/0/www_foo_com
pathMatch:
distinct: false
name: ""
prefix: /foo2
- backendWeights:
invalid: 0
valid: 0
Expand Down
6 changes: 2 additions & 4 deletions internal/xds/translator/extauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ func (*extAuth) patchHCM(mgr *hcmv3.HttpConnectionManager, irListener *ir.HTTPLi
// Only generates one OAuth2 Envoy filter for each unique name.
// For example, if there are two routes under the same gateway with the
// same OIDC config, only one OAuth2 filter will be generated.
for _, existingFilter := range mgr.HttpFilters {
if existingFilter.Name == extAuthFilterName(route.ExtAuth) {
continue
}
if hcmContainsFilter(mgr, extAuthFilterName(route.ExtAuth)) {
continue
}

filter, err := buildHCMExtAuthFilter(route.ExtAuth)
Expand Down
29 changes: 28 additions & 1 deletion internal/xds/translator/testdata/in/xds-ir/ext-auth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ http:
port: 80
protocol: HTTP
weight: 1
- name: httproute/default/httproute-1/rule/1/match/0/www_example_com
hostname: "*"
pathMatch:
exact: "foo"
destination:
name: httproute/default/httproute-1/rule/0
settings:
- endpoints:
- host: "10.0.0.1"
port: 50000
extAuth:
name: default/httproute-1
http:
authority: http-backend.envoy-gateway:80
headersToBackend:
- header1
- header2
path: /auth
destination:
name: securitypolicy/default/policy-for-first-route/http-backend
settings:
- addressType: IP
endpoints:
- host: 7.7.7.7
port: 80
protocol: HTTP
weight: 1
- name: httproute/default/httproute-2/rule/0/match/0/www_example_com
hostname: "*"
pathMatch:
Expand All @@ -46,7 +73,7 @@ http:
- host: "10.0.0.2"
port: 60000
extAuth:
name: default/httproute-2
name: default/gateway-1
grpc:
authority: grpc-backend.default:9000
destination:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
uri: http://http-backend.envoy-gateway:80/auth
transportApiVersion: V3
- disabled: true
name: envoy.filters.http.ext_authz_default/httproute-2
name: envoy.filters.http.ext_authz_default/gateway-1
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz
allowedHeaders:
Expand Down
13 changes: 12 additions & 1 deletion internal/xds/translator/testdata/out/xds-ir/ext-auth.routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
envoy.filters.http.ext_authz_default/httproute-1:
'@type': type.googleapis.com/envoy.config.route.v3.FilterConfig
config: {}
- match:
path: foo
name: httproute/default/httproute-1/rule/1/match/0/www_example_com
route:
cluster: httproute/default/httproute-1/rule/0
upgradeConfigs:
- upgradeType: websocket
typedPerFilterConfig:
envoy.filters.http.ext_authz_default/httproute-1:
'@type': type.googleapis.com/envoy.config.route.v3.FilterConfig
config: {}
- match:
path: bar
name: httproute/default/httproute-2/rule/0/match/0/www_example_com
Expand All @@ -24,6 +35,6 @@
upgradeConfigs:
- upgradeType: websocket
typedPerFilterConfig:
envoy.filters.http.ext_authz_default/httproute-2:
envoy.filters.http.ext_authz_default/gateway-1:
'@type': type.googleapis.com/envoy.config.route.v3.FilterConfig
config: {}
14 changes: 12 additions & 2 deletions internal/xds/translator/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"

routev3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
hcmv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
"google.golang.org/protobuf/types/known/anypb"
)

Expand Down Expand Up @@ -109,6 +110,15 @@ func enableFilterOnRoute(filterType string, route *routev3.Route, configName str
return nil
}

func perRouteFilterName(filterType, routeName string) string {
return fmt.Sprintf("%s_%s", filterType, routeName)
func perRouteFilterName(filterType, configName string) string {
return fmt.Sprintf("%s_%s", filterType, configName)
}

func hcmContainsFilter(mgr *hcmv3.HttpConnectionManager, filterName string) bool {
for _, existingFilter := range mgr.HttpFilters {
if existingFilter.Name == filterName {
return true
}
}
return false
}

0 comments on commit 70b29a2

Please sign in to comment.