Add support for HTTP External Authorization Services#7418
Add support for HTTP External Authorization Services#7418therealak12 wants to merge 2 commits intoprojectcontour:mainfrom
Conversation
47679b5 to
4651b0c
Compare
Signed-off-by: therealak12 <ak12hastam@gmail.com>
4651b0c to
e0bce55
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #7418 +/- ##
==========================================
- Coverage 81.85% 81.78% -0.07%
==========================================
Files 130 130
Lines 15747 15895 +148
==========================================
+ Hits 12889 13000 +111
- Misses 2574 2608 +34
- Partials 284 287 +3
🚀 New features to boost your workflow:
|
tsaarni
left a comment
There was a problem hiding this comment.
Thank you @therealak12 for the contribution!
The changes look good overall but I would like to discuss some of the API aspects and potential error scenarios.
| // or a gRPC authorization server. | ||
| // | ||
| // +optional | ||
| ServiceAPIType contour_v1.AuthorizationServiceAPIType `json:"serviceAPIType,omitempty"` |
There was a problem hiding this comment.
Config file is parsed as YAML
| ServiceAPIType contour_v1.AuthorizationServiceAPIType `json:"serviceAPIType,omitempty"` | |
| ServiceAPIType contour_v1.AuthorizationServiceAPIType `yaml:"serviceAPIType,omitempty"` |
| // HttpAuthorizationServerSettings defines configurations for interacting with an external HTTP authorization server. | ||
| // | ||
| // +optional | ||
| HTTPServerSettings *contour_v1.HTTPAuthorizationServerSettings `json:"httpSettings,omitempty"` |
There was a problem hiding this comment.
Config file is parsed as YAML
| HTTPServerSettings *contour_v1.HTTPAuthorizationServerSettings `json:"httpSettings,omitempty"` | |
| HTTPServerSettings *contour_v1.HTTPAuthorizationServerSettings `yaml:"httpSettings,omitempty"` |
| }).Status(p).IsValid() | ||
| } | ||
|
|
||
| func AuthzTypeHTTPWithContext(t *testing.T, rh ResourceEventHandlerWrapper, c *Contour) { |
There was a problem hiding this comment.
AuthzTypeHTTPWithContext is not called anywhere. Forgot to call it from TestAuthorization?
| HttpService: &envoy_filter_http_ext_authz_v3.HttpService{ | ||
| ServerUri: &envoy_config_core_v3.HttpUri{ | ||
| // Uri: externalAuthorization.HttpServerURI, | ||
| Uri: "http://dummy/", |
There was a problem hiding this comment.
Is the Uri field mandatory, or can it be left empty? If it is required, we should add an explanation for not to cause confusion for reader.
| // HTTPAuthorizationServerSettings defines configurations for interacting with an external HTTP authorization server. | ||
| // | ||
| // +optional | ||
| HTTPServerSettings *HTTPAuthorizationServerSettings `json:"httpSettings,omitempty"` |
There was a problem hiding this comment.
Add a comment stating that httpSettings is used only for HTTP based authorization service.
To enforce this and prevent confusion, we can add a CEL validation rule to the AuthorizationServer struct. Something like below but note that I did not test this yet
// +kubebuilder:validation:XValidation:message="httpSettings can only be set when serviceAPIType is 'http'",rule="!has(self.httpSettings) || self.serviceAPIType == 'http'"
| switch contourConfiguration.GlobalExternalAuthorization.ServiceAPIType { | ||
| case contour_v1.AuthorizationGRPCService: | ||
| globalExternalAuthConfig.ServiceAPIType = contour_v1.AuthorizationGRPCService |
There was a problem hiding this comment.
Should we have fall back to the gRPC authorization server type here if type is not set?
| Context: context, | ||
| } | ||
|
|
||
| switch contourConfiguration.GlobalExternalAuthorization.ServiceAPIType { |
There was a problem hiding this comment.
We should refactor the switch-case logic in cmd/contour/serve.go within setupGlobalExternalAuthentication() and the corresponding logic in internal/dag/httpproxy_processor.go within computeVirtualHostAuthorization() into one.
| AuthorizationResponseTimeout: *respTimeout, | ||
| } | ||
|
|
||
| switch auth.ServiceAPIType { |
There was a problem hiding this comment.
We should refactor the switch-case logic in internal/dag/httpproxy_processor.go within computeVirtualHostAuthorization() and the corresponding logic in cmd/contour/serve.go within setupGlobalExternalAuthentication() into one.
| "AuthzTypeGRPC": AuthzTypeGRPC, | ||
| "AuthzTypeHTTP": authzTypeHTTP, | ||
| "AuthzTypeHTTPWithPathPrefix": AuthzTypeHTTPWithPathPrefix, | ||
| "AuthzTypeHTTPWithAllowedAuthorizationHeaders": AuthzTypeHTTPWithAllowedAuthorizationHeaders, | ||
| "AuthzTypeHTTPWithAllowedUpstreamHeaders": AuthzTypeHTTPWithAllowedUpstreamHeaders, |
There was a problem hiding this comment.
Minor nit: these test functions do not need to be exported. All of them can start with a lowercase letter.
| // +optional | ||
| // +kubebuilder:validation:Enum=http;grpc | ||
| // +kubebuilder:default=grpc | ||
| ServiceAPIType AuthorizationServiceAPIType `json:"serviceAPIType,omitempty"` |
There was a problem hiding this comment.
I recommend using serviceType (without API) to align with how Envoy seems to call it.
| HttpUpstreamType: &envoy_config_core_v3.HttpUri_Cluster{ | ||
| Cluster: externalAuthorization.AuthorizationService.Name, | ||
| }, | ||
| Timeout: envoy.Timeout(externalAuthorization.AuthorizationResponseTimeout), |
There was a problem hiding this comment.
The httpproxy.spec.virtualhost.authorization.responseTimeout parameter is optional in our configuration, and envoy.Timeout() returns nil if the value is not set. However, HttpUri requires a defined value.
For gRPC, the default value is documented as infinite. We should apply the same setting by using 0, as leaving the field empty causes an error.
|
@therealak12 I did some experiments related to my previous comments. You are free to use any of this work: snapp-incubator/contour@http-ext-authz...Nordix:contour:http-based-ext-authz |
|
The Contour project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to the #contour channel in the Kubernetes Slack |
Signed-off-by: therealak12 <ak12hastam@gmail.com>
|
Hi, thank you for your review and the helpful suggestions. Apologies for the delay. Due to the recent war affecting my country, I was unable to continue working on this PR for some time. Now that the situation has stabilized, I applied the requested changes. Please take another look when you have a chance. |
Envoy external authorization filter supports HTTP and GRPC servers. Contour only supports configuring gRPC services at the moment. The PR adds support for HTTP ext-authz services.
We've been using this in production for >1 year.
Closes #6509