Skip to content

fix(auth): make JwtAuthFilter eager-401 with @PermitAll opt-out - #5404

Merged
Yicong-Huang merged 3 commits into
apache:mainfrom
Yicong-Huang:fix/jwt-eager-401
Jun 6, 2026
Merged

Yicong-Huang merged 3 commits into
apache:mainfrom
Yicong-Huang:fix/jwt-eager-401

Conversation

@Yicong-Huang

@Yicong-Huang Yicong-Huang commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Replaces the lazy pass-through behavior in common/auth/JwtAuthFilter with an RFC 6750 eager 401 + WWW-Authenticate challenge. Missing Authorization throws the bare Bearer challenge; an invalid token throws error="invalid_token" so a well-behaved client can distinguish "please log in" from "your stored token is invalid, discard it". Valid tokens populate a SecurityContext exactly as before.

Endpoints that need to serve anonymous traffic opt out with @PermitAll (JSR-250). This PR audits every resource method in the 5 microservices and applies @PermitAll where the lazy filter previously made it implicit:

  • 5x HealthCheckResource (liveness probes)
  • AccessControlResource /auth/* (routing proxy that authenticates itself via parseToken in the resource body)
  • LiteLLMProxyResource /chat/*, LiteLLMModelsResource /models (preserve current "gated only by guiWorkflowWorkspaceCopilotEnabled" behavior; whether these should require an authenticated user is a separate hardening decision)
  • DatasetResource: 5 endpoints with /public-* or /publicVersion paths, plus /{did}/cover and /{did}/cover-url which already take @Auth Optional[SessionUser] for opt-in user context

UnauthorizedException + UnauthorizedExceptionMapper carry the WWW-Authenticate challenge to the JAX-RS edge. The exception extends RuntimeException (not WebApplicationException) so unit tests can run without a Jersey RuntimeDelegate on the classpath, and is constructed with writableStackTrace=false to avoid fillInStackTrace cost on the auth hot path.

Any related issues, documentation, discussions?

Closes #4901. The earlier attempt at this fix, #4903, was reverted in #5025 because expired tokens from localStorage were piggy-backed onto /api/config/gui and broke the login page (#5026). PR #5392 has since fixed the frontend to drop expired tokens client-side (skipWhenExpired: true) and clear the session reactively on 401, so this PR can now ship safely.

How was this PR tested?

Added JwtAuthFilterSpec (header-missing / non-Bearer / invalid-token / valid-token; method- and class-level @PermitAll; resource-info-absent fallback) and UnauthorizedExceptionMapperSpec. Updated existing service specs to expect 401 (from the filter) instead of 403 (from the role filter) for missing-Authorization scenarios, and *ServiceRunSpec mocks verify the new UnauthorizedExceptionMapper registration. sbt Auth/test + 4 service specs all green; sbt scalafmtCheckAll clean. Manually tested end-to-end against a running config-service build with curl (missing / bad / valid tokens, @PermitAll healthcheck and pre-login) and in the browser with a forged JWT in localStorage to confirm the eager 401 path interoperates cleanly with PR #5392's 401 interceptor.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.7)

Replaces the lazy pass-through behavior in common/auth/JwtAuthFilter
with an RFC 6750 eager 401 + WWW-Authenticate challenge. Missing
Authorization throws the bare Bearer challenge; an invalid token throws
error="invalid_token" so a misbehaving client can distinguish "log in"
from "your token is gone bad" and discard it. Valid tokens populate a
SecurityContext exactly as before.

Endpoints that need to serve anonymous traffic opt out with @permitAll
(JSR-250). This PR audits the 5 microservices' resource methods and
applies @permitAll where the lazy filter previously made it implicit:

  - 5x HealthCheckResource (liveness probes)
  - AccessControlResource /auth/* (routing proxy that authenticates
    itself via parseToken in the resource body)
  - LiteLLMProxyResource /chat/*, LiteLLMModelsResource /models
    (preserve current "gated only by guiWorkflowWorkspaceCopilotEnabled"
    behavior; pure-anonymous access is a separate hardening decision)
  - DatasetResource: 5 endpoints with /public-* or /publicVersion paths,
    plus /{did}/cover and /{did}/cover-url which already take
    @Auth Optional[SessionUser] for opt-in user context

UnauthorizedException + UnauthorizedExceptionMapper carry the WWW-
Authenticate challenge to the JAX-RS edge. The exception extends
RuntimeException (not WebApplicationException) so unit tests can run
without a Jersey RuntimeDelegate on the classpath, and is constructed
with writableStackTrace=false to avoid fillInStackTrace cost on the
auth hot path.

The earlier attempt at this fix (apache#4903) was reverted in apache#5025 because
expired tokens from localStorage were piggy-backed onto /api/config/gui
and broke the login page (apache#5026). PR apache#5392 has since fixed the frontend
to drop expired tokens client-side (skipWhenExpired:true) and clear the
session reactively on 401, so this PR can now ship safely.

Existing test specs in the 5 services updated to expect 401 (from the
filter) instead of 403 (from the role filter) for missing-Authorization
scenarios, and the RunSpec mocks verify UnauthorizedExceptionMapper is
registered alongside the existing auth providers.

Closes apache#4901.
@github-actions github-actions Bot added fix common platform Non-amber Scala service paths labels Jun 6, 2026
@codecov-commenter

codecov-commenter commented Jun 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.67%. Comparing base (749798d) to head (01c641a).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...n/scala/org/apache/texera/auth/JwtAuthFilter.scala 82.14% 1 Missing and 4 partials ⚠️
...org/apache/texera/auth/UnauthorizedException.scala 66.66% 3 Missing ⚠️
.../scala/org/apache/texera/service/FileService.scala 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5404      +/-   ##
============================================
+ Coverage     51.63%   51.67%   +0.03%     
- Complexity     2422     2459      +37     
============================================
  Files          1057     1067      +10     
  Lines         41069    41485     +416     
  Branches       4415     4498      +83     
============================================
+ Hits          21206    21436     +230     
- Misses        18623    18796     +173     
- Partials       1240     1253      +13     
Flag Coverage Δ *Carryforward flag
access-control-service 42.22% <100.00%> (+0.32%) ⬆️
agent-service 33.76% <ø> (ø)
amber 52.26% <78.37%> (+0.01%) ⬆️
computing-unit-managing-service 1.65% <100.00%> (+0.27%) ⬆️
config-service 57.97% <100.00%> (+3.28%) ⬆️
file-service 38.32% <0.00%> (-0.11%) ⬇️
frontend 46.45% <ø> (+0.09%) ⬆️
pyamber 90.69% <ø> (ø)
python 90.84% <ø> (ø) Carriedforward from 1c688e1
workflow-compiling-service 58.69% <100.00%> (+0.30%) ⬆️

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Yicong-Huang Yicong-Huang changed the title fix(auth): make JwtAuthFilter eager-401 with @PermitAll opt-out (re-attempt of #4903) fix(auth): make JwtAuthFilter eager-401 with @PermitAll opt-out Jun 6, 2026
@Yicong-Huang
Yicong-Huang requested a review from xuang7 June 6, 2026 17:57
@Yicong-Huang Yicong-Huang added the release/v1.2 back porting to release/v1.2 label Jun 6, 2026

@bobbai00 bobbai00 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.

Manually tested most of the functionalities on the frontend. Works well

@Yicong-Huang

Copy link
Copy Markdown
Contributor Author

also this one @xuang7

The pre-existing CI workflow ran `Auth/jacoco` only when Auth had no
tests — the inline comment said so explicitly. JwtAuthFilterSpec and
the just-moved UnauthorizedExceptionMapperSpec now do have tests, so
add `Auth/jacoco` to the sbt invocation in build.yml so Codecov picks
the report up.

Moving UnauthorizedExceptionMapperSpec from access-control-service to
common/auth puts the spec next to the code it covers and lets
Auth/jacoco report on the mapper (jacoco only attributes coverage to
the module whose bytecode is being exercised). The move required
adding jersey-common as a test-scope dep so Response.status(...).build
finds a RuntimeDelegate at test time — the limitation the original
spec was placed in access-control-service to dodge.

Local Auth/jacoco now reports: JwtAuthFilter 100% line / 88% branch
on `filter` (1 generated branch missed), UnauthorizedException 100%,
UnauthorizedExceptionMapper 100%. The remaining bytecode-level branch
gaps in JwtAuthFilter are Scala compiler artifacts (lazy-val DCL,
short-circuit `m != null` paths Java reflection never hits) and not
worth chasing.
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file ci changes related to CI labels Jun 6, 2026
…ace clash

Moving UnauthorizedExceptionMapperSpec into common/auth required adding
jersey-common 3.0.16 (jakarta namespace) as a test-scope dep to bring
in a RuntimeDelegate provider. That worked locally but broke amber's
HuggingFaceModelResourceSpec on CI: sbt's cross-module classloader
cache mixed the jakarta artifact added here with the javax.ws.rs-api
2.1.1 that amber/HuggingFaceModelResource pulls in (via its
`import javax.ws.rs._` — that file is the one outlier in the codebase),
which surfaced as `LinkageError: ClassCastException` on Response.status
inside amber's tests.

Revert to leaving the spec next to access-control-service, where
dropwizard-testing already provides a RuntimeDelegate. We lose
attribution of the mapper's coverage to Auth's jacoco report, but the
mapper is 50 lines with one method — a small follow-up if we ever care.
`Auth/jacoco` stays in the CI workflow so JwtAuthFilterSpec coverage is
reported.

HuggingFaceModelResource's `javax.ws.rs._` imports are a real bug worth
fixing separately, but doing it inside an auth PR is scope creep.
@github-actions github-actions Bot removed the dependencies Pull requests that update a dependency file label Jun 6, 2026
Yicong-Huang added a commit that referenced this pull request Jun 6, 2026
### What changes were proposed in this PR?

Adds `api/config/pre-login` to `JwtModule.forRoot`'s `disallowedRoutes`
so the anonymous pre-login config fetch is no longer auto-attached with
`Authorization: Bearer …`. Before this change a stored JWT whose
signature can't be verified server-side (key rotation, manual tampering,
cross-deployment bleed) would make the eager `JwtAuthFilter` return 401
to the pre-login request, leaving `GuiConfigService` in an unrecoverable
error state and the login form blank until a manual reload.

### Any related issues, documentation, discussions?

Closes #5407. Companion to #5404 — without this change, the eager filter
introduced there exposes the regression described above.

### How was this PR tested?

Manually tested in the browser against #5404's backend with a forged JWT
in localStorage; confirmed `/api/config/pre-login` no longer carries
`Authorization` and the login form renders without a manual reload.

### Was this PR authored or co-authored using generative AI tooling?

(backported from commit 65aca57)

Generated-by: Claude Code (Opus 4.7)
@Yicong-Huang

Copy link
Copy Markdown
Contributor Author

coverage needs to be filled from individual services. will cover them later to keep this PR smaller.

@xuang7 xuang7 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!

@Yicong-Huang

Copy link
Copy Markdown
Contributor Author

thanks! merging now.

@Yicong-Huang
Yicong-Huang added this pull request to the merge queue Jun 6, 2026
Merged via the queue into apache:main with commit 5c2eaa2 Jun 6, 2026
40 checks passed
@Yicong-Huang
Yicong-Huang deleted the fix/jwt-eager-401 branch June 6, 2026 23:57
Yicong-Huang added a commit that referenced this pull request Jun 6, 2026
### What changes were proposed in this PR?

Replaces the lazy pass-through behavior in `common/auth/JwtAuthFilter`
with an RFC 6750 eager 401 + `WWW-Authenticate` challenge. Missing
`Authorization` throws the bare `Bearer` challenge; an invalid token
throws `error="invalid_token"` so a well-behaved client can distinguish
"please log in" from "your stored token is invalid, discard it". Valid
tokens populate a `SecurityContext` exactly as before.

Endpoints that need to serve anonymous traffic opt out with `@PermitAll`
(JSR-250). This PR audits every resource method in the 5 microservices
and applies `@PermitAll` where the lazy filter previously made it
implicit:

- 5x `HealthCheckResource` (liveness probes)
- `AccessControlResource` `/auth/*` (routing proxy that authenticates
itself via `parseToken` in the resource body)
- `LiteLLMProxyResource` `/chat/*`, `LiteLLMModelsResource` `/models`
(preserve current "gated only by `guiWorkflowWorkspaceCopilotEnabled`"
behavior; whether these should require an authenticated user is a
separate hardening decision)
- `DatasetResource`: 5 endpoints with `/public-*` or `/publicVersion`
paths, plus `/{did}/cover` and `/{did}/cover-url` which already take
`@Auth Optional[SessionUser]` for opt-in user context

`UnauthorizedException` + `UnauthorizedExceptionMapper` carry the
`WWW-Authenticate` challenge to the JAX-RS edge. The exception extends
`RuntimeException` (not `WebApplicationException`) so unit tests can run
without a Jersey `RuntimeDelegate` on the classpath, and is constructed
with `writableStackTrace=false` to avoid `fillInStackTrace` cost on the
auth hot path.

### Any related issues, documentation, discussions?

Closes #4901. The earlier attempt at this fix, #4903, was reverted in
#5025 because expired tokens from `localStorage` were piggy-backed onto
`/api/config/gui` and broke the login page (#5026). PR #5392 has since
fixed the frontend to drop expired tokens client-side (`skipWhenExpired:
true`) and clear the session reactively on 401, so this PR can now ship
safely.

### How was this PR tested?

Added `JwtAuthFilterSpec` (header-missing / non-Bearer / invalid-token /
valid-token; method- and class-level `@PermitAll`; resource-info-absent
fallback) and `UnauthorizedExceptionMapperSpec`. Updated existing
service specs to expect 401 (from the filter) instead of 403 (from the
role filter) for missing-Authorization scenarios, and `*ServiceRunSpec`
mocks verify the new `UnauthorizedExceptionMapper` registration. `sbt
Auth/test` + 4 service specs all green; `sbt scalafmtCheckAll` clean.
Manually tested end-to-end against a running `config-service` build with
`curl` (missing / bad / valid tokens, `@PermitAll` healthcheck and
pre-login) and in the browser with a forged JWT in localStorage to
confirm the eager 401 path interoperates cleanly with PR #5392's 401
interceptor.

### Was this PR authored or co-authored using generative AI tooling?

(backported from commit 5c2eaa2)

Generated-by: Claude Code (Opus 4.7)
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Backport to release/v1.2 succeeded as fb315d6. Run

bobbai00 pushed a commit to bobbai00/texera that referenced this pull request Jun 7, 2026
)

### What changes were proposed in this PR?

Adds `api/config/pre-login` to `JwtModule.forRoot`'s `disallowedRoutes`
so the anonymous pre-login config fetch is no longer auto-attached with
`Authorization: Bearer …`. Before this change a stored JWT whose
signature can't be verified server-side (key rotation, manual tampering,
cross-deployment bleed) would make the eager `JwtAuthFilter` return 401
to the pre-login request, leaving `GuiConfigService` in an unrecoverable
error state and the login form blank until a manual reload.

### Any related issues, documentation, discussions?

Closes apache#5407. Companion to apache#5404 — without this change, the eager filter
introduced there exposes the regression described above.

### How was this PR tested?

Manually tested in the browser against apache#5404's backend with a forged JWT
in localStorage; confirmed `/api/config/pre-login` no longer carries
`Authorization` and the login form renders without a manual reload.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.7)
Yicong-Huang added a commit that referenced this pull request Jun 7, 2026
### What changes were proposed in this PR?

`LiteLLMProxyResource` (`/chat/*`) and `LiteLLMModelsResource`
(`/models`) in `access-control-service` were `@PermitAll` — they contain
no auth check beyond a `guiWorkflowWorkspaceCopilotEnabled` feature
flag, so any anonymous caller could spend the deployment's LiteLLM
credits whenever Copilot was on. PR #5404 left the annotations in place
to preserve pre-eager-filter behavior and deferred the hardening
decision; this picks it back up.

Both classes now use `@RolesAllowed(Array("REGULAR", "ADMIN"))`. The
JwtAuthFilter from #5404 runs at `Priorities.AUTHENTICATION`, so missing
tokens fall to a 401 from the filter and bad-role tokens fall through to
a 403 from Jersey's role check.

`access-control-service` was the one microservice that hadn't picked up
`RolesAllowedDynamicFeature` when #5199 added it elsewhere, so this PR
also registers the feature in `AccessControlService.scala` — otherwise
the annotations would have been decorative.
`AccessControlServiceRunSpec` is updated to pin the registration so a
future refactor can't quietly drop it and send us back to
anonymous-LLM-access.

### Any related issues, documentation, discussions?

Closes #5420. Follow-up hardening for #5404.

### How was this PR tested?

`sbt AccessControlService/test` (22 cases) and `sbt scalafmtCheckAll`
clean. Manual verification against a running access-control-service:
anonymous `curl http://localhost:8081/api/models` returns 401 with
`WWW-Authenticate: Bearer realm="texera"` instead of the pre-PR 200; a
REGULAR-role bearer token gets through to LiteLLM as expected.

### Was this PR authored or co-authored using generative AI tooling?

(backported from commit afc5f98)

Generated-by: Claude Code (Opus 4.7)
Yicong-Huang added a commit to Ma77Ball/texera that referenced this pull request Jun 7, 2026
…che#5421)

### What changes were proposed in this PR?

`LiteLLMProxyResource` (`/chat/*`) and `LiteLLMModelsResource`
(`/models`) in `access-control-service` were `@PermitAll` — they contain
no auth check beyond a `guiWorkflowWorkspaceCopilotEnabled` feature
flag, so any anonymous caller could spend the deployment's LiteLLM
credits whenever Copilot was on. PR apache#5404 left the annotations in place
to preserve pre-eager-filter behavior and deferred the hardening
decision; this picks it back up.

Both classes now use `@RolesAllowed(Array("REGULAR", "ADMIN"))`. The
JwtAuthFilter from apache#5404 runs at `Priorities.AUTHENTICATION`, so missing
tokens fall to a 401 from the filter and bad-role tokens fall through to
a 403 from Jersey's role check.

`access-control-service` was the one microservice that hadn't picked up
`RolesAllowedDynamicFeature` when apache#5199 added it elsewhere, so this PR
also registers the feature in `AccessControlService.scala` — otherwise
the annotations would have been decorative.
`AccessControlServiceRunSpec` is updated to pin the registration so a
future refactor can't quietly drop it and send us back to
anonymous-LLM-access.

### Any related issues, documentation, discussions?

Closes apache#5420. Follow-up hardening for apache#5404.

### How was this PR tested?

`sbt AccessControlService/test` (22 cases) and `sbt scalafmtCheckAll`
clean. Manual verification against a running access-control-service:
anonymous `curl http://localhost:8081/api/models` returns 401 with
`WWW-Authenticate: Bearer realm="texera"` instead of the pre-PR 200; a
REGULAR-role bearer token gets through to LiteLLM as expected.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.7)
Yicong-Huang added a commit that referenced this pull request Jun 9, 2026
…AllowedDynamicFeature (#5198)

### What changes were proposed in this PR?

Registers Jersey's `RolesAllowedDynamicFeature` in `file-service`'s
Jersey environment so the `@RolesAllowed` / `@PermitAll` annotations
already present on `DatasetResource` are actually enforced.

`file-service` registered `JwtAuthFilter` (authentication) and the
`AuthValueFactoryProvider.Binder` (so `@Auth user` injects), but never
`RolesAllowedDynamicFeature` (authorization). The ~20
`@RolesAllowed(Array("REGULAR", "ADMIN"))` annotations on
`DatasetResource` were therefore decorative: any valid JWT reached the
resource method regardless of role. This adds the one missing
registration.

```scala
// Enforce @RolesAllowed annotations on resource methods
environment.jersey.register(classOf[RolesAllowedDynamicFeature])
```

Once enforcement is live, the six public-dataset endpoints
(`getPublicPresignedUrl`, `getPublicPresignedUrlWithS3`,
`getPublicDatasetVersionList`,
`retrievePublicDatasetVersionRootFileNodes`, `getPublicDataset`,
`getDatasetCover`) must stay reachable without a JWT for anonymous hub
visitors. They are already `@PermitAll` on `main`; the new spec pins
that so a future refactor cannot silently lock them out.

### Scope note

This PR was originally "complete @RolesAllowed enforcement across
microservices." Since then the rest of that work has landed or is in
flight on `main`, so this PR has been narrowed to the one remaining gap:

- `config-service`, `computing-unit-managing-service`,
`workflow-compiling-service`: done in #5049 / #5199.
- `JwtAuthFilter` priority + eager-401 + `@PermitAll` opt-out: done in
#5404.
- `access-control-service` (LiteLLM proxy hardening + feature
registration): handled by #5421 (@Yicong-Huang).
- **`file-service`: this PR.**

With this and #5421, every microservice that uses `@RolesAllowed`
enforces it, closing out #4904.

### Any related issues, documentation, or discussions?

Closes #5433. Follow-up to #4904; companion to #5421.

### How was this PR tested?

Added `DatasetResourcePermissionsSpec`, which verifies the six
public-dataset endpoints carry `@PermitAll` so they remain
anonymous-accessible after enforcement is enabled. `file-service` and
the auth modules compile clean. Existing `DatasetResource`
`@RolesAllowed` annotations are unchanged.

### Was this PR authored or co-authored using generative AI tooling?

Co-authored with Claude Opus 4.8 in compliance with ASF Generative
Tooling Guidance.

---------

(backported from commit 7b7a5c6)

Co-authored-by: Yicong Huang <[email protected]>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 9, 2026
…AllowedDynamicFeature (apache#5198)

### What changes were proposed in this PR?

Registers Jersey's `RolesAllowedDynamicFeature` in `file-service`'s
Jersey environment so the `@RolesAllowed` / `@PermitAll` annotations
already present on `DatasetResource` are actually enforced.

`file-service` registered `JwtAuthFilter` (authentication) and the
`AuthValueFactoryProvider.Binder` (so `@Auth user` injects), but never
`RolesAllowedDynamicFeature` (authorization). The ~20
`@RolesAllowed(Array("REGULAR", "ADMIN"))` annotations on
`DatasetResource` were therefore decorative: any valid JWT reached the
resource method regardless of role. This adds the one missing
registration.

```scala
// Enforce @RolesAllowed annotations on resource methods
environment.jersey.register(classOf[RolesAllowedDynamicFeature])
```

Once enforcement is live, the six public-dataset endpoints
(`getPublicPresignedUrl`, `getPublicPresignedUrlWithS3`,
`getPublicDatasetVersionList`,
`retrievePublicDatasetVersionRootFileNodes`, `getPublicDataset`,
`getDatasetCover`) must stay reachable without a JWT for anonymous hub
visitors. They are already `@PermitAll` on `main`; the new spec pins
that so a future refactor cannot silently lock them out.

### Scope note

This PR was originally "complete @RolesAllowed enforcement across
microservices." Since then the rest of that work has landed or is in
flight on `main`, so this PR has been narrowed to the one remaining gap:

- `config-service`, `computing-unit-managing-service`,
`workflow-compiling-service`: done in apache#5049 / apache#5199.
- `JwtAuthFilter` priority + eager-401 + `@PermitAll` opt-out: done in
apache#5404.
- `access-control-service` (LiteLLM proxy hardening + feature
registration): handled by apache#5421 (@Yicong-Huang).
- **`file-service`: this PR.**

With this and apache#5421, every microservice that uses `@RolesAllowed`
enforces it, closing out apache#4904.

### Any related issues, documentation, or discussions?

Closes apache#5433. Follow-up to apache#4904; companion to apache#5421.

### How was this PR tested?

Added `DatasetResourcePermissionsSpec`, which verifies the six
public-dataset endpoints carry `@PermitAll` so they remain
anonymous-accessible after enforcement is enabled. `file-service` and
the auth modules compile clean. Existing `DatasetResource`
`@RolesAllowed` annotations are unchanged.

### Was this PR authored or co-authored using generative AI tooling?

Co-authored with Claude Opus 4.8 in compliance with ASF Generative
Tooling Guidance.

---------

Co-authored-by: Yicong Huang <[email protected]>
ELin2025 pushed a commit to ELin2025/texera that referenced this pull request Jun 16, 2026
…che#5421)

### What changes were proposed in this PR?

`LiteLLMProxyResource` (`/chat/*`) and `LiteLLMModelsResource`
(`/models`) in `access-control-service` were `@PermitAll` — they contain
no auth check beyond a `guiWorkflowWorkspaceCopilotEnabled` feature
flag, so any anonymous caller could spend the deployment's LiteLLM
credits whenever Copilot was on. PR apache#5404 left the annotations in place
to preserve pre-eager-filter behavior and deferred the hardening
decision; this picks it back up.

Both classes now use `@RolesAllowed(Array("REGULAR", "ADMIN"))`. The
JwtAuthFilter from apache#5404 runs at `Priorities.AUTHENTICATION`, so missing
tokens fall to a 401 from the filter and bad-role tokens fall through to
a 403 from Jersey's role check.

`access-control-service` was the one microservice that hadn't picked up
`RolesAllowedDynamicFeature` when apache#5199 added it elsewhere, so this PR
also registers the feature in `AccessControlService.scala` — otherwise
the annotations would have been decorative.
`AccessControlServiceRunSpec` is updated to pin the registration so a
future refactor can't quietly drop it and send us back to
anonymous-LLM-access.

### Any related issues, documentation, discussions?

Closes apache#5420. Follow-up hardening for apache#5404.

### How was this PR tested?

`sbt AccessControlService/test` (22 cases) and `sbt scalafmtCheckAll`
clean. Manual verification against a running access-control-service:
anonymous `curl http://localhost:8081/api/models` returns 401 with
`WWW-Authenticate: Bearer realm="texera"` instead of the pre-PR 200; a
REGULAR-role bearer token gets through to LiteLLM as expected.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.7)
ELin2025 pushed a commit to ELin2025/texera that referenced this pull request Jun 16, 2026
…AllowedDynamicFeature (apache#5198)

### What changes were proposed in this PR?

Registers Jersey's `RolesAllowedDynamicFeature` in `file-service`'s
Jersey environment so the `@RolesAllowed` / `@PermitAll` annotations
already present on `DatasetResource` are actually enforced.

`file-service` registered `JwtAuthFilter` (authentication) and the
`AuthValueFactoryProvider.Binder` (so `@Auth user` injects), but never
`RolesAllowedDynamicFeature` (authorization). The ~20
`@RolesAllowed(Array("REGULAR", "ADMIN"))` annotations on
`DatasetResource` were therefore decorative: any valid JWT reached the
resource method regardless of role. This adds the one missing
registration.

```scala
// Enforce @RolesAllowed annotations on resource methods
environment.jersey.register(classOf[RolesAllowedDynamicFeature])
```

Once enforcement is live, the six public-dataset endpoints
(`getPublicPresignedUrl`, `getPublicPresignedUrlWithS3`,
`getPublicDatasetVersionList`,
`retrievePublicDatasetVersionRootFileNodes`, `getPublicDataset`,
`getDatasetCover`) must stay reachable without a JWT for anonymous hub
visitors. They are already `@PermitAll` on `main`; the new spec pins
that so a future refactor cannot silently lock them out.

### Scope note

This PR was originally "complete @RolesAllowed enforcement across
microservices." Since then the rest of that work has landed or is in
flight on `main`, so this PR has been narrowed to the one remaining gap:

- `config-service`, `computing-unit-managing-service`,
`workflow-compiling-service`: done in apache#5049 / apache#5199.
- `JwtAuthFilter` priority + eager-401 + `@PermitAll` opt-out: done in
apache#5404.
- `access-control-service` (LiteLLM proxy hardening + feature
registration): handled by apache#5421 (@Yicong-Huang).
- **`file-service`: this PR.**

With this and apache#5421, every microservice that uses `@RolesAllowed`
enforces it, closing out apache#4904.

### Any related issues, documentation, or discussions?

Closes apache#5433. Follow-up to apache#4904; companion to apache#5421.

### How was this PR tested?

Added `DatasetResourcePermissionsSpec`, which verifies the six
public-dataset endpoints carry `@PermitAll` so they remain
anonymous-accessible after enforcement is enabled. `file-service` and
the auth modules compile clean. Existing `DatasetResource`
`@RolesAllowed` annotations are unchanged.

### Was this PR authored or co-authored using generative AI tooling?

Co-authored with Claude Opus 4.8 in compliance with ASF Generative
Tooling Guidance.

---------

Co-authored-by: Yicong Huang <[email protected]>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
)

### What changes were proposed in this PR?

Adds `api/config/pre-login` to `JwtModule.forRoot`'s `disallowedRoutes`
so the anonymous pre-login config fetch is no longer auto-attached with
`Authorization: Bearer …`. Before this change a stored JWT whose
signature can't be verified server-side (key rotation, manual tampering,
cross-deployment bleed) would make the eager `JwtAuthFilter` return 401
to the pre-login request, leaving `GuiConfigService` in an unrecoverable
error state and the login form blank until a manual reload.

### Any related issues, documentation, discussions?

Closes apache#5407. Companion to apache#5404 — without this change, the eager filter
introduced there exposes the regression described above.

### How was this PR tested?

Manually tested in the browser against apache#5404's backend with a forged JWT
in localStorage; confirmed `/api/config/pre-login` no longer carries
`Authorization` and the login form renders without a manual reload.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.7)
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…he#5404)

### What changes were proposed in this PR?

Replaces the lazy pass-through behavior in `common/auth/JwtAuthFilter`
with an RFC 6750 eager 401 + `WWW-Authenticate` challenge. Missing
`Authorization` throws the bare `Bearer` challenge; an invalid token
throws `error="invalid_token"` so a well-behaved client can distinguish
"please log in" from "your stored token is invalid, discard it". Valid
tokens populate a `SecurityContext` exactly as before.

Endpoints that need to serve anonymous traffic opt out with `@PermitAll`
(JSR-250). This PR audits every resource method in the 5 microservices
and applies `@PermitAll` where the lazy filter previously made it
implicit:

- 5x `HealthCheckResource` (liveness probes)
- `AccessControlResource` `/auth/*` (routing proxy that authenticates
itself via `parseToken` in the resource body)
- `LiteLLMProxyResource` `/chat/*`, `LiteLLMModelsResource` `/models`
(preserve current "gated only by `guiWorkflowWorkspaceCopilotEnabled`"
behavior; whether these should require an authenticated user is a
separate hardening decision)
- `DatasetResource`: 5 endpoints with `/public-*` or `/publicVersion`
paths, plus `/{did}/cover` and `/{did}/cover-url` which already take
`@Auth Optional[SessionUser]` for opt-in user context

`UnauthorizedException` + `UnauthorizedExceptionMapper` carry the
`WWW-Authenticate` challenge to the JAX-RS edge. The exception extends
`RuntimeException` (not `WebApplicationException`) so unit tests can run
without a Jersey `RuntimeDelegate` on the classpath, and is constructed
with `writableStackTrace=false` to avoid `fillInStackTrace` cost on the
auth hot path.

### Any related issues, documentation, discussions?

Closes apache#4901. The earlier attempt at this fix, apache#4903, was reverted in
apache#5025 because expired tokens from `localStorage` were piggy-backed onto
`/api/config/gui` and broke the login page (apache#5026). PR apache#5392 has since
fixed the frontend to drop expired tokens client-side (`skipWhenExpired:
true`) and clear the session reactively on 401, so this PR can now ship
safely.

### How was this PR tested?

Added `JwtAuthFilterSpec` (header-missing / non-Bearer / invalid-token /
valid-token; method- and class-level `@PermitAll`; resource-info-absent
fallback) and `UnauthorizedExceptionMapperSpec`. Updated existing
service specs to expect 401 (from the filter) instead of 403 (from the
role filter) for missing-Authorization scenarios, and `*ServiceRunSpec`
mocks verify the new `UnauthorizedExceptionMapper` registration. `sbt
Auth/test` + 4 service specs all green; `sbt scalafmtCheckAll` clean.
Manually tested end-to-end against a running `config-service` build with
`curl` (missing / bad / valid tokens, `@PermitAll` healthcheck and
pre-login) and in the browser with a forged JWT in localStorage to
confirm the eager 401 path interoperates cleanly with PR apache#5392's 401
interceptor.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.7)
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…che#5421)

### What changes were proposed in this PR?

`LiteLLMProxyResource` (`/chat/*`) and `LiteLLMModelsResource`
(`/models`) in `access-control-service` were `@PermitAll` — they contain
no auth check beyond a `guiWorkflowWorkspaceCopilotEnabled` feature
flag, so any anonymous caller could spend the deployment's LiteLLM
credits whenever Copilot was on. PR apache#5404 left the annotations in place
to preserve pre-eager-filter behavior and deferred the hardening
decision; this picks it back up.

Both classes now use `@RolesAllowed(Array("REGULAR", "ADMIN"))`. The
JwtAuthFilter from apache#5404 runs at `Priorities.AUTHENTICATION`, so missing
tokens fall to a 401 from the filter and bad-role tokens fall through to
a 403 from Jersey's role check.

`access-control-service` was the one microservice that hadn't picked up
`RolesAllowedDynamicFeature` when apache#5199 added it elsewhere, so this PR
also registers the feature in `AccessControlService.scala` — otherwise
the annotations would have been decorative.
`AccessControlServiceRunSpec` is updated to pin the registration so a
future refactor can't quietly drop it and send us back to
anonymous-LLM-access.

### Any related issues, documentation, discussions?

Closes apache#5420. Follow-up hardening for apache#5404.

### How was this PR tested?

`sbt AccessControlService/test` (22 cases) and `sbt scalafmtCheckAll`
clean. Manual verification against a running access-control-service:
anonymous `curl http://localhost:8081/api/models` returns 401 with
`WWW-Authenticate: Bearer realm="texera"` instead of the pre-PR 200; a
REGULAR-role bearer token gets through to LiteLLM as expected.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.7)
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…AllowedDynamicFeature (apache#5198)

### What changes were proposed in this PR?

Registers Jersey's `RolesAllowedDynamicFeature` in `file-service`'s
Jersey environment so the `@RolesAllowed` / `@PermitAll` annotations
already present on `DatasetResource` are actually enforced.

`file-service` registered `JwtAuthFilter` (authentication) and the
`AuthValueFactoryProvider.Binder` (so `@Auth user` injects), but never
`RolesAllowedDynamicFeature` (authorization). The ~20
`@RolesAllowed(Array("REGULAR", "ADMIN"))` annotations on
`DatasetResource` were therefore decorative: any valid JWT reached the
resource method regardless of role. This adds the one missing
registration.

```scala
// Enforce @RolesAllowed annotations on resource methods
environment.jersey.register(classOf[RolesAllowedDynamicFeature])
```

Once enforcement is live, the six public-dataset endpoints
(`getPublicPresignedUrl`, `getPublicPresignedUrlWithS3`,
`getPublicDatasetVersionList`,
`retrievePublicDatasetVersionRootFileNodes`, `getPublicDataset`,
`getDatasetCover`) must stay reachable without a JWT for anonymous hub
visitors. They are already `@PermitAll` on `main`; the new spec pins
that so a future refactor cannot silently lock them out.

### Scope note

This PR was originally "complete @RolesAllowed enforcement across
microservices." Since then the rest of that work has landed or is in
flight on `main`, so this PR has been narrowed to the one remaining gap:

- `config-service`, `computing-unit-managing-service`,
`workflow-compiling-service`: done in apache#5049 / apache#5199.
- `JwtAuthFilter` priority + eager-401 + `@PermitAll` opt-out: done in
apache#5404.
- `access-control-service` (LiteLLM proxy hardening + feature
registration): handled by apache#5421 (@Yicong-Huang).
- **`file-service`: this PR.**

With this and apache#5421, every microservice that uses `@RolesAllowed`
enforces it, closing out apache#4904.

### Any related issues, documentation, or discussions?

Closes apache#5433. Follow-up to apache#4904; companion to apache#5421.

### How was this PR tested?

Added `DatasetResourcePermissionsSpec`, which verifies the six
public-dataset endpoints carry `@PermitAll` so they remain
anonymous-accessible after enforcement is enabled. `file-service` and
the auth modules compile clean. Existing `DatasetResource`
`@RolesAllowed` annotations are unchanged.

### Was this PR authored or co-authored using generative AI tooling?

Co-authored with Claude Opus 4.8 in compliance with ASF Generative
Tooling Guidance.

---------

Co-authored-by: Yicong Huang <[email protected]>
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Nov 2, 2026
apache#9079)

### What changes were proposed in this PR?

`compileWorkflowAsync` called the JWT-protected `/api/compile`
(`@RolesAllowed(REGULAR, ADMIN)` behind `JwtAuthFilter`, since apache#5199 /
apache#5404) with only `Content-Type`, so every agent compile returned 401.
The agent silently proceeded without operator output schemas or compile
errors.

```
Before:  prepareStep -> POST /api/compile (no Authorization)      -> 401 -> null
After:   prepareStep -> POST /api/compile (Bearer <delegate token>) -> 200 -> schemas + operatorErrors
```

| File | Change |
| --- | --- |
| `api/compile-api.ts` | optional `token` param; sends
`createAuthHeaders(token)` when present (no-token behavior unchanged) |
| `agent/texera-agent.ts` | `prepareStep` passes
`this.delegateConfig?.userToken` |

Audited the other agent-service HTTP calls: workflow persist/retrieve
and execution already send the Bearer token;
`/api/resources/operator-metadata` is public. Compile was the only gap.

### Any related issues, documentation, discussions?

Closes apache#9078

### How was this PR tested?

Regression tests written first (failed before the fix, pass after):

- `compile-api.spec.ts`: sends `Authorization: Bearer <token>` when
given; omits it for an empty token; against a mock that mirrors
`JwtAuthFilter` (401 without Bearer, 200 with), returns `null` without a
token and the schemas with one.
- `texera-agent.spec.ts`: in delegate mode, every compile request
carries `Bearer <delegate token>`.

```
cd agent-service
bun test             # 314 pass, 0 fail (19 files)
bun run typecheck    # tsc --noEmit, exit 0
bun run format:check # All matched files use Prettier code style!
```

Verified end-to-end against a running cluster.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci changes related to CI common fix platform Non-amber Scala service paths release/v1.2 back porting to release/v1.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JwtAuthFilter: switch to eager 401 on missing/invalid token, opt-out via @PermitAll

4 participants