Accept inbound Noise connections in remote exec-server (#62325)

## Why

Remote Noise executors previously connected outbound to a rendezvous relay. An inbound listener lets harnesses that can reach the executor connect directly while retaining registry-backed authorization.

## What changed

Use `--listen ws://IP:PORT` with `--remote` in Noise mode to accept inbound WebSockets. The listener serves RPCs over encrypted Noise streams after the registry authorizes the harness. It limits concurrent connections and handshake attempts, closes sockets that miss the first authorization deadline, and drains connections on shutdown.

Noise clients can attach optional admission headers from the connection bundle to `wss://` requests.

## Testing

The inbound integration test exercises a registry-authorized file read, rejection of a registry-denied harness, the absence of a plaintext RPC response, and connection closure on shutdown. Unit tests cover handshake limits and rejection of admission headers before dialing a plaintext WebSocket.

GitOrigin-RevId: b388672e49a3fe806e38f6db38825435ba25d27a
This commit is contained in:
richardopenai
2026-11-18 17:55:49 +00:00
committed by copyberry
parent f2d3086682
commit c1ed51ca2c
21 changed files with 646 additions and 48 deletions
+18 -6
View File
@@ -68,11 +68,7 @@ pub struct ExecServerCommand {
request_dispatch_mode: codex_exec_server::RequestDispatchMode,
/// Transport endpoint URL. Supported values: `ws://IP:PORT` (default), `stdio`, `stdio://`.
#[arg(
long = "listen",
value_name = "URL",
conflicts_with = "exec_server_remote"
)]
#[arg(long = "listen", value_name = "URL")]
listen: Option<String>,
#[command(flatten)]
@@ -303,7 +299,13 @@ impl ExecServerCommand {
let mut remote_config = codex_exec_server::RemoteEnvironmentConfig::new_with_transport(
base_url,
environment_id,
if direct_transport {
if let Some(listen) = self.listen.as_deref() {
let address = listen
.strip_prefix("ws://")
.and_then(|s| s.parse().ok())
.ok_or_else(|| anyhow::anyhow!("remote --listen requires ws://IP:PORT"))?;
codex_exec_server::RemoteEnvironmentTransport::NoiseInbound(address)
} else if direct_transport {
codex_exec_server::RemoteEnvironmentTransport::Direct
} else {
codex_exec_server::RemoteEnvironmentTransport::Noise
@@ -428,6 +430,16 @@ impl ExecServerCommand {
!self.chatgpt_token_stdin || self.command.is_none(),
"--chatgpt-token-stdin cannot be used with forward"
);
anyhow::ensure!(
self.remote.is_none()
|| self.listen.is_none()
|| (self.remote_transport == ExecServerRemoteTransport::Noise
&& self.command.is_none()
&& self.listen.as_deref().is_some_and(|s| s
.strip_prefix("ws://")
.is_some_and(|v| v.parse::<std::net::SocketAddr>().is_ok()))),
"remote --listen requires ws://IP:PORT, Noise transport, and no forward"
);
match (self.remote_transport, self.aws_sigv4) {
(ExecServerRemoteTransport::Noise, true) => {
anyhow::bail!("--aws-sigv4 requires --remote-transport direct");
@@ -351,3 +351,30 @@ fn standalone_help_documents_executor_options() {
.join("\n");
insta::assert_snapshot!(help);
}
/// An inbound Noise listener requires remote registration and cannot expose direct RPC transport.
#[test]
fn inbound_noise_requires_registered_noise_transport() {
let command = exec_server_from_args(&[
"--remote",
"https://registry.example.com",
"--environment-id",
"env-1",
"--listen",
"ws://0.0.0.0:9001",
]);
assert_eq!(command.listen.as_deref(), Some("ws://0.0.0.0:9001"));
command.validate_remote_transport().unwrap();
let command = exec_server_from_args(&[
"--remote",
"https://registry.example.com",
"--environment-id",
"env-1",
"--remote-transport",
"direct",
"--aws-sigv4",
"--listen",
"ws://0.0.0.0:9001",
]);
assert!(command.validate_remote_transport().is_err());
}