From 135e3d5aab7b18ee18c12c4d4454df332ab38513 Mon Sep 17 00:00:00 2001 From: Gabriel Fonseca Date: Sun, 15 Nov 2026 22:08:29 +0000 Subject: [PATCH] chore(code-server): rebase model proxy route to /v1/proxy and tighten to POST Move the hosted-worker model proxy route from `/v1/model-proxy/{provider}` to `/v1/proxy/{provider}` and register it as POST-only at the router level. - lib.rs: route path `/v1/model-proxy/...` -> `/v1/proxy/...`; `axum::routing::any` -> `axum::routing::post`. The handler's `proxy_path_allowed` already refused non-POST, so this is a surface hardening, not a behavior change. - worker_access.rs: worker URL template and module doc now use `/v1/proxy/...`; test expectations updated to match. - docs + changelog: updated the worker env table, credential-flow diagram, and added a `[Unreleased]` Changed entry. Workers are unaffected: the server generates each worker's proxy URL at container launch, so no client-side change is needed. --- CHANGELOG.md | 3 +++ crates/code-server/src/lib.rs | 4 ++-- crates/code-server/src/worker_access.rs | 10 +++++----- docs/CONTAINERS.md | 4 ++-- docs/design/worker-architecture.md | 4 ++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22f329c..b8a2c0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - `features.enable_telemetry` in the core project config. The CLI never read it, so it changed nothing. Config files that still contain the key load as before. Use `analytics.enabled` for product analytics, or `telemetry` for local event tracing. +### Changed +- The hosted-worker model proxy route moved from `/v1/model-proxy/` to `/v1/proxy/`. Workers are unaffected: the server generates each worker's proxy URL at container launch, so no client-side change is needed. The route is now explicitly `POST`-only at the router level (it already refused non-`POST` in the handler). + ## [0.2.2] - 2026-11-11 ### Added diff --git a/crates/code-server/src/lib.rs b/crates/code-server/src/lib.rs index 55f8008..f504411 100644 --- a/crates/code-server/src/lib.rs +++ b/crates/code-server/src/lib.rs @@ -1813,8 +1813,8 @@ pub fn app(state: Arc) -> Router { Router::new() .route("/health", get(health)) .route( - "/v1/model-proxy/{provider}/{*rest}", - axum::routing::any(model_proxy_route), + "/v1/proxy/{provider}/{*rest}", + axum::routing::post(model_proxy_route), ) .route("/v1/webhooks/{source}", post(integration_webhook)) .route("/v1/oauth/{provider}/callback", get(generic_oauth_callback)) diff --git a/crates/code-server/src/worker_access.rs b/crates/code-server/src/worker_access.rs index 55aa91d..46e1775 100644 --- a/crates/code-server/src/worker_access.rs +++ b/crates/code-server/src/worker_access.rs @@ -5,7 +5,7 @@ //! - Each task gets a random token. The token authorizes only that task's worker //! endpoints (read the task, read its runtime, read and write its GitHub //! integration, and post completion). -//! - Model calls go through `/v1/model-proxy/{provider}`. The proxy checks the +//! - Model calls go through `/v1/proxy/{provider}`. The proxy checks the //! token, drops the caller's auth headers, adds the real provider key from the //! server's environment, and streams the upstream response back. //! - The token is revoked when the task completes or is cancelled. Tokens are stored @@ -266,7 +266,7 @@ pub(crate) fn worker_provider_env( token: &str, ) -> Vec<(String, String)> { let base = format!( - "{}/v1/model-proxy/{provider_name}", + "{}/v1/proxy/{provider_name}", proxy_base_url.trim_end_matches('/') ); match provider_name { @@ -578,7 +578,7 @@ mod tests { ("OPENAI_API_KEY".to_string(), "tok".to_string()), ( "OPENAI_BASE_URL".to_string(), - "http://host.docker.internal:8790/v1/model-proxy/openai".to_string() + "http://host.docker.internal:8790/v1/proxy/openai".to_string() ), ] ); @@ -599,7 +599,7 @@ mod tests { ("OLLAMA_API_KEY".to_string(), "tok".to_string()), ( "OLLAMA_BASE_URL".to_string(), - "http://frontal-relay:8788/v1/model-proxy/ollama".to_string() + "http://frontal-relay:8788/v1/proxy/ollama".to_string() ), ] ); @@ -670,7 +670,7 @@ mod proxy_tests { fn worker_request(token: Option<&str>) -> Request { let mut builder = Request::builder() .method("POST") - .uri("/v1/model-proxy/openai/chat/completions?stream=false") + .uri("/v1/proxy/openai/chat/completions?stream=false") .header("content-type", "application/json"); if let Some(token) = token { builder = builder.header("authorization", format!("Bearer {token}")); diff --git a/docs/CONTAINERS.md b/docs/CONTAINERS.md index b103b1f..d454427 100644 --- a/docs/CONTAINERS.md +++ b/docs/CONTAINERS.md @@ -207,7 +207,7 @@ The server starts each worker with a small, deliberate environment: |---|---|---| | `FRONTAL_CODE_SERVER_API_KEY` | A random token for this task only | Authenticates the worker's own calls: read the task and its runtime, read and write its GitHub integration, publish, and complete. | | `OPENAI_API_KEY` (or `FRONTAL_API_KEY`, `XAI_API_KEY`, `AZURE_OPENAI_API_KEY`) | The same task token | The CLI's provider client needs a value. Model calls use it to reach the proxy, not the provider. | -| `OPENAI_BASE_URL` (or the matching `*_BASE_URL`) | `http://frontal-relay:/v1/model-proxy/` | Sends model traffic through the server. | +| `OPENAI_BASE_URL` (or the matching `*_BASE_URL`) | `http://frontal-relay:/v1/proxy/` | Sends model traffic through the server. | | `FRONTAL_CODE_SERVER_URL`, `FRONTAL_CODE_HOSTED_WORKER`, `FRONTAL_CODE_HOSTED_TASK_FILE` | Fixed values | Locate the server and the task file. | | `FRONTAL_CODE_MAX_OUTPUT_TOKENS` | Copied from the server, if set | Non-secret tuning. | @@ -234,7 +234,7 @@ Every worker runs with `--cap-drop ALL`, `--security-opt no-new-privileges:true` ### How model calls reach the provider -The worker sends each model request to `/v1/model-proxy/` on the server. The proxy: +The worker sends each model request to `/v1/proxy/` on the server. The proxy: 1. Checks the worker's token. The token must be live (issued for a task that has not completed or been cancelled). 2. Removes the caller's authorization headers. diff --git a/docs/design/worker-architecture.md b/docs/design/worker-architecture.md index 5b30a7a..dccd513 100644 --- a/docs/design/worker-architecture.md +++ b/docs/design/worker-architecture.md @@ -24,10 +24,10 @@ This document describes how a hosted task runs an agent, where each credential l │ creates worker container with: │ FRONTAL_CODE_SERVER_API_KEY = task token │ OPENAI_API_KEY (or the matching key var) = task token - │ OPENAI_BASE_URL = http://frontal-relay:8788/v1/model-proxy/openai + │ OPENAI_BASE_URL = http://frontal-relay:8788/v1/proxy/openai │ FRONTAL_CODE_SERVER_URL = http://frontal-relay:8788 ▼ - worker ──► relay ──► code-server /v1/model-proxy/openai/... ──► provider + worker ──► relay ──► code-server /v1/proxy/openai/... ──► provider (drops the token, adds OPENAI_API_KEY) worker ──► relay ──► code-server /v1/tasks//publish (patch) └─► fresh clone, apply, commit, push with GITHUB_TOKEN