Add opt-in WebSocket authentication to exec-server (#47601)

## What changed

Expose the shared `--ws-auth` options on `codex exec-server` for direct WebSocket listeners. Support capability tokens configured by token file or SHA-256 digest, and signed JWT bearer tokens. Validate `Authorization: Bearer TOKEN` before each WebSocket upgrade, rejecting missing or invalid credentials with HTTP 401 when authentication is enabled.

Reject listener authentication with stdio, `--remote`, or `forward`. Document the options and connection-time authentication behavior.

## Testing

Add CLI integration tests for all three credential configurations, unauthorized upgrade rejection, authenticated RPC initialization and reconnects, invalid configuration, and incompatible transports.

GitOrigin-RevId: 941fbd3d43e732c910d29b6f8137077b7c332835
This commit is contained in:
Ruslan Nigmatullin
2026-09-23 17:56:46 +00:00
committed by copyberry
parent 6824dabe03
commit 2210190435
10 changed files with 315 additions and 13 deletions
+5
View File
@@ -23,6 +23,7 @@ pub use transport::ExecServerListenUrlParseError;
use crate::ExecServerRuntimePaths;
use crate::ExecServerTelemetry;
use codex_http_client::HttpClientFactory;
use codex_websocket_auth::WebsocketAuthSettings;
pub async fn run_main(
listen_url: &str,
@@ -35,6 +36,7 @@ pub async fn run_main(
ExecServerTelemetry::default(),
http_client_factory,
RequestDispatchMode::Inline,
WebsocketAuthSettings::default(),
)
.await
}
@@ -50,6 +52,7 @@ pub async fn run_main_with_telemetry(
telemetry: ExecServerTelemetry,
http_client_factory: HttpClientFactory,
request_dispatch_mode: RequestDispatchMode,
websocket_auth: WebsocketAuthSettings,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
std::sync::LazyLock::force(&build_identity::PROVIDER_ID);
transport::run_transport(
@@ -58,6 +61,7 @@ pub async fn run_main_with_telemetry(
telemetry,
http_client_factory,
request_dispatch_mode,
websocket_auth,
)
.await
}
@@ -97,6 +101,7 @@ mod tests {
ExecServerTelemetry::default(),
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
super::RequestDispatchMode::Inline,
codex_websocket_auth::WebsocketAuthSettings::default(),
)
.await
.expect_err("invalid listen URL should fail");