ory / hydra

The most scalable and customizable OpenID Certified™ OpenID Connect and OAuth Provider on the market. Become an OpenID Connect and OAuth2 Provider over night. Broad support for related RFCs. Written in Go, cloud native, headless, API-first. Available as a service on Ory Network and for self-hosters.
https://www.ory.sh/?utm_source=github&utm_medium=banner&utm_campaign=hydra
Apache License 2.0
15.66k stars 1.5k forks source link

Support per-client configuration of token type (opaque/jwt) #3392

Closed sgal closed 1 year ago

sgal commented 1 year ago

Preflight checklist

Describe your problem

We have a login solution based on Hydra that serves both internal clients (meaning oauth2 clients) and external clients.

For internal clients, we have an existing codebase that is built around JWT tokens that is hard to migrate to opaque. These clients also use internal identifiers as subjects in access tokens.

For external clients, we would like to use the pairwise subjects feature and opaque tokens that come with it.

We also want to have Single Sign On support between internal/external clients.

Currently, Hydra only supports a global configuration of token types, which prevents us from enabling the pairwise subjects feature for external clients, while keeping internal clients unchanged.

Describe your ideal solution

It would be great to be able to configure token type per client, similar to how it is done with token TTL values. With that, our internal clients would stay on JWT tokens and internal identifiers as subjects, and we could also enable external clients with pairwise subjects and opaque tokens.

Workarounds or alternatives

  1. Switch all clients to opaque tokens and implement an opaque -> JWT translation layer for internal clients. This solution forces us to use a separate token issuer for JWT tokens.
  2. Migrate all clients to opaque tokens. This is a massive migration for us, with around 500 services involved and infrastructure not really built around introspection calls.

Version

2.x

Additional Context

No response

igorcavalcante commented 1 year ago

It's a very interesting matter, I am working on a oidc solution with a load fo 50M users and spikes of 30k full auth cylces persecond, do claim checks like expiration dates via introspection is something to be avoided.

aeneasr commented 1 year ago

There are two ways to address this from a client perspective:

  1. Have a per-client configuration for the resulting token type
  2. Add a parameter to the consent flow which decides which token type to send

I think the first option is easier to implement than the second option. Currently, we switch the token strategy based on the config here:

https://github.com/ory/hydra/blob/7599c82db261df6855501b5c9d653c3efa1afab6/fositex/token_strategy.go#L30-L34

If the requester

https://github.com/ory/hydra/blob/7599c82db261df6855501b5c9d653c3efa1afab6/fositex/token_strategy.go#L41

contains the client, we could potentially use that as an override for the strategy here

https://github.com/ory/hydra/blob/7599c82db261df6855501b5c9d653c3efa1afab6/fositex/token_strategy.go#L29-L35

However, I'm not sure how that would impact the subject identifier verification. Currently, validation seems to happen in these places:

https://github.com/ory/hydra/blob/7599c82db261df6855501b5c9d653c3efa1afab6/driver/config/provider.go#L225

https://github.com/ory/hydra/blob/7599c82db261df6855501b5c9d653c3efa1afab6/consent/strategy_default.go#L1018-L1034

So any change to this logic would require end-to-end tests to ensure that the behavior is correct.

sgal commented 1 year ago

I think option 1 would be more scalable for flows that do not use consent, like jwt-bearer. I'm not sure if pairwise support is needed there, seems like an extreme edge case. But token type would be great to have in that grant type.

aeneasr commented 1 year ago

The problem is that we need to validate for these edge cases, because otherwise the behavior is incorrect, which could potentially imply that we'll fail OpenID certification. So while it is an edge case, it has to be considered and properly handled :)

sgal commented 1 year ago

I think we're on the same page here. rfc7523 is only oAuth2 and it has no mention of pairwise or any other subject obfuscation, so would it break the OIDC certification if we skip pairwise there?

aeneasr commented 1 year ago

I'm not quite sure if I understand, in this feature request we would issue JWT access tokens for OAuth2 Clients that asks us to do so. That impacts all OAuth2 and OpenID Connect flows, which is we need to make sure that they behave according to spec.

We can also limit this feature to RFC7523 only, but I think we could solve this for the general use case "this client should get JWT access tokens".