Skip to content

Commit

Permalink
feat: support failOpen in ext auth (#2948)
Browse files Browse the repository at this point in the history
* feat: support failOpen in ext auth

Signed-off-by: Dennis Zhou <idennis.zhou@gmail.com>

* fix test

Signed-off-by: Dennis Zhou <idennis.zhou@gmail.com>

---------

Signed-off-by: Dennis Zhou <idennis.zhou@gmail.com>
  • Loading branch information
deszhou authored Mar 18, 2024
1 parent 36717d7 commit 2161064
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/gatewayapi/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ func (t *Translator) buildExtAuth(
extAuth := &ir.ExtAuth{
Name: name,
HeadersToExtAuth: policy.Spec.ExtAuth.HeadersToExtAuth,
FailOpen: policy.Spec.ExtAuth.FailOpen,
}

if http != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ securityPolicies:
headersToBackend:
- header1
- header2
failOpen: false
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ securityPolicies:
namespace: default
spec:
extAuth:
failOpen: false
http:
backendRef:
name: http-backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ securityPolicies:
headersToBackend:
- header1
- header2
failOpen: false
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ securityPolicies:
namespace: default
spec:
extAuth:
failOpen: false
http:
backendRef:
name: http-backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ securityPolicies:
headersToBackend:
- header1
- header2
failOpen: false
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ securityPolicies:
namespace: default
spec:
extAuth:
failOpen: false
http:
backendRef:
name: http-backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ securityPolicies:
headersToBackend:
- header1
- header2
failOpen: false
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ securityPolicies:
namespace: default
spec:
extAuth:
failOpen: false
http:
backendRef:
name: http-backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ securityPolicies:
headersToBackend:
- header1
- header2
failOpen: false
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
Expand All @@ -229,3 +230,4 @@ securityPolicies:
backendRef:
name: grpc-backend
port: 9000
failOpen: true
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ securityPolicies:
namespace: default
spec:
extAuth:
failOpen: true
grpc:
backendRef:
name: grpc-backend
Expand Down Expand Up @@ -242,6 +243,7 @@ securityPolicies:
namespace: default
spec:
extAuth:
failOpen: false
http:
backendRef:
name: http-backend
Expand Down Expand Up @@ -305,6 +307,7 @@ xdsIR:
protocol: HTTP
weight: 1
extAuth:
failOpen: true
grpc:
authority: grpc-backend.default:9000
destination:
Expand Down Expand Up @@ -345,6 +348,7 @@ xdsIR:
protocol: HTTP
weight: 1
extAuth:
failOpen: false
http:
authority: http-backend.envoy-gateway:80
destination:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ securityPolicies:
headersToBackend:
- header1
- header2
failOpen: false
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
Expand All @@ -169,3 +170,4 @@ securityPolicies:
backendRef:
name: grpc-backend
port: 9000
failOpen: true
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ securityPolicies:
namespace: default
spec:
extAuth:
failOpen: true
grpc:
backendRef:
name: grpc-backend
Expand Down Expand Up @@ -182,6 +183,7 @@ securityPolicies:
namespace: default
spec:
extAuth:
failOpen: false
http:
backendRef:
name: http-backend
Expand Down Expand Up @@ -245,6 +247,7 @@ xdsIR:
protocol: HTTP
weight: 1
extAuth:
failOpen: true
grpc:
authority: grpc-backend.default:9000
destination:
Expand Down Expand Up @@ -280,6 +283,7 @@ xdsIR:
protocol: HTTP
weight: 1
extAuth:
failOpen: true
grpc:
authority: grpc-backend.default:9000
destination:
Expand Down Expand Up @@ -315,6 +319,7 @@ xdsIR:
protocol: HTTP
weight: 1
extAuth:
failOpen: false
http:
authority: http-backend.envoy-gateway:80
destination:
Expand Down
8 changes: 8 additions & 0 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,14 @@ type ExtAuth struct {
// in HeadersToExtAuth or not.
// +optional
HeadersToExtAuth []string `json:"headersToExtAuth,omitempty"`

// FailOpen is a switch used to control the behavior when a response from the External Authorization service cannot be obtained.
// If FailOpen is set to true, the system allows the traffic to pass through.
// Otherwise, if it is set to false or not set (defaulting to false),
// the system blocks the traffic and returns a HTTP 5xx error, reflecting a fail-closed approach.
// This setting determines whether to prioritize accessibility over strict security in case of authorization service failure.
// +optional
FailOpen *bool `json:"failOpen,omitempty"`
}

// HTTPExtAuthService defines the HTTP External Authorization service
Expand Down
5 changes: 5 additions & 0 deletions internal/ir/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion internal/xds/translator/extauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ func extAuthFilterName(extAuth *ir.ExtAuth) string {
func extAuthConfig(extAuth *ir.ExtAuth) *extauthv3.ExtAuthz {
config := &extauthv3.ExtAuthz{
TransportApiVersion: corev3.ApiVersion_V3,
FailureModeAllow: false,
}

if extAuth.FailOpen != nil {
config.FailureModeAllow = *extAuth.FailOpen
}

var headersToExtAuth []*matcherv3.StringMatcher
Expand Down
3 changes: 3 additions & 0 deletions 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,7 @@ http:
port: 80
protocol: HTTP
weight: 1
failOpen: false
- name: httproute/default/httproute-1/rule/1/match/0/www_example_com
hostname: "*"
pathMatch:
Expand Down Expand Up @@ -62,6 +63,7 @@ http:
port: 80
protocol: HTTP
weight: 1
failOpen: false
- name: httproute/default/httproute-2/rule/0/match/0/www_example_com
hostname: "*"
pathMatch:
Expand All @@ -88,3 +90,4 @@ http:
headersToExtAuth:
- header1
- header2
failOpen: true
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
patterns:
- exact: header1
- exact: header2
failureModeAllow: true
grpcService:
envoyGrpc:
authority: grpc-backend.default:9000
Expand Down

0 comments on commit 2161064

Please sign in to comment.