Skip to content

Add configurable expiry for UC access tokens issued by token exchange - #1689

Merged
yili-db merged 6 commits into
unitycatalog:mainfrom
s-maling-celonis:feat/access-token-expiry
Jul 27, 2026
Merged

yili-db merged 6 commits into
unitycatalog:mainfrom
s-maling-celonis:feat/access-token-expiry

Conversation

@s-maling-celonis

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

Copy link
Copy Markdown
Contributor

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

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

@@ -28,6 +28,7 @@ server.audiences=

# D-Days H-Hours M-Minutes S-Seconds (P5D = 5 days,PT5H = 5 hours, PT5M = 5 minutes, PT5S = 5 seconds)
server.cookie-timeout=P5D

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.

The cookie still expires in 5 days, but the JWT inside expires in 1 day? A cookie with expired token is useless for the remaining 4 days, right?

I suggest changing the cookie timeout to be: min(cookie_timeout, access_token_timeout) to avoid sending out cookie that can outlast the access token.

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.

Done in f9f1826. Added ServerProperties.getEffectiveCookieTimeout() which returns min(server.cookie-timeout, server.access-token-timeout), and AuthService now uses that when setting the UC_TOKEN cookie via ext=cookie. With the current defaults (P5D / PT24H), the cookie max-age is capped to 24h. Added testEffectiveCookieTimeout to cover both directions of the min.

@yili-db

yili-db commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Please call out the behavior change of changing from never expiring token to 1 day.

.isEqualTo("urn:ietf:params:oauth:token-type:access_token");
assertThat(body.get("token_type").asText()).isEqualTo("Bearer");
assertThat(body.get("expires_in").asLong()).isEqualTo(Duration.parse("PT24H").getSeconds());
assertThat(JWT.decode(body.get("access_token").asText()).getExpiresAt()).isNotNull();

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.

should validate that the expiration is expected iat + ttl. If changing wall clock is an issue, You can use a time range to validate.

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.

Done in d7e8d1a. testTokenExchangeWithCorrectIssuerAndAudience now decodes the access token and asserts exp is close to iat + PT24H (within 2 seconds), in addition to checking expires_in matches the configured TTL.

.isEqualTo("urn:ietf:params:oauth:token-type:access_token");
assertThat(body.get("token_type").asText()).isEqualTo("Bearer");
assertThat(body.get("expires_in").asLong()).isEqualTo(Duration.parse("PT24H").getSeconds());
assertThat(JWT.decode(body.get("access_token").asText()).getExpiresAt()).isNotNull();

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.

Similar to // Logout without cookie should return 401 (no credentials provided) can you also try to send any request with an expired token to make sure the expiration does work?

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.

Done in 6abf0c7. Added testExpiredAccessTokenIsRejected, which sends a signed UC access token with a past exp claim as a UC_TOKEN cookie to /auth/logout and asserts the server returns 401.

@s-maling-celonis

Copy link
Copy Markdown
Contributor Author

Documented in aaf319e and the updated PR description. UC access tokens now expire after 24 hours by default (server.access-token-timeout=PT24H); previously they had no exp claim. Config comments, Helm auth.accessTokenTimeout, and the PR "Behavior change" section describe the migration impact and how to tune the timeout.

@s-maling-celonis
s-maling-celonis force-pushed the feat/access-token-expiry branch from 0d0e1b3 to 7fa1ece Compare July 21, 2026 07:57
s-maling-celonis and others added 6 commits July 21, 2026 09:58
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]>
Signed-off-by: s-maling-celonis <[email protected]>
When ext=cookie is used, set cookie max-age to min(cookie_timeout,
access_token_timeout) so the browser does not keep sending a cookie
after the JWT inside it has expired.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
Validate expires_in and JWT exp against iat + PT24H with a small
clock-skew tolerance instead of only checking that exp is present.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
Send a signed access token with a past exp claim to a protected
endpoint and assert the server returns 401 Unauthorized.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
Clarify that UC access tokens now expire after 24 hours by default,
add server.properties guidance for migration, and wire
server.access-token-timeout through auth.accessTokenTimeout in Helm.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
Drop the previously/no-exp-claim comments from server.properties and
Helm values; the behavior change remains documented in the PR description.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: s-maling-celonis <[email protected]>
@s-maling-celonis
s-maling-celonis force-pushed the feat/access-token-expiry branch from 7fa1ece to f6ab603 Compare July 21, 2026 07:58
@s-maling-celonis
s-maling-celonis requested a review from yili-db July 21, 2026 08:00

@yili-db yili-db left a comment

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.

Nice and clean work. Thank you!

@yili-db

yili-db commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

@tdas Please take a look.

@tdas tdas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. the fixes on @yili-db comment looks good too. thanks for those fixes.

@yili-db
yili-db merged commit 163045b into unitycatalog:main Jul 27, 2026
14 of 16 checks passed
yili-db pushed a commit that referenced this pull request Oct 27, 2026
## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2019/files) to
review incremental changes.
-
[**stack/ep3-helm-ci**](#2019)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2019/files)]
← _this PR_
-
[stack/ep3-helm-release](#2020)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2020/files/9090e88439087610b7240d3dd89c8464e6ac83d9..573a422bfdfcc8aa1e144e1a8d28c19879ed5b14)]
-
[stack/ep3-helm-docs](#2021)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2021/files/573a422bfdfcc8aa1e144e1a8d28c19879ed5b14..936a12fac01b260d4d3fa97706943c076c8ac757)]

---------
**Description of changes**

The UI moved from yarn to bun in #1732, but the Helm chart still starts
it with `yarn start`. Yarn 1 refuses to run in a project whose
`package.json` declares `packageManager: bun@…`. So with any UI image
built from today's `ui/`, the UI pod crash-loops and `helm install
--wait` times out.

This PR:

- starts the UI with `bun run start` when the image has bun, and with
`yarn start` otherwise. The UI stays on by default, as on main;
- adds a `helm test` hook that checks the server API, the UI page and
the UI's `/api` proxy. Its image is set by `test.image` (with
`test.imagePullSecrets`), so a mirrored registry can run it;
- adds a **Helm Chart Tests** workflow for pull requests that touch
`helm/`, `ui/` or the `Dockerfile`. It checks that the chart README is
current (helm-docs), runs `ct lint`, installs the chart on kind with
server and UI images built from the PR, and runs `helm test`;
- regenerates the chart README, which was missing the values added in
#1689 and #1690, and fixes two yamllint errors in `values.yaml`. The
yamllint fixes are whitespace only, and the parsed values are identical.

UI images built from today's `ui/` now start with bun. The published
`unitycatalog-ui:main` image (May 2025) predates bun and has only yarn,
so it keeps starting with yarn, and a default install or `helm upgrade`
from main keeps its UI. bun is checked first, because a bun image also
has yarn (from `node:18`), but yarn refuses to run there. Once each
release publishes a bun-based UI image (#2020, #2021), the yarn branch
can go.

**Tests:** on a local kind cluster, the unchanged chart crash-loops the
UI as described above. With this PR, the install is ready in about 30
seconds and `helm test` passes. CI installs the chart with its default
values, with server and UI images built from the PR. This stack changes
no JVM code, and the full `build/sbt test` suite passes locally.

<details><summary><b>📐 Design notes &amp; details</b></summary>

**Repro of the bug** (kind with Kubernetes 1.32, server image `v0.7.0`,
UI image built from `main`):

```
error This project's package.json defines "packageManager": "yarn@[email protected]". However the current global version of Yarn is 1.22.22.
```

With `bun run start`, the following all returned 200 through a
port-forward: the UI page, the server API, a read through the UI's
`/api` proxy, and creating and deleting a catalog and a schema through
that proxy.

**Why this workflow builds Docker images.** #1420 disabled the image
*publishing* workflows to protect their Docker Hub secrets. This
workflow builds images only to load them into a throwaway kind cluster:

- it pushes nothing and uses no secrets;
- `permissions: contents: read` and `persist-credentials: false`;
- it runs on `pull_request`, not `pull_request_target`;
- actions are pinned to commit SHAs and the helm-docs image to a digest;
- zizmor reports no findings for it.

**What the test checks.**

- The UI dev server enables its host check whenever it proxies the API.
In that mode it accepts `localhost`, `*.localhost` and IP addresses, and
rejects other hostnames such as the Service name (see #753). The test
sends `Host: localhost`, as a browser on `kubectl port-forward` does.
Ingress and HTTPRoute mode turn the proxy off, and the test then skips
the proxy check.
- With `auth.enabled`, the test has no token, so it checks only the UI
page. With auth on and the UI off, there is nothing to check, and no
test pod is rendered.
- A failed check prints which check failed, and CI runs `helm test
--logs` so the output reaches the job log. The test pod is kept after it
passes and replaced on the next run, because `--logs` reads it after the
test finishes.
- The test checks that the UI is served, not that the UI compiles: the
dev server serves `index.html` even after a compile error.
- Ingress and HTTPRoute installs aren't exercised, because they need a
controller in kind.

**Local limits.** This machine can't build the server image from source
(old Docker and kernel), so locally I ran the same steps with the
released `v0.7.0` server image. The first from-source build in this
workflow is this PR's CI run.

Tools: Helm 3.20.0, chart-testing-action 2.9.0 (ct 3.15.0), kind-action
1.15.1, helm-docs 1.14.2.

**Measured results** (kind, chart from this PR, UI on, images built from
the PR):

| Request | Status |
|---|---|
| server `GET /api/2.1/unity-catalog/catalogs` | 200 |
| UI `GET /` with `Host: localhost:3000` | 200, UI page |
| UI `GET /` with `Host: uc.example.com` | 200, but the body is `Invalid
Host header` (the dev server's rejection page, see #753) |
| through the UI: `GET /api/2.1/unity-catalog/catalogs` | 200 |
| through the UI: `POST /catalogs {"name": "ep3"}` | 200 |
| through the UI: the same `POST` again | 400 (already exists) |
| through the UI: `GET /catalogs/missing` | 404 |
| through the UI: `DELETE /catalogs/ep3` | 200 |
| unchanged chart (`yarn start`) | UI pod in CrashLoopBackOff; `helm
install --wait` times out |

**Security review: building images in CI again.** #1420 turned off the
workflows that built and pushed images, because they held Docker Hub
secrets. This workflow builds images again, for testing only. I reviewed
it, and also ran GLM 5.3 and Claude Opus reviews; every point below was
checked against the files, the actions at their pinned commits, and a CI
run.

*If a container in this job is compromised:*

| Where the bad code runs | What it can do |
|---|---|
| inside `docker build` (a base image, or an npm, Maven, apk or apt
package) | change the image under test; it gets no token and no secret |
| inside a kind pod (a chart helper image) | the same, unless it escapes
the pod |
| on the runner (helm, uv, ct, kind, helm-docs, or an escape from the
privileged kind node) | control this job: a read-only `GITHUB_TOKEN`, no
secrets, no way to push images, charts or code; it can make the test
pass or fail wrongly |

The one way out of the job was the GitHub Actions cache. A job running
on `main` writes caches that other workflows on `main` restore,
including the sbt and bun caches and `ai-review.yml`, which holds
secrets. So the workflow runs **only on pull requests**: a pull
request's caches are scoped to that pull request, and `main` never reads
them. A tampered helm-docs image could edit chart files before the
install, so the check now fails on any change under `helm/`, not only
`README.md`.

*Docker Hub credentials:* this workflow can't reach them under any
trigger. GitHub gives a job only the secrets it names, and this workflow
names none; pull requests from forks get no secrets at all. Before
anyone turns the old image workflows back on: they log in to Docker Hub
and use the `type=gha` build cache in the same job, so a poisoned cache
could reach the published images.

*Pinned inputs:* actions by commit SHA (`actions/checkout` at v7.0.1);
helm-docs, the Dockerfiles' base images and syntax frontend, the `helm
test` image and the kind node image
(`kindest/node:v1.37.0@sha256:a1ed…`) by digest; kind v0.33.0, kubectl
v1.37.1, helm v3.20.0 and uv 0.13.1 by version; the UI's npm packages by
`bun.lock`. The chart's other helper images still use `latest` here;
#2020 pins them. Not pinned, and pre-existing: `apk add bash` and
`apt-get install jq` during the image builds and `apk add` in the config
init container (signed packages, but versions move), and sbt's Maven
downloads and launcher jar (no hash lock).

*Follow-ups (not in this stack):* zizmor checks for all workflows.
Separately, the existing cache exposure this workflow avoids stays as it
is: `unit-tests.yml`, `lint-check.yml` and `cross-spark-build.yml` write
caches on `main`, and `ai-review.yml` restores caches while holding
secrets. zizmor's cache-poisoning audit doesn't flag the `ai-review.yml`
case (0 findings when run on it).

</details>

**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [ ] If there is a related issue, make sure it is linked to this PR.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [ ] If you've added or modified a feature, documentation in `docs` is
updated

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[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.

3 participants