coupergateway / couper

Couper is a lightweight API gateway designed to support developers in building and operating API-driven Web projects
https://couper.io
MIT License
87 stars 15 forks source link

let JWT validation call token instrospection #632

Open johakoch opened 2 years ago

johakoch commented 2 years ago

Use cases:

This could be achieved by making the JWT validator call the token introspection endpoint at the authorization server.

OAuth2 Token Introspection: RFC 7662

Proposed new attributes for jwt block (or for a nested introspection block):

    introspection_endpoint = ""
    introspection_endpoint_auth_method = "" # see values for token_endpoint_auth_method
    client_id = ""                          # for authenticating at introspection_endpoint
    client_secret = ""                      # for authenticating at introspection_endpoint
    introspection_mode = "always|interval"
    # for introspection_mode = "interval":
    introspection_interval = "10m"          # max: exp - unixtime()

There are two introspection_modes:

filex commented 2 years ago

Do we need to store local data in Couper for this? E.g. a map of tokens and last check? Or a list of revoked tokens?

johakoch commented 2 years ago

Do we need to store local data in Couper for this? E.g. a map of tokens and last check? Or a list of revoked tokens?

In my proposal, in introspection_mode "interval", the response to the introspection request (containing the active property) is cached for a specified ttl (introspection_interval). The cache key could be e.g. the token itself, or a combination of iss and jti (string identifier for the token) if available.

Additionally, revoked tokens (or, again, some identifier) could be stored, to further reduce traffic.

johakoch commented 1 year ago

If token is JWT:

In this case, it would be sufficient to cache only the introspection response's active property.


If token is opaque:

In this case, the whole introspection response has to be cached.

johakoch commented 1 year ago

Alternative configuration:


jwt "..." {
  # ...
  introspection {
    endpoint = "..." # the introspection endpoint at the authorization server
    backend = "..."  # or backend {}; for introspection request
    ttl = "..."      # duration; positive value: cache introspection response, otherwise do not cache
  }
}
johakoch commented 1 year ago

Should this be a beta feature (beta_introspection block)? Is attribute name endpoint ok? Or should it be introspection_endpoint (parallel to token_endpoint in oauth, but maybe redundant here)?

johakoch commented 1 year ago

Token introspection is offered by e.g.

johakoch commented 1 year ago

VSCode: https://github.com/avenga/couper-vscode/pull/132