Repository navigation
Resolve token exchange principals from subject token claims - #1691
Conversation
e0698b6 to
69755b6
Compare
eb8f9a1 to
149de6c
Compare
There was a problem hiding this comment.
Yes — after switching issuance to the resolved principal email, that overload was unused. Removed in 909af1d.
| } | ||
|
|
||
| if (audiences.isEmpty()) { | ||
| if (tokenClientId.isPresent() |
There was a problem hiding this comment.
This means that for a matching azp/client_id tokens, audience allowlist is bypassed? May I ask why? It seems to defeat the purpose of audience allowlist.
If audience is truly unpredictable, the wildcard * audience can already disable it.
There was a problem hiding this comment.
Good catch — that bypass was intentional for dynamic client UUIDs, but you're right that it weakens the audience allowlist.
Fixed in 909af1d: audience validation now uses server.audiences only (aud match or *). azp / client_id are used only for principal resolution via externalId, not to skip the allowlist. Docs and tests updated accordingly (including a case that rejects a mismatched aud even when externalId matches).
| ErrorCode.UNAUTHENTICATED, "Token verification failed: " + e.getMessage(), e); | ||
| } | ||
|
|
||
| if (!serverProperties.isAudienceValidationDisabled() |
There was a problem hiding this comment.
The issuer validation remains in this function but audience validation moves to resolvePrincipalEmail?
Earlier in this PR you had audience validation conditional on if it's picking up email or id. Now that is no longer true. I think audience validation should be restored here to remain together with the other verification.
Then the resolvePrincipalEmail just do one thing: extract the email from a JWT token that is already validated and trusted.
There was a problem hiding this comment.
Done — audience validation is back in grantToken with issuer and signature checks. resolvePrincipalEmail only extracts the UC email from the already-validated token (bb8ccd59).
bb8ccd5 to
bd5287b
Compare
| } | ||
| } | ||
|
|
||
| return Optional.empty(); |
There was a problem hiding this comment.
[AI-assisted]
we should never eat this without logging. if the lookup fails, this turns a db/server issue into User not allowed, doesnt it? same below for email lookup.
future operational failures become indistinguishable from auth denial, and debugging token exchange gets much harder.
There was a problem hiding this comment.
Agreed — swallowing the lookup turned DB/server failures into User not allowed.
dc54e569 only treats NOT_FOUND as a miss. Any other BaseException or runtime error is logged and rethrown (email and externalId lookups share that path).
| * id_token} subjects, resolution order is email (or {@code sub}) then OAuth client id from {@code | ||
| * azp} or {@code client_id} mapped to {@code externalId}. For {@code access_token} subjects | ||
| * without an {@code email} claim, {@code externalId} is tried before {@code sub}. | ||
| */ |
There was a problem hiding this comment.
[AI-assisted]
blocker: why can an id_token fall back to azp/client_id? for browser tokens azp is the app, not the human, so this can issue a service principal token for the wrong user, right?
future cli/browser tokens that dont resolve by email could inherit grants from whichever UC user has externalId equal to the oauth client id.
There was a problem hiding this comment.
Yes — for an id_token, azp/client_id is the app, not the human.
dc54e569 drops that fallback: id_token resolves only from email/sub. azp/client_id → externalId remains for M2M access_token subjects. Covered by idTokenDoesNotResolveViaOauthClientId and testIdTokenExchangeDoesNotFallBackToExternalId.
Drop OAuth client credentials on POST /auth/tokens and map service principals via azp or non-URL aud to UC user externalId after email resolution fails. Co-authored-by: Cursor <[email protected]> Signed-off-by: s-maling-celonis <[email protected]>
Add a unique index on uc_users.external_id, prefer externalId over sub for access_token subjects without an email claim, and assert issued UC token sub in integration tests. Co-authored-by: Cursor <[email protected]> Signed-off-by: s-maling-celonis <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]> Co-authored-by: Cursor <[email protected]>
Stop falling back to aud when mapping subject tokens to UC externalId; aud remains for audience validation only. Update docs and tests. Signed-off-by: s-maling-celonis <[email protected]> Co-authored-by: Cursor <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]> Co-authored-by: Cursor <[email protected]>
Rename TokenExchangePrincipalResolver to TokenExchangeSubjectTokenHandler, deduplicate externalId user lookup, extract resolution order into a private strategy, and align AuthService javadoc with the handler behavior. Signed-off-by: s-maling-celonis <[email protected]> Co-authored-by: Cursor <[email protected]>
Keep aud validation independent of principal resolution so registered externalIds cannot skip server.audiences; remove unused DecodedJWT token helper. Co-authored-by: Cursor <[email protected]> Signed-off-by: s-maling-celonis <[email protected]>
…ecks. resolvePrincipalEmail now only maps an already-trusted JWT to a UC principal. Co-authored-by: Cursor <[email protected]> Signed-off-by: s-maling-celonis <[email protected]>
id_token exchange now resolves only from email/sub so a browser or CLI token cannot inherit a service principal via azp. User lookups log and rethrow non-NOT_FOUND failures instead of mapping them to User not allowed. Signed-off-by: s-maling-celonis <[email protected]> Co-authored-by: Cursor <[email protected]>
dc54e56 to
39c317f
Compare
Signed-off-by: s-maling-celonis <[email protected]> Co-authored-by: Cursor <[email protected]>
Summary
This PR contains subject-token principal resolution for
POST /auth/tokens.UC resolves the principal from the subject token — no OAuth client credentials on the UC request:
id_token(CLI/browser):emailclaim orsub→getUserByEmail, thenexternalIdfallback viaazporclient_idaccess_token(M2M): if noemailclaim,externalIdviaazp/client_idfirst, thensub; otherwise same asid_tokenThe issued UC access token always uses the resolved user's email as
sub(for grants/authorization).Additional behavior:
azporclient_idmatches a registered UC userexternalIdare accepted even when the client UUID is not inserver.audiencesuc_users.external_id(multipleNULLvalues still allowed)externalIdflow overserver.audiences=*for per-tenant service principalsBootstrap UC users with
emailfor grants andexternalId= OAuth client id (same value as the token'sazporclient_idclaim).Test plan
build/sbt "server/testOnly io.unitycatalog.server.service.TokenExchangePrincipalResolverTest io.unitycatalog.server.service.AuthServiceClientPrincipalTest io.unitycatalog.server.persist.UserRepositoryTest io.unitycatalog.server.service.AuthServiceTest io.unitycatalog.server.service.AuthServiceAllowlistTest"(24/24 passed locally)externalId(AuthServiceClientPrincipalTest)subclaim is the resolved user email (AuthServiceClientPrincipalTest)extractOAuthClientIdreadsazpthenclient_id(TokenExchangePrincipalResolverTest)