Support for different authorization/contextualization mechanisms for the same URLs having different authentication contexts #521
Labels
feature
Used for new features
Milestone
Preflight checklist
Describe the background of your feature request
The actual background are setups, which require different authentication mechanisms for the same URLs, even using same HTTP methods.
Imagine you have a service, which exposes an endpoint, e.g.
/foo/bar
and the required behavior is as follows:That can be actually defined more or less by the following rule pipeline:
The problem is however, that if the request is anonymous, the
subscription_plan
will fail, as the corresponding backend will not find a user with ID set toanonymous
(or whatever is set in the configuration of theanonymous
authenticator), as long as it does not handle such specific cases. This is however usually not the case and if it is, it introduces a coupling between heimdall and that backend.This problem becomes even more worse, if the resource does not only support reading requests (via HTTP GET), but also implements resource updates (e.g. via HTTP PUT or POST as described in the example above) and the endpoint requires different contextual or authorization mechanisms for reading and writing requests. As of today, there is no way to address such scenarios with heimdall as the only matching criteria is the url of the endpoint. Here contextualizers and authorizers can only used, if the corresponding backend can deal with anonymous requests.
Describe your idea
There are multiple options on how to support such scenarios with heimdall, respectively what needs to be implemented to support them:
Extend the matching functionality to not only support the URLs, but also the HTTP method and headers cookies. This would allow definition of distinct rules for the different use cases supported by the endpoint. So the rule definition given in the previous section would be split into three rules as shown below:
With that approach there is a complete freedom on how to make use of authorizers and contetualizers for the upstream services.
The following table summarizes the pros and cons of this alternative.
method
property on the rule level if method matching is used.Enable conditional execution of rule pipeline mechanisms by introducing an
if
property, which would evaluate CEL conditions and only if the condition is true, let the mechanism execute. This way, we still have one rule, but it would look like follows:This approach is by far less verbose compared to the previous one, might however lead to pretty long and hard to test/maintain rules compared to the approach 1 and might change the semantic of the response for HTTP methods (see
deny_all
authorizer above, which would lead to403 Forbidden
instead of405 Method not Allowed
). So maybe there will be a need to have response code overrides for errors on the level of the error handlers in addition. It gives however complete freedom on how to make use of authorizers and contetualizers for the upstream services as well.The following table summarizes the pros and cons of this alternative.
Extend the implementation of contextualizers to enable customization of response code verification. As of now the implementation expects only 200 codes. All other response codes are treated as error, leading to the execution of the error pipeline. This might be the simplest possible implementation, which would allow use cases as described in the background section, but is by far less powerful compared to the previous two, so that there will be still situations, which would not be supported.
Are there any workarounds or alternatives?
Don't use contextualizers and authorizers in heimdall in such cases and let the upstream services implement the corresponding functionality. This is however something, heimdall wants the upstream services to help with and resolve the corresponding dependencies. If the upstream service has to deal with that complexity anyway (because heimdall does not support all such cases), why using contextualizers and authorizers at all?
Alternatively let the services used by contextualizers and authorizers cope with anonymous requests, respectively user data, which them usually don't know. Can work. Might be problematic in many cases as written in the background section.
Version
v0.6.1-alpha
Additional Context
No response
The text was updated successfully, but these errors were encountered: