-
Notifications
You must be signed in to change notification settings - Fork 712
Add support for HTTP External Authorization Services #7418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -239,15 +239,39 @@ type ExtensionServiceReference struct { | |
| Name string `json:"name,omitempty" protobuf:"bytes,3,opt,name=name"` | ||
| } | ||
|
|
||
| // AuthorizationServiceType indicates the protocol | ||
| // implemented by the external authorization server. | ||
| type AuthorizationServiceType string | ||
|
|
||
| const ( | ||
| AuthorizationGRPCService AuthorizationServiceType = "grpc" | ||
| AuthorizationHTTPService AuthorizationServiceType = "http" | ||
| ) | ||
|
|
||
| // AuthorizationServer configures an external server to authenticate | ||
| // client requests. The external server must implement the v3 Envoy | ||
| // external authorization GRPC protocol (https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/auth/v3/external_auth.proto). | ||
| // external authorization GRPC protocol (https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/auth/v3/external_auth.proto) | ||
| // or the HTTP authorization server protocol. | ||
| // +kubebuilder:validation:XValidation:message="httpSettings can only be set when serviceType is 'http'",rule="!has(self.httpSettings) || self.serviceType == 'http'" | ||
| type AuthorizationServer struct { | ||
| // ExtensionServiceRef specifies the extension resource that will authorize client requests. | ||
| // | ||
| // +optional | ||
| ExtensionServiceRef ExtensionServiceReference `json:"extensionRef,omitempty"` | ||
|
|
||
| // ServiceType sets the protocol used to communicate with | ||
| // the external authorization server. | ||
| // | ||
| // +optional | ||
| // +kubebuilder:validation:Enum=http;grpc | ||
| // +kubebuilder:default=grpc | ||
| ServiceType AuthorizationServiceType `json:"serviceType,omitempty"` | ||
|
|
||
| // HTTPAuthorizationServerSettings defines configurations for interacting with an external HTTP authorization server. | ||
| // | ||
| // +optional | ||
| HTTPServerSettings *HTTPAuthorizationServerSettings `json:"httpSettings,omitempty"` | ||
|
|
||
| // AuthPolicy sets a default authorization policy for client requests. | ||
| // This policy will be used unless overridden by individual routes. | ||
| // | ||
|
|
@@ -276,6 +300,64 @@ type AuthorizationServer struct { | |
| WithRequestBody *AuthorizationServerBufferSettings `json:"withRequestBody,omitempty"` | ||
| } | ||
|
|
||
| // HTTPAuthorizationServerSettings defines configurations for interacting with an external HTTP authorization server. | ||
| type HTTPAuthorizationServerSettings struct { | ||
| // PathPrefix Sets a prefix to the value of authorization request header Path. | ||
| // | ||
| // +optional | ||
| PathPrefix string `json:"pathPrefix,omitempty"` | ||
|
|
||
| // AllowedAuthorizationHeaders specifies client request headers that will be sent to the authorization server. | ||
| // Host, Method, Path, Content-Length, and Authorization headers are additionally included in the list. | ||
| // | ||
| // +optional | ||
| AllowedAuthorizationHeaders []HTTPAuthorizationServerAllowedHeaders `json:"allowedAuthorizationHeaders,omitempty"` | ||
|
Comment on lines
+310
to
+314
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should move this to the top level (directly to Envoy had deprecated the HTTP service level field
I would prefer the name |
||
|
|
||
| // AllowedUpstreamHeaders specifies response headers from the authorization server | ||
| // that may be added to the original client request before sending it to the upstream. | ||
| // | ||
| // +optional | ||
| AllowedUpstreamHeaders []HTTPAuthorizationServerAllowedHeaders `json:"allowedUpstreamHeaders,omitempty"` | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also add field The use case for this is in #7367. |
||
|
|
||
| // HTTPAuthorizationServerAllowedHeaders specifies how to conditionally match against allowed headers | ||
| // in the context of HTTP authorization. Regex support is intentionally excluded to simplify the user | ||
| // experience and prevent potential issues. Only one of Prefix, Exact, Suffix or Contains must be provided. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also define CEL validation for early detection to enforce this at creation time to avoid any possible confusion. Something like below but note that I did not test this yet +// +kubebuilder:validation:XValidation:message="only one of prefix, suffix, exact, and contains should be set in the allowedHeader",rule="(has(self.exact) ? 1 : 0) + (has(self.prefix) ? 1 : 0) + (has(self.suffix) ? 1 : 0) + (has(self.contains) ? 1 : 0) == 1" |
||
| // +kubebuilder:validation:XValidation:message="only one of prefix, suffix, exact, and contains should be set in the allowedHeader",rule="(has(self.exact) ? 1 : 0) + (has(self.prefix) ? 1 : 0) + (has(self.suffix) ? 1 : 0) + (has(self.contains) ? 1 : 0) == 1" | ||
| type HTTPAuthorizationServerAllowedHeaders struct { | ||
| // Exact specifies a string that the header name must be equal to. | ||
| // | ||
| // +optional | ||
| Exact string `json:"exact,omitempty"` | ||
|
|
||
| // Prefix defines a prefix match for the header name. | ||
| // | ||
| // +optional | ||
| Prefix string `json:"prefix,omitempty"` | ||
|
|
||
| // Suffix defines a suffix match for a header name. | ||
| // | ||
| // +optional | ||
| Suffix string `json:"suffix,omitempty"` | ||
|
|
||
| // To streamline user experience and mitigate potential issues, we do not support regex. | ||
| // Additionally, it's essential to ensure that any regex patterns adhere to the configured runtime key, re2.max_program_size.error_level | ||
| // by verifying that the program size is smaller than the specified value. | ||
| // This necessitates thorough validation of user input. | ||
| // | ||
| // Regex string `json:"regex,omitempty"` | ||
|
|
||
| // Contains specifies a substring that must be present in the header name. | ||
| // | ||
| // +optional | ||
| Contains string `json:"contains,omitempty"` | ||
|
|
||
| // IgnoreCase specifies whether string matching should be case-insensitive. | ||
| // | ||
| // +optional | ||
| IgnoreCase bool `json:"ignoreCase,omitempty"` | ||
| } | ||
|
|
||
| // AuthorizationServerBufferSettings enables ExtAuthz filter to buffer client request data and send it as part of authorization request | ||
| type AuthorizationServerBufferSettings struct { | ||
| // MaxRequestBytes sets the maximum size of message body ExtAuthz filter will hold in-memory. | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,7 @@ type ExtensionServiceTarget struct { | |
| // ExtensionServiceSpec defines the desired state of an ExtensionService resource. | ||
| type ExtensionServiceSpec struct { | ||
| // Services specifies the set of Kubernetes Service resources that | ||
| // receive GRPC extension API requests. | ||
| // receive extension API requests. | ||
| // If no weights are specified for any of the entries in | ||
| // this array, traffic will be spread evenly across all the | ||
| // services. | ||
|
|
@@ -78,15 +78,15 @@ type ExtensionServiceSpec struct { | |
| UpstreamValidation *contour_v1.UpstreamValidation `json:"validation,omitempty"` | ||
|
|
||
| // Protocol may be used to specify (or override) the protocol used to reach this Service. | ||
| // Values may be h2 or h2c. If omitted, protocol-selection falls back on Service annotations. | ||
| // Values may be h2, h2c or http/1.1. If omitted, protocol-selection falls back on Service annotations. | ||
| // | ||
| // +optional | ||
| // +kubebuilder:validation:Enum=h2;h2c | ||
| // +kubebuilder:validation:Enum=http/1.1;h2;h2c | ||
| Protocol *string `json:"protocol,omitempty"` | ||
|
Comment on lines
80
to
85
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Adding the I have also question regarding how the Finally, we should consider whether the |
||
|
|
||
| // The policy for load balancing GRPC service requests. Note that the | ||
| // The policy for load balancing service requests. Note that the | ||
| // `Cookie` and `RequestHash` load balancing strategies cannot be used | ||
| // here. | ||
| // here for GRPC service requests. | ||
| // | ||
| // +optional | ||
| LoadBalancerPolicy *contour_v1.LoadBalancerPolicy `json:"loadBalancerPolicy,omitempty"` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ## Contour now supports HTTP external authorization services | ||
|
|
||
| With this change, Contour supports HTTP external authorization services in addition to gRPC. | ||
| This expands compatibility with a broader range of authorization providers and | ||
| allows operators to choose the protocol that best fits their environment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment stating that
httpSettingsis used only for HTTP based authorization service.To enforce this and prevent confusion, we can add a CEL validation rule to the
AuthorizationServerstruct. Something like below but note that I did not test this yet