Add exec-server network policy callback types (#34620)

## What changed

- Define the `network/policyRequest` RPC payloads for associating a network request with a process and returning an `allow`, `deny`, or `ask` decision.
- Cover HTTP, HTTPS CONNECT, and SOCKS5 TCP/UDP requests, with shared size limits for callback fields.
- Add the backward-compatible `requestPolicyDecisions` remote proxy option so executors can opt in to sending policy decisions to clients.
- Re-export the new protocol types from `codex-exec-server`.

## Testing

- Verify the request and decision JSON shapes.
- Verify that the proxy opt-in is omitted and defaults to `false` for legacy configurations, while an enabled value round-trips.

GitOrigin-RevId: 65b0a0723d1abb6e4f504a41d3a0dd41f5f21bf7
This commit is contained in:
viyatb-oai
2026-07-21 21:54:31 +00:00
committed by copyberry
parent ad020f29ae
commit d838ea0f64
6 changed files with 160 additions and 0 deletions
+2
View File
@@ -1,7 +1,9 @@
mod network_policy;
mod process_id;
mod protocol;
pub mod rpc;
pub use network_policy::*;
pub use process_id::ProcessId;
pub use protocol::*;
pub use rpc::*;
@@ -0,0 +1,51 @@
use serde::Deserialize;
use serde::Serialize;
use crate::ProcessId;
pub const NETWORK_POLICY_REQUEST_METHOD: &str = "network/policyRequest";
pub const MAX_NETWORK_POLICY_HOST_BYTES: usize = 253;
pub const MAX_NETWORK_POLICY_PROCESS_ID_BYTES: usize = 256;
pub const MAX_NETWORK_POLICY_REASON_BYTES: usize = 1024;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NetworkPolicyRequestParams {
pub process_id: ProcessId,
pub request: ExecServerNetworkPolicyRequest,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ExecServerNetworkPolicyRequest {
pub protocol: ExecServerNetworkProtocol,
pub host: String,
pub port: u16,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ExecServerNetworkProtocol {
Http,
HttpsConnect,
Socks5Tcp,
Socks5Udp,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NetworkPolicyRequestResponse {
pub decision: ExecServerNetworkPolicyDecision,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ExecServerNetworkPolicyDecision {
Allow,
Deny { reason: String },
Ask { reason: String },
}
#[cfg(test)]
#[path = "network_policy_tests.rs"]
mod tests;
@@ -0,0 +1,75 @@
use pretty_assertions::assert_eq;
use super::ExecServerNetworkPolicyDecision;
use super::ExecServerNetworkPolicyRequest;
use super::ExecServerNetworkProtocol;
use super::NetworkPolicyRequestParams;
use super::NetworkPolicyRequestResponse;
use crate::ProcessId;
#[test]
fn network_policy_request_uses_stable_json_shapes() {
let request = NetworkPolicyRequestParams {
process_id: ProcessId::from("process-1"),
request: ExecServerNetworkPolicyRequest {
protocol: ExecServerNetworkProtocol::HttpsConnect,
host: "example.com".to_string(),
port: 443,
},
};
let request_json = serde_json::json!({
"processId": "process-1",
"request": {
"protocol": "https_connect",
"host": "example.com",
"port": 443,
},
});
assert_eq!(
serde_json::to_value(&request).expect("serialize policy request"),
request_json
);
let decoded_request: NetworkPolicyRequestParams =
serde_json::from_value(request_json.clone()).expect("deserialize policy request");
assert_eq!(
serde_json::to_value(decoded_request).expect("reserialize policy request"),
request_json
);
let decision = NetworkPolicyRequestResponse {
decision: ExecServerNetworkPolicyDecision::Allow,
};
let decision_json = serde_json::json!({
"decision": {"type": "allow"},
});
assert_eq!(
serde_json::to_value(&decision).expect("serialize policy decision"),
decision_json
);
assert_eq!(
serde_json::from_value::<NetworkPolicyRequestResponse>(decision_json)
.expect("deserialize policy decision"),
decision
);
for (decision, decision_json) in [
(
ExecServerNetworkPolicyDecision::Deny {
reason: "not_allowed".to_string(),
},
serde_json::json!({"type": "deny", "reason": "not_allowed"}),
),
(
ExecServerNetworkPolicyDecision::Ask {
reason: "not_allowed".to_string(),
},
serde_json::json!({"type": "ask", "reason": "not_allowed"}),
),
] {
let response = NetworkPolicyRequestResponse { decision };
assert_eq!(
serde_json::to_value(&response).expect("serialize policy decision"),
serde_json::json!({"decision": decision_json})
);
}
}