-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Support configurable principal claim in JWT Realm Tokens #86533
Support configurable principal claim in JWT Realm Tokens #86533
Conversation
The JwtAuthenticationToken relied on the "sub" claim always existing because OIDC requires that ID tokens contain a sub, as does the spec for JWT format OAuth access tokens (RFC 9068). However, the may be cases where JWTs do not contain a "sub", so we instead consult an ordered list of "user id claims" that can be configured via the xpack.security.authc.jwt.userid_claims setting
…sticsearch into enhancement/jwt-realm-token-config
Hi @justincr-elastic, I've created a changelog YAML for you. |
…' into enhancement/jwt-realm-token-config
@elasticmachine update branch |
@elasticmachine update branch |
…' into enhancement/jwt-realm-token-config
…enhancement/jwt-realm-token-config
@elasticmachine update branch |
@elasticmachine update branch |
Pinging @elastic/es-security (Team:Security) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this, Justin! The logic looks good as far as I can tell, not being very familiar with JWT - but it seems aligned with the email threads and such on the topic.
I left a few comments, mostly cleanups and minor issues.
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/InternalRealms.java
Outdated
Show resolved
Hide resolved
...ecurity/src/main/java/org/elasticsearch/xpack/security/authc/jwt/JwtAuthenticationToken.java
Outdated
Show resolved
Hide resolved
...ecurity/src/main/java/org/elasticsearch/xpack/security/authc/jwt/JwtAuthenticationToken.java
Outdated
Show resolved
Hide resolved
...ecurity/src/main/java/org/elasticsearch/xpack/security/authc/jwt/JwtAuthenticationToken.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/jwt/JwtRealms.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/jwt/JwtRealm.java
Outdated
Show resolved
Hide resolved
…ecurity/authc/jwt/JwtAuthenticationToken.java Co-authored-by: Gordon Brown <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good work. LGTM!
Hi @evilwon22, LGTM is a commonly used acronym in Elasticsearch PRs which means Looks Good To Me. |
Hi @tvernum, Gordon reviewed and approved, but we would like you to take a second look at these changes too. Instead of calling it JwtAuthenticatorTokenFactory from your initial commit, I generalized the name to JwtRealms. In theory, it holds settings and code which are common for every JwtRealm. If you have a suggestion for a better name, let me know. Is it a Manager, Factory, Proxy, or something else? For now, it includes common code for parsing the principalClaimNames setting, and token object. However, it could be generalized to handle other things on behalf of all JwtRealm instances. It is not part of the scope of this PR, but I am wondering in future if this JwtRealms pattern of having a list of each JwtRealm could be utilized to improve performance of token calls. For example, if a JWT is missing claims in the principalClaimNames setting, JwtRealm.token() will execute N times the number of configured JwtRealms, and all of those calls will fail. There might be a way to remember if the first call to JwtRealm.token() failed, and skip the remaining N-1 calls to the same method. Another future idea is have the first call to JwtRealm.token() iterate over all of the JwtRealm objects, and use the principal claim name setting from each realm to decide which claim to use from a JWT for the realm order cache key, instead of duplicating those claim names in the new setting introduced by this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit surprised about where this PR ended up.
It contains additional validation checks (and realm tracking) that I don't think we need.
Overall, I'm OK with it, but I think the check that the realm's principal is in the principal_claims
is an obstacle.
...in/core/src/main/java/org/elasticsearch/xpack/core/security/authc/jwt/JwtRealmsSettings.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/jwt/JwtRealm.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/jwt/JwtRealms.java
Outdated
Show resolved
Hide resolved
@elasticmachine update branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
JWT Realm Tokens use hard-coded claims iss/aud/sub to compute token principal. The principal is used to cache realm order, so a previously successful realm can be bumped to the start of the realm list for that principal.
This works well for JWTs that are OIDC ID Tokens, because those 3 claims are mandatory. It does not work for OAuth 2.0 Access Tokens, which are typically opaque values. If those Access Tokens are JWTs, sometimes they use similar claims but not all of them. Access Tokens can be created via a number of different OAuth 2.0 flows, including but not limited to:
This PR will allow overriding JWT Realm Token parsing to override using principal=iss/aud/sub. Realm order cache keys are used outside of individual JWT realms, so it is not possible to configure this per realm. Multiple JWT realms can still be configured and work, but processing order might change at runtime depending on the override claims selected.