Skip to content

Wildcard issuer/audience matching and subject-token principal resolution - #1661

Closed
s-maling-celonis wants to merge 6 commits into
unitycatalog:mainfrom
s-maling-celonis:feat/wildcard-audiences
Closed

s-maling-celonis wants to merge 6 commits into
unitycatalog:mainfrom
s-maling-celonis:feat/wildcard-audiences

Conversation

@s-maling-celonis

@s-maling-celonis s-maling-celonis commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extends token exchange for multi-tenant OAuth deployments with four related changes:

Wildcard server.allowed-issuers (supersedes #1657)

  • Add IssuerAllowlist for single-DNS-label wildcard issuer patterns (e.g. https://*.dev.example.com)
  • Reuse the same matcher in AudienceAllowlist

Wildcard server.audiences

  • Validate JWT aud after signature verification (any token audience may match any configured entry)
  • Support server.audiences=* alone to disable audience checks for dynamic OAuth client UUID audiences

Subject-token principal resolution (service principals)

UC resolves the principal from the subject token on POST /auth/tokens — no OAuth client credentials on the UC request:

  1. id_token (CLI/browser): email claim or sub → getUserByEmail, then externalId fallback via azp/non-URL aud
  2. access_token (M2M): if no email claim, externalId via azp/non-URL aud first, then sub; otherwise same as id_token

The issued UC access token always uses the resolved user's email as sub (for grants/authorization).

Additional behavior:

  • Audience bypass: signed subject tokens whose azp or non-URL aud matches a registered UC user externalId are accepted even when the client UUID is not in server.audiences
  • Unique index on uc_users.external_id (multiple NULL values still allowed)
  • Prefer the externalId flow over server.audiences=* for per-tenant service principals

UC access token expiry

  • Add server.access-token-timeout (default PT24H) for access tokens issued by token exchange
  • Set JWT exp via withExpiresAt in SecurityContext.createAccessToken
  • Return expires_in in the /auth/tokens response so clients can cache and refresh correctly

Chunked JSON payload authorization

UnityAccessDecorator previously ran beforeRequest on every peekData chunk, before the full JSON body was buffered and parsed. For chunked POST requests (e.g. POST /schemas), authorization could run on a partial payload and fail to resolve payload-derived resource keys such as catalog_name, causing:

Cannot invoke "java.util.UUID.toString()" because "resource" is null

This fix:

  • Defers authorization until processPeekData has successfully parsed the complete JSON payload
  • Checks the accumulated payload buffer (not the current chunk) for JSON completion

Example multi-tenant configuration:

server.allowed-issuers=https://*.dev.example.com
server.audiences=unity-catalog-local,*.dev.example.com
server.access-token-timeout=PT24H

Bootstrap UC users with email for grants and externalId = OAuth client_id.

@s-maling-celonis
s-maling-celonis force-pushed the feat/wildcard-audiences branch from e094ac2 to 31dc6da Compare July 8, 2026 11:02
@s-maling-celonis s-maling-celonis changed the title Support wildcard patterns in server.audiences Wildcard issuer/audience matching and subject-token principal resolution Jul 8, 2026
s-maling-celonis and others added 4 commits July 8, 2026 13:04
Mirror issuer-style wildcard matching for JWT aud claims during token
exchange, including exact and single-label wildcard patterns. A lone *
disables audience validation for dynamic OAuth client UUID audiences.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
Allow issuer allowlist entries such as https://*.dev.example.com so UC can
accept tokens from any tenant on a realm without listing each issuer explicitly.
Reuse the same wildcard matcher for audience validation via AudienceAllowlist.

Signed-off-by: s-maling-celonis <[email protected]>
Co-authored-by: Cursor <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
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]>
@s-maling-celonis
s-maling-celonis force-pushed the feat/wildcard-audiences branch from 31dc6da to 3a75f32 Compare July 8, 2026 11:05
UC access tokens previously had no exp claim. Add server.access-token-timeout
(default PT24H), set JWT expiration in SecurityContext, and return expires_in
from the token exchange response.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
Co-authored-by: Cursor <[email protected]>
@s-maling-celonis
s-maling-celonis force-pushed the feat/wildcard-audiences branch from 51cd13e to dec19d4 Compare July 8, 2026 14:01
Defer beforeRequest authorization until processPeekData has buffered and
successfully parsed the full JSON payload, so payload-derived resource keys
such as catalog_name are available before SpEL evaluation. Check the
accumulated payload buffer for completion instead of the current chunk.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
Co-authored-by: Cursor <[email protected]>
@s-maling-celonis
s-maling-celonis force-pushed the feat/wildcard-audiences branch from e50e266 to 520bd14 Compare July 14, 2026 18:13
peekDataHandler.processPeekData(data);
Map<SecurableType, UUID> resourceIds = mapResourceKeys(resourceKeys, nonResourceValues);
evaluateAction.beforeRequest(principal, expression, resourceIds, nonResourceValues);
if (peekDataHandler.processPeekData(data)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are aware of this. But adding back this if alone will bring back the auth skipping vulnerability. processPeekData could always return false for a valid request.
I am revamping #1494 to fix it.
Can you revert these 3 lines for now please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, i will be closing this PR anyway in favor of the 3 new independent changes. Wrt. this change, i think we can just manually apply the changes from the linked PR onto our fork.

@yili-db

yili-db commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

This is valuable work, but the PR bundles several independent changes on the auth path. Since these are all security-sensitive, each needs to be reviewed carefully on its own — bundled together it's hard to reason about any one of them, and they get tied to the same merge. Can we split it into different PRs?

Rough breakdown, in dependency order:

  1. Access-token expiry (server.access-token-timeout, withExpiresAt, expires_in). Small and self-contained.

  2. Wildcard issuer/audience matching (IssuerAllowlist, AudienceAllowlist, audiences=* handling).

  3. Subject-token principal resolution (TokenExchangePrincipalResolver, externalId lookup + unique constraint, audience-bypass-via-externalId). The most sensitive part — it relaxes audience binding during signature verification and accepts cross-audience tokens for registered clients, so it needs its own focused review and sign-off. Depends on (2).

This lets the expiry and wildcard changes land quickly and keeps each PR focused.

Thank you!

@s-maling-celonis

Copy link
Copy Markdown
Contributor Author

Closing in favor of three focused PRs (per review feedback to split security-sensitive auth changes):

  1. Access token expiry — Add configurable expiry for UC access tokens issued by token exchange #1689
  2. Wildcard issuer/audience matching — Support wildcard patterns in server.allowed-issuers and server.audiences #1690
  3. Subject-token principal resolution — Resolve token exchange principals from subject token claims #1691

The chunked JSON authorization fix (UnityAccessDecorator) is deferred until #1494 lands.

yili-db pushed a commit that referenced this pull request Jul 27, 2026
…#1689)

## Summary

Split from #1661 (PR 1 of 3).

UC access tokens previously had no `exp` claim. This adds:

- `server.access-token-timeout` (default `PT24H`)
- JWT expiration via `withExpiresAt` in
`SecurityContext.createAccessToken`
- `expires_in` in the `/auth/tokens` response so clients can cache and
refresh correctly
- Cookie max-age capped to `min(server.cookie-timeout,
server.access-token-timeout)` when `ext=cookie`
- Helm support via `auth.accessTokenTimeout`

## Behavior change

Previously, UC access tokens issued by `/auth/tokens` had **no `exp`
claim** and did not expire.

This PR changes the default lifetime to **24 hours**
(`server.access-token-timeout=PT24H`).

**Impact:**
- Clients must re-exchange tokens (or refresh using `expires_in`) at
least once per day with default settings.
- Deployments that relied on non-expiring tokens must set
`server.access-token-timeout` explicitly (for example to a longer
duration) if they need backward-compatible behavior during migration.

**Scope:** Applies only to UC access tokens issued by `/auth/tokens`
token exchange (`JwtTokenType.ACCESS`). The bootstrap admin token in
`etc/conf/token.txt` (service token, `JwtTokenType.SERVICE`) is
unchanged and still does not expire.

## Test plan

- [x] `sbt "server/testOnly
io.unitycatalog.server.service.AuthServiceTest,
io.unitycatalog.server.utils.ServerPropertiesTest"`
- [x] Token exchange returns `expires_in` matching configured timeout
- [x] Issued UC access token JWT includes valid `exp` claim (`exp ≈ iat
+ TTL`)
- [x] Expired access tokens are rejected with 401
- [x] Cookie max-age does not exceed access token lifetime

---------

Signed-off-by: s-maling-celonis <[email protected]>
Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants