You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "adutra (via GitHub)" <gi...@apache.org> on 2025/01/17 23:13:13 UTC

[I] Rethink order of JAX-RS filters in Polaris [polaris]

adutra opened a new issue, #819:
URL: https://github.com/apache/polaris/issues/819

   ### Is your feature request related to a problem? Please describe.
   
   Currently Polaris has a number of filters, some of them being "regular" JAX-RS filters, some others being Vert.x route filters:
   
   | Filter | Type | Priority |
   | ------|-----| --------|
   | `org.apache.polaris.service.quarkus.logging.QuarkusLoggingMDCFilter` | Vert.x | `RouteFilter.DEFAULT_PRIORITY + 100` (110) |
   | `org.apache.polaris.service.quarkus.tracing.QuarkusTracingFilter` | Vert.x | `QuarkusLoggingMDCFilter.PRIORITY - 1` (109) |
   | `org.apache.polaris.service.auth.PolarisPrincipalAuthenticatorFilter` | JAX-RS | `Piorities.AUTHENTICATION ` (1000) |
   | `org.apache.polaris.service.auth.PolarisPrincipalRolesProviderFilter`  | JAX-RS | `Piorities.AUTHENTICATION  + 1` (1001) |
   | `org.apache.polaris.service.ratelimiter.RateLimiterFilter` | JAX-RS | `Piorities.USER ` (5000) |
   
   The above has a number of issues:
   
   First off, from my experience, Vert.x filters always execute first, regardless of priorities (also, Vert.x priorities are inverted compared to JAX-RS ones). This induces a wrong order of execution:
   
   1. `QuarkusLoggingMDCFilter`
   2. `QuarkusTracingFilter`
   3. `PolarisPrincipalAuthenticatorFilter`
   4. `PolarisPrincipalRolesProviderFilter`
   5. `RateLimiterFilter`
   
   Secondly, we ideally need a filter to verify realm IDs. For two reasons:
   
   1. The default realm ID resolver throws an exception if the realm is unknown. That's fine, but the error at that stage, since the resolver is a CDI bean, is translated into HTTP 500. If we want to return something more meaningful, like HTTP 403, we'd need to do that in a filter.  Related to this: #805.
   2. Also, `QuarkusLoggingMDCFilter` and `QuarkusTracingFilter` both need the realm ID. So they should execute after the realm ID filter.
   
   ### Describe the solution you'd like
   
   I think we need to reorder the filters as below:
   
   1. `RealmIdFilter`(to be created)
   2. `QuarkusLoggingMDCFilter`
   3. `QuarkusTracingFilter`
   4. `PolarisPrincipalAuthenticatorFilter`
   5. `PolarisPrincipalRolesProviderFilter`
   6. `RateLimiterFilter`
   
   Or maybe as below if we want the authenticator to kick in first:
   
   1. `PolarisPrincipalAuthenticatorFilter`
   2. `RealmIdFilter`(to be created)
   3. `PolarisPrincipalRolesProviderFilter`
   4. `QuarkusLoggingMDCFilter`
   5. `QuarkusTracingFilter`
   6. `RateLimiterFilter`
   
   
   ### Describe alternatives you've considered
   
   _No response_
   
   ### Additional context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Rethink order of JAX-RS filters in Polaris [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on issue #819:
URL: https://github.com/apache/polaris/issues/819#issuecomment-2609569562

   @collado-mike `RealmContextResolver` wasn't deleted, but renamed. Its default implementation is here now:
   
   https://github.com/apache/polaris/blob/390f1fa57bb1af24a21aa95fdbff49a46e31add7/service/common/src/main/java/org/apache/polaris/service/context/DefaultRealmIdResolver.java#L29
   
   > The RealmIdFilter or RealmContextResolver must be executed prior to authentication - a caller can only be authenticated within a realm.
   
   Thanks for confirming, that was my conclusion as well.
   
   For the record, it was already being resolved prior to authentication, but with one annoying difference: the realm was being resolved as part of CDI resolution, see here:
   
   https://github.com/apache/polaris/blob/df538b3928d259e9ec0339d05b12ef6c73b55a15/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java#L101-L110
   
   While this works well in the happy case (the realm can be resolved), it throws HTTP 500 in the unhappy case of wrong realm.
   
   Hence the changes in this PR: realm resolution is moved to a pre-auth filter:
   
   https://github.com/apache/polaris/blob/9c454942cc12de03ed820dc324c90b7ff4e38341/service/common/src/main/java/org/apache/polaris/service/context/RealmIdFilter.java#L48-L56
   
   The filter resolves the realm, then sets it as a request property. Then CDI now simply reads the realm ID from the request property and produces the request-scoped bean that will be injected everywhere:
   
   https://github.com/apache/polaris/blob/9c454942cc12de03ed820dc324c90b7ff4e38341/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java#L101-L105
   
   Does that make sense?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Rethink order of JAX-RS filters in Polaris [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b closed issue #819: Rethink order of JAX-RS filters in Polaris
URL: https://github.com/apache/polaris/issues/819


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Rethink order of JAX-RS filters in Polaris [polaris]

Posted by "collado-mike (via GitHub)" <gi...@apache.org>.
collado-mike commented on issue #819:
URL: https://github.com/apache/polaris/issues/819#issuecomment-2608427119

   I guess I have missed the commit where `RealmContextResolver` has been deleted? That was the intention of that filter in the original code base.
   
   The `RealmIdFilter` or `RealmContextResolver` must be executed prior to authentication - a caller can only be authenticated within a realm. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org