-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: OAuth2/OIDC metadata discovery for jwt
authenticator
#1043
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1043 +/- ##
==========================================
+ Coverage 89.20% 89.65% +0.45%
==========================================
Files 246 249 +3
Lines 10367 10615 +248
==========================================
+ Hits 9248 9517 +269
+ Misses 881 862 -19
+ Partials 238 236 -2 ☔ View full report in Codecov by Sentry. |
109f946
to
64c8e74
Compare
be5c103
to
994fe27
Compare
…auth2 package; tests updated
Unfortunatelly, it took much longer then anticipated. One of the reasons - I'm still COVID positive. First of all - great job! Thank you for that! During the review, I encountered some challenges/issues which I would like to discuss with you in Discord:
To overcome some of the above said challenges, I allowed myself to do some refactoring. You can find that code in the https://github.com/dadrus/heimdall/tree/feature/oidc_autodiscovery branch. I wanted to talk about all that before pushing it to your PR. BTW, that PR is not complete as yours, it just refactors the discovery/metadata part to make it more future proof and simplify the code base. From the two authenticators, only the |
Joint Review Results:
|
…ttl property (breaking change)
…he changes of the endpoint API
…e changes of the endpoint API
I updated the title to wip again as there are still some opens to be discussed and implemented if there will be deviations from suggestions. Some tests are also still missing and I have not yet touched the documentation (waiting for the discussion of the opens) |
To have a better focused discussion, here only the opens using the same numbers as above (everything else is added/updated by the recent commits):
|
…ose coming from the metadata
As long as there is no feedback to the opens from #1043 (comment), the PR is feature complete. I personally would however like to change the default HTTP cache ttl for the |
jwt
authenticator
jwt
authenticatorjwt
authenticator
jwt
authenticatorjwt
authenticator
Related issue(s)
closes #619
Checklist
Description
As discussed in discord and also here, this PR extends the configuration of the
jwt
and theoauth2_introspection
authenticators as follows:Both have received a new
metadata_endpoint
property, which allows configuration of the [RFC 8414 - OAuth 2.0 Authorization Server Metadata] endpoint to discover the capabilities of the ouath2/OIDC server. With the RFC 8414 in place the OpenID Connect Discovery 1.0 specification is a OIDC specific profile for that RFC. Since the implementation doesn't make use of any OIDC specifics here, the chosen name adheres to OAuth2 definitions (actually even the referenced OIDC spec talks about metadata endpoint, even the document itself is named "discovery"). Either this new, or the already available endpoints must be configured.The old endpoints were updated to support templating of endpoint path parts, which becomes very handy in multi tenancy setups. The new
metadata_endpoint
supports that as well. Templating is only allowed for those endpoints, which are explicitly configured. E.g. if the newmetadata_endpoint
is configured, one can make use of templates (see examples below), but the usage of templates in endpoints retrieved from the OAuth2 server metadata is prohibited and will result in an error if template statements will appear in those. If one configures the old endpoints directly, templating is allowed.In both allowed cases a new object
TokenIssuer
is available to the template. In case of theoauth2_introspection
authenticator, there is however a limitation: the token issuer information is only available if the token format is a JWT.Here an example:
Given the external metadata endpoint of an auth server of the form
https://my-fancy-auth-server/realms/customer1/.well-known/openid-configuration
and the accest token in JWT format carrying theiss
claim with the valuehttps://my-fancy-auth-server/realms/customer1
, one can configure the endpoints like shown below to resolve the proper customer specific auth server profile:That way internally you would use the
https://auth-server.svc.cluster.local/realms/customer1/.well-known/openid-configuration
endpoint to get metadata information and verify the token. This does not only reduce network hops, but also allows for seamless dispatching to the proper customer specific oauth server profile/realm for the given token.Since the verification of the issuer reference can become a security concern, this PR introduces a new
disable_issuer_identifier_verification
property on the level ofmetadata_endpoint
, defaulting tofalse
and ensuring that value of theissuer
claim in the obtained metadata matches the URL patterns to communicate to the metadata endpoint as required by both, the RFC and the OIDC spec referenced above. The above example with the external and internal urls, would clearly violate such requirements, as long as the contents of the discovery document is not domain aware. In such cases, you would need to set thedisable_issuer_identifier_verification
property totrue
and hopefully implement other measures in you infrastructure preventing spoofing of the auth servers in place.BREAKING CHANGE
In addition, this PR introduces a breaking change related to http cache configuration and usage. Before this PR, all endpoints allowed enabling or disabling of http cache header usage via the
enable_http_cache
property. Since many server misbehave or just do not set the corresponding headers (see RFC 7234 for details), there is a need to support proper defaults to avoid useless bandwidth abuse. For that reason, the above said property has been refactored to an object, namedhttp_cache
, supporting now two properties:enabled
- which can be used to enable or disable the http cachedefault_ttl
- which allows setting http cache ttl if the server does not set any cache related headerThe defaults are context dependent. E.g. for the new
metadata_endpoint
, these aretrue
and5m
. In general, http caching is however disabled. Another place, where http caching plays a role is in the http endpoint provider to load rule sets from remote locations. Here the default is the enabled cache, but without default ttl.The following code snippet summarize the differences
feat: OAuth2 metadata discovery for
oauth2_introspection
authenticatorrefactor!: Endpoint specific HTTP cache settings refactored to allow cache ttl definition