Skip to content

Commit

Permalink
add BodyToExtAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienPillevesse committed Nov 7, 2024
1 parent aeb6848 commit ce1a65b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/ext_auth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type ExtAuth struct {
// +optional
HeadersToExtAuth []string `json:"headersToExtAuth,omitempty"`

BodyToExtAuth *string `json:"bodyToExtAuth,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),
Expand Down
1 change: 1 addition & 0 deletions internal/gatewayapi/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ func (t *Translator) buildExtAuth(policy *egv1a1.SecurityPolicy, resources *reso
extAuth := &ir.ExtAuth{
Name: irConfigName(policy),
HeadersToExtAuth: policy.Spec.ExtAuth.HeadersToExtAuth,
BodyToExtAuth: policy.Spec.ExtAuth.BodyToExtAuth,
FailOpen: policy.Spec.ExtAuth.FailOpen,
Traffic: traffic,
RecomputeRoute: policy.Spec.ExtAuth.RecomputeRoute,
Expand Down
2 changes: 2 additions & 0 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ type ExtAuth struct {
// +optional
HeadersToExtAuth []string `json:"headersToExtAuth,omitempty"`

BodyToExtAuth *string `json:"bodyToExtAuth,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),
Expand Down
7 changes: 7 additions & 0 deletions internal/xds/translator/extauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ func extAuthConfig(extAuth *ir.ExtAuth) *extauthv3.ExtAuthz {
})
}

if extAuth.BodyToExtAuth != nil {
config.WithRequestBody = &extauthv3.BufferSettings{
AllowPartialMessage: false,
PackAsBytes: false,
}
}

if len(headersToExtAuth) > 0 {
config.AllowedHeaders = &matcherv3.ListStringMatcher{
Patterns: headersToExtAuth,
Expand Down

0 comments on commit ce1a65b

Please sign in to comment.