Skip to content

fix(auth): require REGULAR/ADMIN role on LiteLLM proxy endpoints - #5421

Merged
Yicong-Huang merged 7 commits into
apache:mainfrom
Yicong-Huang:fix/litellm-proxy-rolesallowed
Jun 7, 2026
Merged

Yicong-Huang merged 7 commits into
apache:mainfrom
Yicong-Huang:fix/litellm-proxy-rolesallowed

Conversation

@Yicong-Huang

Copy link
Copy Markdown
Contributor

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?

Generated-by: Claude Code (Opus 4.7)

`LiteLLMProxyResource` (/chat/*) and `LiteLLMModelsResource` (/models)
were `@PermitAll`: an anonymous caller could hit either endpoint and
spend the deployment's LiteLLM credits whenever
`guiWorkflowWorkspaceCopilotEnabled` was on. PR apache#5404 left the
annotation in place to preserve pre-eager-filter behavior and deferred
this decision — issue apache#5420 picks it back up.

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

Register `RolesAllowedDynamicFeature` in AccessControlService so the
annotations are actually enforced; `access-control-service` was the one
microservice that hadn't picked up the registration when apache#5199 added
it elsewhere, which means the annotations would have been decorative
without this change. Pin the registration in `AccessControlServiceRunSpec`
so a future refactor can't quietly drop it and send us back to
anonymous-LLM-access.

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

codecov-commenter commented Jun 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.71%. Comparing base (5c2eaa2) to head (7b606c1).

Files with missing lines Patch % Lines
...exera/service/resource/AccessControlResource.scala 75.00% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5421      +/-   ##
============================================
+ Coverage     51.61%   51.71%   +0.10%     
- Complexity     2448     2449       +1     
============================================
  Files          1067     1067              
  Lines         41255    41273      +18     
  Branches       4437     4437              
============================================
+ Hits          21292    21344      +52     
+ Misses        18712    18671      -41     
- Partials       1251     1258       +7     
Flag Coverage Δ *Carryforward flag
access-control-service 64.61% <76.00%> (+22.39%) ⬆️
agent-service 33.76% <ø> (ø) Carriedforward from 1e39cd0
amber 52.15% <ø> (ø) Carriedforward from 1e39cd0
computing-unit-managing-service 1.65% <ø> (ø)
config-service 57.97% <ø> (+1.91%) ⬆️
file-service 38.32% <ø> (ø)
frontend 46.37% <ø> (ø) Carriedforward from 1e39cd0
pyamber 90.69% <ø> (ø) Carriedforward from 1e39cd0
python 90.84% <ø> (ø) Carriedforward from 1e39cd0
workflow-compiling-service 58.69% <ø> (ø)

*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 requested review from bobbai00 and xuang7 June 7, 2026 00:02
@Yicong-Huang Yicong-Huang added the release/v1.2 back porting to release/v1.2 label Jun 7, 2026
@Yicong-Huang

Copy link
Copy Markdown
Contributor Author

adding @xuang7 for backport review.

Wires the LiteLLM proxy resources through the same Jersey auth pipeline
production uses (JwtAuthFilter + UnauthorizedExceptionMapper +
RolesAllowedDynamicFeature) and asserts:
  - POST /chat/completions and GET /models with no Authorization
    return 401 + the Bearer realm challenge
  - INACTIVE-role tokens return 403
  - REGULAR / ADMIN tokens reach the resource body (response entity
    contains "Copilot feature is disabled" because gui.conf's default is
    `copilot-enabled = false`, which distinguishes a resource-level 403
    from a RolesAllowedDynamicFeature 403)

The three new comments are tightened to describe what the code is now,
not the path that led here.
…xies

Extends LiteLLMProxyResource / LiteLLMModelsResource with constructor
parameters for copilotEnabled, litellmBaseUrl, litellmApiKey, plus a
no-arg auxiliary constructor that delegates to GuiConfig / LLMConfig for
the production wiring Jersey reflection uses.

LiteLLMProxyAuthSpec now passes copilotEnabled = true and a deliberately
unreachable upstream (http://127.0.0.1:1) to the resources, so a
REGULAR / ADMIN request that clears the auth + role gates falls into
the resource's catch branch and returns 502 with the "Failed to proxy"
entity. That gives one regression guard per endpoint that the
authenticated path actually reaches the proxy call, complementing the
auth-rejection guards already in place.
@xuang7

xuang7 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

+1 for backporting this to release/v1.2.

…registration

Jersey reflection skips constructors whose params are not @context /
HK2-injectable, so the 3-arg constructor added for test injection is
ignored at production startup and the no-arg auxiliary ctor takes over.
Add a spec case that registers both resources via `addResource(classOf[...])`
to exercise that production code path — if a future refactor drops the
no-arg form, the test fails at ResourceExtension.before() instead of at
deployment time.
The earlier LiteLLM auth spec asserted on production-error wording via
`should include("Failed to proxy request to LiteLLM")` and similar —
that couples the test to whichever phrasing the resource happens to
log. Replace with:

  - 502 cases: assert status only. Nothing else in the route produces 502,
    so the code reaching that branch is enough to verify auth passed.
  - 403-disabled cases: extract the resource's "Copilot feature is
    disabled" payload to LiteLLMProxyResource.CopilotDisabledBody and
    compare the test response against the same constant. Tests still
    distinguish the resource's 403 from a RolesAllowedDynamicFeature 403
    without hard-coding any string.

Also adds a copilot-disabled ResourceExtension and two tests that hit
the early-exit branch, covering the patch lines Codecov flagged in
PR apache#5421 as 42% covered.
…-process mock

Adds a third ResourceExtension whose LiteLLM upstream points at a
com.sun.net.httpserver.HttpServer bound to a free random port. The
mock returns a canned JSON body for /chat/completions and /models, so
the resource's success path (request building, status passthrough,
body forwarding) runs end-to-end without touching the network.

Two new tests assert the resource's response body matches the mock's
verbatim, which proves the resource actually read and forwarded the
upstream body rather than fabricating an entity itself.
…cover

The "reach the LiteLLM proxy path" descriptions predate the mock-upstream
tests added in the previous commit. With those in place the 200-from-mock
cases are the strong evidence that auth + role passed and the proxy ran,
so the unreachable-upstream tests' real and only job is exercising the
catch branch. Rename to "return 502 when the upstream LiteLLM call fails".

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

Tested. Works well!

@Yicong-Huang
Yicong-Huang added this pull request to the merge queue Jun 7, 2026
Merged via the queue into apache:main with commit afc5f98 Jun 7, 2026
28 checks passed
@Yicong-Huang
Yicong-Huang deleted the fix/litellm-proxy-rolesallowed branch June 7, 2026 19:13
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)
@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Backport to release/v1.2 succeeded as 24e5b70. Run

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]>
bobbai00 pushed a commit to bobbai00/texera that referenced this pull request Jun 10, 2026
The LLM gateway (access-control-service) requires a REGULAR/ADMIN-role
JWT (apache#5421) and injects the LiteLLM master key downstream,
but the agent-service still sent the static LLM_API_KEY ("dummy"), so
every generation call returned 401 Unauthorized.

The delegating user's JWT is now the only credential the agent-service
sends: userToken is required when creating an agent (the request is
rejected otherwise), and LLM_API_KEY is removed from the service, the
helm chart, and the single-node env.
github-merge-queue Bot pushed a commit that referenced this pull request Jun 11, 2026
…ser (#5605)

### What changes were proposed in this PR?

Since #5421, the access-control-service LLM gateway requires a
REGULAR/ADMIN-role user JWT and injects `LITELLM_MASTER_KEY` into the
downstream request itself, but the agent-service still authenticated
with the static `LLM_API_KEY` default (`"dummy"`), so every agent
generation call returned 401 Unauthorized. This PR makes the delegating
user's JWT the only credential the agent-service ever sends:

- Creating an agent (`POST /agents`) now requires the user's JWT in the
`Authorization: Bearer` header (the standard place for credentials,
instead of a `userToken` field in the JSON payload); requests without it
are rejected with 401, since an agent without a user could never call
the gateway anyway. The frontend's JWT interceptor already attaches this
header, so `agent.service.ts` simply stops duplicating the token in the
request body.
- The OpenAI client authenticates with the delegating user's JWT; the
`LLM_API_KEY` env var is removed from the service (`env.ts`), the helm
chart (deployment env, `llm-api-key` secret entry, `llmApiKey` values),
and the single-node `.env`. The master key now lives only in the
access-control-service and LiteLLM.
- Elysia `VALIDATION`/`PARSE` errors are mapped to 400 instead of
falling through to a generic 500 (surfaced by Copilot's review comment
on the schema-violation tests).

```mermaid
sequenceDiagram
    participant FE as Frontend (user JWT)
    participant AS as agent-service
    participant ACS as access-control-service (LLM gateway)
    participant LLM as LiteLLM

    FE->>AS: POST /agents<br/>Authorization: Bearer (user JWT) — required, else 401
    FE->>AS: send message
    rect rgb(255, 235, 235)
    Note over AS,ACS: before: Authorization: Bearer dummy → 401
    end
    AS->>ACS: POST /api/chat/completions<br/>Authorization: Bearer (user JWT) ✅
    ACS->>LLM: forward with Authorization: Bearer (LITELLM_MASTER_KEY)
    LLM-->>AS: completion
    AS-->>FE: agent response
```

### Any related issues, documentation, discussions?

Closes #5604

### How was this PR tested?

Updated `server.test.ts`: agent creation sends a minted JWT in the
`Authorization` header; added cases for a missing header, a non-Bearer
scheme, and an invalid token (93 tests pass via `bun test`). Also
verified end-to-end on a local Kubernetes deployment (this branch's
chart + agent-service image, everything else from `ghcr.io/apache`
nightlies): creation without the header → 401, with the header → 200,
and a websocket message produced a real `gpt-5-mini` completion through
access-control-service → LiteLLM. `typecheck` and `format:check` pass;
the frontend change typechecks via `tsc --noEmit`.

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

Generated-by: Claude Fable 5 (1M context)

---------

Co-authored-by: Bob Bai <[email protected]>
Yicong-Huang pushed a commit that referenced this pull request Jun 11, 2026
…ser (#5605)

### What changes were proposed in this PR?

Since #5421, the access-control-service LLM gateway requires a
REGULAR/ADMIN-role user JWT and injects `LITELLM_MASTER_KEY` into the
downstream request itself, but the agent-service still authenticated
with the static `LLM_API_KEY` default (`"dummy"`), so every agent
generation call returned 401 Unauthorized. This PR makes the delegating
user's JWT the only credential the agent-service ever sends:

- Creating an agent (`POST /agents`) now requires the user's JWT in the
`Authorization: Bearer` header (the standard place for credentials,
instead of a `userToken` field in the JSON payload); requests without it
are rejected with 401, since an agent without a user could never call
the gateway anyway. The frontend's JWT interceptor already attaches this
header, so `agent.service.ts` simply stops duplicating the token in the
request body.
- The OpenAI client authenticates with the delegating user's JWT; the
`LLM_API_KEY` env var is removed from the service (`env.ts`), the helm
chart (deployment env, `llm-api-key` secret entry, `llmApiKey` values),
and the single-node `.env`. The master key now lives only in the
access-control-service and LiteLLM.
- Elysia `VALIDATION`/`PARSE` errors are mapped to 400 instead of
falling through to a generic 500 (surfaced by Copilot's review comment
on the schema-violation tests).

```mermaid
sequenceDiagram
    participant FE as Frontend (user JWT)
    participant AS as agent-service
    participant ACS as access-control-service (LLM gateway)
    participant LLM as LiteLLM

    FE->>AS: POST /agents<br/>Authorization: Bearer (user JWT) — required, else 401
    FE->>AS: send message
    rect rgb(255, 235, 235)
    Note over AS,ACS: before: Authorization: Bearer dummy → 401
    end
    AS->>ACS: POST /api/chat/completions<br/>Authorization: Bearer (user JWT) ✅
    ACS->>LLM: forward with Authorization: Bearer (LITELLM_MASTER_KEY)
    LLM-->>AS: completion
    AS-->>FE: agent response
```

### Any related issues, documentation, discussions?

Closes #5604

### How was this PR tested?

Updated `server.test.ts`: agent creation sends a minted JWT in the
`Authorization` header; added cases for a missing header, a non-Bearer
scheme, and an invalid token (93 tests pass via `bun test`). Also
verified end-to-end on a local Kubernetes deployment (this branch's
chart + agent-service image, everything else from `ghcr.io/apache`
nightlies): creation without the header → 401, with the header → 200,
and a websocket message produced a real `gpt-5-mini` completion through
access-control-service → LiteLLM. `typecheck` and `format:check` pass;
the frontend change typechecks via `tsc --noEmit`.

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

Generated-by: Claude Fable 5 (1M context)

---------

(backported from commit ae3128d)

Co-authored-by: Bob Bai <[email protected]>
bobbai00 pushed a commit to bobbai00/dataflow-agent that referenced this pull request Jun 12, 2026
Pulls 61 upstream commits. Resolved conflicts:
- agent-service/src/server.ts: adopt upstream's header-only auth (delegating
  user JWT read from the Authorization header, apache/texera#5421; userToken
  dropped from the request body / CreateAgentRequest) while keeping our `driver`
  (explicitDriver) feature and our `agent.initialize(delegateConfig)` bootstrap
  — which loads the workflow itself, so upstream's inline retrieveWorkflow block
  and its import were dropped.
- amber/.../WorkflowService.scala: keep our cache-aware clearExecutionResources
  doc (the method body retains cache invalidation).
- agent-service/src/api/agent-service-api.ts: createAgent sends the token as an
  `Authorization: Bearer` header instead of body `userToken` (the e2e harnesses
  go through this helper).

Co-Authored-By: Claude Opus 4.8 <[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]>
ELin2025 pushed a commit to ELin2025/texera that referenced this pull request Jun 16, 2026
…ser (apache#5605)

### What changes were proposed in this PR?

Since apache#5421, the access-control-service LLM gateway requires a
REGULAR/ADMIN-role user JWT and injects `LITELLM_MASTER_KEY` into the
downstream request itself, but the agent-service still authenticated
with the static `LLM_API_KEY` default (`"dummy"`), so every agent
generation call returned 401 Unauthorized. This PR makes the delegating
user's JWT the only credential the agent-service ever sends:

- Creating an agent (`POST /agents`) now requires the user's JWT in the
`Authorization: Bearer` header (the standard place for credentials,
instead of a `userToken` field in the JSON payload); requests without it
are rejected with 401, since an agent without a user could never call
the gateway anyway. The frontend's JWT interceptor already attaches this
header, so `agent.service.ts` simply stops duplicating the token in the
request body.
- The OpenAI client authenticates with the delegating user's JWT; the
`LLM_API_KEY` env var is removed from the service (`env.ts`), the helm
chart (deployment env, `llm-api-key` secret entry, `llmApiKey` values),
and the single-node `.env`. The master key now lives only in the
access-control-service and LiteLLM.
- Elysia `VALIDATION`/`PARSE` errors are mapped to 400 instead of
falling through to a generic 500 (surfaced by Copilot's review comment
on the schema-violation tests).

```mermaid
sequenceDiagram
    participant FE as Frontend (user JWT)
    participant AS as agent-service
    participant ACS as access-control-service (LLM gateway)
    participant LLM as LiteLLM

    FE->>AS: POST /agents<br/>Authorization: Bearer (user JWT) — required, else 401
    FE->>AS: send message
    rect rgb(255, 235, 235)
    Note over AS,ACS: before: Authorization: Bearer dummy → 401
    end
    AS->>ACS: POST /api/chat/completions<br/>Authorization: Bearer (user JWT) ✅
    ACS->>LLM: forward with Authorization: Bearer (LITELLM_MASTER_KEY)
    LLM-->>AS: completion
    AS-->>FE: agent response
```

### Any related issues, documentation, discussions?

Closes apache#5604

### How was this PR tested?

Updated `server.test.ts`: agent creation sends a minted JWT in the
`Authorization` header; added cases for a missing header, a non-Bearer
scheme, and an invalid token (93 tests pass via `bun test`). Also
verified end-to-end on a local Kubernetes deployment (this branch's
chart + agent-service image, everything else from `ghcr.io/apache`
nightlies): creation without the header → 401, with the header → 200,
and a websocket message produced a real `gpt-5-mini` completion through
access-control-service → LiteLLM. `typecheck` and `format:check` pass;
the frontend change typechecks via `tsc --noEmit`.

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

Generated-by: Claude Fable 5 (1M context)

---------

Co-authored-by: Bob Bai <[email protected]>
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]>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…ser (apache#5605)

### What changes were proposed in this PR?

Since apache#5421, the access-control-service LLM gateway requires a
REGULAR/ADMIN-role user JWT and injects `LITELLM_MASTER_KEY` into the
downstream request itself, but the agent-service still authenticated
with the static `LLM_API_KEY` default (`"dummy"`), so every agent
generation call returned 401 Unauthorized. This PR makes the delegating
user's JWT the only credential the agent-service ever sends:

- Creating an agent (`POST /agents`) now requires the user's JWT in the
`Authorization: Bearer` header (the standard place for credentials,
instead of a `userToken` field in the JSON payload); requests without it
are rejected with 401, since an agent without a user could never call
the gateway anyway. The frontend's JWT interceptor already attaches this
header, so `agent.service.ts` simply stops duplicating the token in the
request body.
- The OpenAI client authenticates with the delegating user's JWT; the
`LLM_API_KEY` env var is removed from the service (`env.ts`), the helm
chart (deployment env, `llm-api-key` secret entry, `llmApiKey` values),
and the single-node `.env`. The master key now lives only in the
access-control-service and LiteLLM.
- Elysia `VALIDATION`/`PARSE` errors are mapped to 400 instead of
falling through to a generic 500 (surfaced by Copilot's review comment
on the schema-violation tests).

```mermaid
sequenceDiagram
    participant FE as Frontend (user JWT)
    participant AS as agent-service
    participant ACS as access-control-service (LLM gateway)
    participant LLM as LiteLLM

    FE->>AS: POST /agents<br/>Authorization: Bearer (user JWT) — required, else 401
    FE->>AS: send message
    rect rgb(255, 235, 235)
    Note over AS,ACS: before: Authorization: Bearer dummy → 401
    end
    AS->>ACS: POST /api/chat/completions<br/>Authorization: Bearer (user JWT) ✅
    ACS->>LLM: forward with Authorization: Bearer (LITELLM_MASTER_KEY)
    LLM-->>AS: completion
    AS-->>FE: agent response
```

### Any related issues, documentation, discussions?

Closes apache#5604

### How was this PR tested?

Updated `server.test.ts`: agent creation sends a minted JWT in the
`Authorization` header; added cases for a missing header, a non-Bearer
scheme, and an invalid token (93 tests pass via `bun test`). Also
verified end-to-end on a local Kubernetes deployment (this branch's
chart + agent-service image, everything else from `ghcr.io/apache`
nightlies): creation without the header → 401, with the header → 200,
and a websocket message produced a real `gpt-5-mini` completion through
access-control-service → LiteLLM. `typecheck` and `format:check` pass;
the frontend change typechecks via `tsc --noEmit`.

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

Generated-by: Claude Fable 5 (1M context)

---------

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

Labels

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.

LiteLLM proxy endpoints accept anonymous requests when Copilot is enabled

4 participants