Files
codex/codex-rs/windows-sandbox-rs/src/provisioning_protocol.rs
T
johnl-oai 7e45bdb5fd Enable authenticated Windows sandbox provisioning (#42351)
## Why

The Windows sandbox service had provisioning policy and client authentication in place, but its IPC listener was still disabled.

## What changed

- Serve framed provisioning requests over a local named pipe, authenticate packaged clients, validate requests and machine policy, and report provisioning outcomes through bounded responses and Windows event logging.
- Return `unavailable` for configuration parse failures so clients can fall back to the elevated setup helper.
- Keep validated directory handles alive in the setup helper so path protections survive an unexpected service exit.
- Make connection recovery and shutdown wakeups tolerate clients that disconnect before the listener accepts them.

## Testing

Added Windows tests for response framing, configuration-error classification, pipe security and reconnect behavior, shutdown wakeups, and retained helper handles.

GitOrigin-RevId: 68e9d546dcada88ff162ea4f98c0f4d748706b34
2026-09-02 20:27:05 +00:00

77 lines
2.5 KiB
Rust

//! Dedicated protocol exchanged with the Windows sandbox provisioning service.
use crate::WindowsSandboxProvisioningSettings;
use anyhow::Result;
use serde::Deserialize;
use serde::Serialize;
use std::io::Read;
use std::io::Write;
/// Protocol version shared by provisioning clients and the Windows service.
pub const PROVISIONING_PROTOCOL_VERSION: u8 = 1;
/// Named pipe used by the machine-wide Windows sandbox provisioning service.
pub const SANDBOX_PROVISIONING_PIPE_NAME: &str = r"\\.\pipe\OpenAI.CodexSandbox";
/// Versioned provisioning-service message carried in a length-prefixed JSON frame.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct FramedProvisioningMessage {
pub version: u8,
#[serde(flatten)]
pub message: ProvisioningMessage,
}
/// Request and response messages exchanged with the provisioning service.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ProvisioningMessage {
ProvisionSandboxRequest {
payload: SandboxProvisioningRequest,
},
ProvisionSandboxResponse {
payload: SandboxProvisioningResponse,
},
}
/// Sandbox setup parameters sent to the provisioning service.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct SandboxProvisioningRequest {
pub codex_home: String,
pub settings: WindowsSandboxProvisioningSettings,
pub listeners: WindowsSandboxProxyListeners,
}
/// Known proxy protocols used for managed-policy validation, separate from firewall settings.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct WindowsSandboxProxyListeners {
pub http_ports: Vec<u16>,
pub socks_ports: Vec<u16>,
}
/// Result returned by the sandbox provisioning service.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum SandboxProvisioningResponse {
Ok,
/// The client should fall back to its elevated setup helper.
Unavailable,
Error {
message: String,
},
}
/// Write a length-prefixed provisioning-service message.
pub fn write_provisioning_frame<W: Write>(
writer: W,
message: &FramedProvisioningMessage,
) -> Result<()> {
crate::framed_io::write_frame(writer, message)
}
/// Read a length-prefixed provisioning-service message, returning `None` on EOF.
pub fn read_provisioning_frame<R: Read>(reader: R) -> Result<Option<FramedProvisioningMessage>> {
crate::framed_io::read_frame(reader)
}