Repository navigation
fix(auth): make JwtAuthFilter eager-401 with @PermitAll opt-out - #5404
Merged
Merged
Conversation
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.
Codecov Report❌ Patch coverage is 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
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Jun 6, 2026
bobbai00
approved these changes
Jun 6, 2026
bobbai00
left a comment
Contributor
There was a problem hiding this comment.
Manually tested most of the functionalities on the frontend. Works well
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.
…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.
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)
Contributor
Author
|
coverage needs to be filled from individual services. will cover them later to keep this PR smaller. |
Contributor
Author
|
thanks! merging now. |
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)
Contributor
|
Backport to |
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)
This was referenced Jun 7, 2026
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]>
This was referenced Oct 21, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this PR?
Replaces the lazy pass-through behavior in
common/auth/JwtAuthFilterwith an RFC 6750 eager 401 +WWW-Authenticatechallenge. MissingAuthorizationthrows the bareBearerchallenge; an invalid token throwserror="invalid_token"so a well-behaved client can distinguish "please log in" from "your stored token is invalid, discard it". Valid tokens populate aSecurityContextexactly 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@PermitAllwhere the lazy filter previously made it implicit:HealthCheckResource(liveness probes)AccessControlResource/auth/*(routing proxy that authenticates itself viaparseTokenin the resource body)LiteLLMProxyResource/chat/*,LiteLLMModelsResource/models(preserve current "gated only byguiWorkflowWorkspaceCopilotEnabled" behavior; whether these should require an authenticated user is a separate hardening decision)DatasetResource: 5 endpoints with/public-*or/publicVersionpaths, plus/{did}/coverand/{did}/cover-urlwhich already take@Auth Optional[SessionUser]for opt-in user contextUnauthorizedException+UnauthorizedExceptionMappercarry theWWW-Authenticatechallenge to the JAX-RS edge. The exception extendsRuntimeException(notWebApplicationException) so unit tests can run without a JerseyRuntimeDelegateon the classpath, and is constructed withwritableStackTrace=falseto avoidfillInStackTracecost 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
localStoragewere piggy-backed onto/api/config/guiand 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) andUnauthorizedExceptionMapperSpec. Updated existing service specs to expect 401 (from the filter) instead of 403 (from the role filter) for missing-Authorization scenarios, and*ServiceRunSpecmocks verify the newUnauthorizedExceptionMapperregistration.sbt Auth/test+ 4 service specs all green;sbt scalafmtCheckAllclean. Manually tested end-to-end against a runningconfig-servicebuild withcurl(missing / bad / valid tokens,@PermitAllhealthcheck 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)