mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
codex: add exec-server managed-network follow-up
Split the remote managed-network wiring and verification fixes out of the main exec-server sandbox PR. This keeps the original review-response branch focused while carrying the exec-server-owned proxy startup, the unsupported approval-callback guard, and the added regression coverage in a stacked follow-up. Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -1279,6 +1279,18 @@ impl Session {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn managed_network_proxy_spec(
|
||||
&self,
|
||||
) -> Option<crate::config::NetworkProxySpec> {
|
||||
let state = self.state.lock().await;
|
||||
state
|
||||
.session_configuration
|
||||
.original_config_do_not_use
|
||||
.permissions
|
||||
.network
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// Builds the `x-codex-beta-features` header value for this session.
|
||||
///
|
||||
/// `ModelClient` is session-scoped and intentionally does not depend on the full `Config`, so
|
||||
|
||||
@@ -78,6 +78,25 @@ impl NetworkProxySpec {
|
||||
self.config.network.enabled
|
||||
}
|
||||
|
||||
pub(crate) fn config(&self) -> &NetworkProxyConfig {
|
||||
&self.config
|
||||
}
|
||||
|
||||
pub(crate) fn constraints(&self) -> &NetworkProxyConstraints {
|
||||
&self.constraints
|
||||
}
|
||||
|
||||
pub(crate) fn requires_remote_approval_callbacks(
|
||||
&self,
|
||||
sandbox_policy: &SandboxPolicy,
|
||||
) -> bool {
|
||||
!self.hard_deny_allowlist_misses
|
||||
&& matches!(
|
||||
sandbox_policy,
|
||||
SandboxPolicy::ReadOnly { .. } | SandboxPolicy::WorkspaceWrite { .. }
|
||||
)
|
||||
}
|
||||
|
||||
pub fn proxy_host_and_port(&self) -> String {
|
||||
host_and_port_from_network_addr(&self.config.network.proxy_url, /*default_port*/ 3128)
|
||||
}
|
||||
|
||||
@@ -38,6 +38,32 @@ fn build_state_with_audit_metadata_threads_metadata_to_state() {
|
||||
assert_eq!(state.audit_metadata(), &metadata);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requires_remote_approval_callbacks_only_for_restricted_expandable_managed_network() {
|
||||
let expandable_spec = NetworkProxySpec {
|
||||
config: NetworkProxyConfig::default(),
|
||||
constraints: NetworkProxyConstraints::default(),
|
||||
hard_deny_allowlist_misses: false,
|
||||
};
|
||||
assert!(
|
||||
expandable_spec.requires_remote_approval_callbacks(&SandboxPolicy::new_read_only_policy())
|
||||
);
|
||||
assert!(
|
||||
expandable_spec
|
||||
.requires_remote_approval_callbacks(&SandboxPolicy::new_workspace_write_policy())
|
||||
);
|
||||
assert!(!expandable_spec.requires_remote_approval_callbacks(&SandboxPolicy::DangerFullAccess));
|
||||
|
||||
let hard_deny_spec = NetworkProxySpec {
|
||||
config: NetworkProxyConfig::default(),
|
||||
constraints: NetworkProxyConstraints::default(),
|
||||
hard_deny_allowlist_misses: true,
|
||||
};
|
||||
assert!(
|
||||
!hard_deny_spec.requires_remote_approval_callbacks(&SandboxPolicy::new_read_only_policy())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requirements_allowed_domains_are_a_baseline_for_user_allowlist() {
|
||||
let mut config = NetworkProxyConfig::default();
|
||||
|
||||
@@ -33,7 +33,9 @@ use crate::unified_exec::NoopSpawnLifecycle;
|
||||
use crate::unified_exec::UnifiedExecError;
|
||||
use crate::unified_exec::UnifiedExecProcess;
|
||||
use crate::unified_exec::UnifiedExecProcessManager;
|
||||
use codex_exec_server::ManagedNetworkConfig;
|
||||
use codex_network_proxy::NetworkProxy;
|
||||
use codex_network_proxy::NetworkProxyAuditMetadata;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::error::SandboxErr;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
@@ -83,6 +85,11 @@ pub struct UnifiedExecRuntime<'a> {
|
||||
shell_mode: UnifiedExecShellMode,
|
||||
}
|
||||
|
||||
struct RemoteManagedNetworkLaunch {
|
||||
config: ManagedNetworkConfig,
|
||||
requires_approval_callbacks: bool,
|
||||
}
|
||||
|
||||
fn build_remote_exec_sandbox_config(
|
||||
attempt: &SandboxAttempt<'_>,
|
||||
additional_permissions: Option<PermissionProfile>,
|
||||
@@ -105,6 +112,35 @@ fn build_remote_exec_sandbox_config(
|
||||
}
|
||||
}
|
||||
|
||||
async fn build_remote_exec_managed_network_launch(
|
||||
session: &crate::codex::Session,
|
||||
sandbox_policy: &codex_protocol::protocol::SandboxPolicy,
|
||||
) -> Option<RemoteManagedNetworkLaunch> {
|
||||
let spec = session.managed_network_proxy_spec().await?;
|
||||
let spec = spec
|
||||
.with_exec_policy_network_rules(session.services.exec_policy.current().as_ref())
|
||||
.map_err(|err| {
|
||||
tracing::warn!(
|
||||
"failed to apply execpolicy network rules to remote managed proxy; continuing with configured network policy: {err}"
|
||||
);
|
||||
err
|
||||
})
|
||||
.unwrap_or_else(|_| spec.clone());
|
||||
|
||||
Some(RemoteManagedNetworkLaunch {
|
||||
config: ManagedNetworkConfig {
|
||||
config: spec.config().clone(),
|
||||
constraints: spec.constraints().clone(),
|
||||
audit_metadata: NetworkProxyAuditMetadata {
|
||||
conversation_id: Some(session.conversation_id.to_string()),
|
||||
app_version: Some(env!("CARGO_PKG_VERSION").to_string()),
|
||||
..NetworkProxyAuditMetadata::default()
|
||||
},
|
||||
},
|
||||
requires_approval_callbacks: spec.requires_remote_approval_callbacks(sandbox_policy),
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> UnifiedExecRuntime<'a> {
|
||||
/// Creates a runtime bound to the shared unified-exec process manager.
|
||||
pub fn new(manager: &'a UnifiedExecProcessManager, shell_mode: UnifiedExecShellMode) -> Self {
|
||||
@@ -238,10 +274,7 @@ impl<'a> ToolRuntime<UnifiedExecRequest, UnifiedExecProcess> for UnifiedExecRunt
|
||||
command
|
||||
};
|
||||
|
||||
let mut env = req.env.clone();
|
||||
if let Some(network) = req.network.as_ref() {
|
||||
network.apply_to_env(&mut env);
|
||||
}
|
||||
let base_env = req.env.clone();
|
||||
if let Some(environment) = ctx
|
||||
.turn
|
||||
.environment
|
||||
@@ -254,17 +287,38 @@ impl<'a> ToolRuntime<UnifiedExecRequest, UnifiedExecProcess> for UnifiedExecRunt
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
let managed_network = if req.network.is_some() {
|
||||
let managed_network =
|
||||
build_remote_exec_managed_network_launch(ctx.session.as_ref(), attempt.policy)
|
||||
.await
|
||||
.ok_or_else(|| {
|
||||
ToolError::Rejected(
|
||||
"remote unified_exec is missing managed-network proxy configuration"
|
||||
.to_string(),
|
||||
)
|
||||
})?;
|
||||
if managed_network.requires_approval_callbacks {
|
||||
return Err(ToolError::Rejected(
|
||||
"remote unified_exec does not yet support managed-network approval callbacks"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
Some(managed_network.config)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let exec_params = codex_exec_server::ExecParams {
|
||||
process_id: req.process_id.to_string().into(),
|
||||
argv: command,
|
||||
cwd: req.cwd.clone(),
|
||||
env,
|
||||
env: base_env.clone(),
|
||||
tty: req.tty,
|
||||
arg0: None,
|
||||
sandbox: build_remote_exec_sandbox_config(
|
||||
attempt,
|
||||
req.additional_permissions.clone(),
|
||||
),
|
||||
managed_network,
|
||||
};
|
||||
return self
|
||||
.manager
|
||||
@@ -280,6 +334,10 @@ impl<'a> ToolRuntime<UnifiedExecRequest, UnifiedExecProcess> for UnifiedExecRunt
|
||||
other => ToolError::Rejected(other.to_string()),
|
||||
});
|
||||
}
|
||||
let mut env = base_env;
|
||||
if let Some(network) = req.network.as_ref() {
|
||||
network.apply_to_env(&mut env);
|
||||
}
|
||||
let Some(environment) = ctx.turn.environment.as_ref() else {
|
||||
return Err(ToolError::Rejected(
|
||||
"exec_command is unavailable in this session".to_string(),
|
||||
|
||||
@@ -610,6 +610,7 @@ impl UnifiedExecProcessManager {
|
||||
tty,
|
||||
arg0: request.arg0.clone(),
|
||||
sandbox: codex_sandboxing::SandboxLaunchConfig::no_sandbox(request.cwd.clone()),
|
||||
managed_network: None,
|
||||
})
|
||||
.await
|
||||
.map_err(|err| UnifiedExecError::create_process(err.to_string()))?;
|
||||
|
||||
Reference in New Issue
Block a user