Forward executor network policy decisions for auditing (#38670)

## What changed

- Add a best-effort `network/policyDecision` notification for final domain and non-domain policy decisions made by executor-local proxies.
- Validate notifications against the active process on the controller and emit audit events with controller-trusted session and execution metadata.
- Reserve outbound RPC capacity so audit notifications cannot block control messages, and expose valid `chatgpt-account-id` header values for audit attribution.

## Testing

- Cover notification serialization, proxy decision capture, executor-to-controller delivery, trusted metadata handling, and reserved RPC capacity.

GitOrigin-RevId: a39f96a6b3d9401c03d54eaef5b9a6d3fe0da78b
This commit is contained in:
viyatb-oai
2026-08-14 23:42:40 +00:00
committed by copyberry
parent a186f5484d
commit 15fde8c1f2
15 changed files with 655 additions and 19 deletions
@@ -4,6 +4,7 @@ use serde::Serialize;
use crate::ProcessId;
pub const NETWORK_POLICY_REQUEST_METHOD: &str = "network/policyRequest";
pub const NETWORK_POLICY_DECISION_METHOD: &str = "network/policyDecision";
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;
@@ -23,6 +24,27 @@ pub struct ExecServerNetworkPolicyRequest {
pub port: u16,
}
/// Reports an executor-local network policy decision to its authenticated controller.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NetworkPolicyDecisionNotification {
pub process_id: ProcessId,
pub timestamp: String,
pub scope: String,
pub decision: String,
pub source: String,
pub reason: String,
pub protocol: ExecServerNetworkProtocol,
pub host: String,
pub port: u16,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub method: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub client: Option<String>,
#[serde(default)]
pub policy_override: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ExecServerNetworkProtocol {
@@ -3,6 +3,7 @@ use pretty_assertions::assert_eq;
use super::ExecServerNetworkPolicyDecision;
use super::ExecServerNetworkPolicyRequest;
use super::ExecServerNetworkProtocol;
use super::NetworkPolicyDecisionNotification;
use super::NetworkPolicyRequestParams;
use super::NetworkPolicyRequestResponse;
use crate::ProcessId;
@@ -73,3 +74,45 @@ fn network_policy_request_uses_stable_json_shapes() {
);
}
}
#[test]
fn network_policy_decision_notification_uses_stable_json_shape() {
let notification = NetworkPolicyDecisionNotification {
process_id: ProcessId::from("process-1"),
timestamp: "2026-08-11T12:34:56.789Z".to_string(),
scope: "domain".to_string(),
decision: "deny".to_string(),
source: "baseline_policy".to_string(),
reason: "not_allowed".to_string(),
protocol: ExecServerNetworkProtocol::HttpsConnect,
host: "example.com".to_string(),
port: 443,
method: Some("CONNECT".to_string()),
client: Some("127.0.0.1".to_string()),
policy_override: false,
};
let expected = serde_json::json!({
"processId": "process-1",
"timestamp": "2026-08-11T12:34:56.789Z",
"scope": "domain",
"decision": "deny",
"source": "baseline_policy",
"reason": "not_allowed",
"protocol": "https_connect",
"host": "example.com",
"port": 443,
"method": "CONNECT",
"client": "127.0.0.1",
"policyOverride": false,
});
assert_eq!(
serde_json::to_value(&notification).expect("serialize policy decision notification"),
expected
);
assert_eq!(
serde_json::from_value::<NetworkPolicyDecisionNotification>(expected)
.expect("deserialize policy decision notification"),
notification
);
}