mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Extract shared network policy types from the proxy crate (#63986)
## Why The protocol and feature configuration crates depend on the network proxy crate for data types. Give them a smaller dependency that contains the shared definitions. ## What changed Move environment network policies, domain and Unix socket permissions, policy decisions and their sources, and credential provider definitions into `codex-network-policy-types`. Use the new crate directly from `codex-protocol` and `codex-features`. Re-export the moved types from `codex-network-proxy` and keep environment policy conversion and application, along with credential provider validation, in the proxy crate. GitOrigin-RevId: 8af684da746830bce45ac00135aed8052dba3824
This commit is contained in:
Generated
+11
-2
@@ -3632,7 +3632,7 @@ dependencies = [
|
||||
name = "codex-features"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"codex-network-proxy",
|
||||
"codex-network-policy-types",
|
||||
"codex-protocol",
|
||||
"codex-utils-redacted-string",
|
||||
"pretty_assertions",
|
||||
@@ -4576,6 +4576,14 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "codex-network-policy-types"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"schemars 0.8.22",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "codex-network-proxy"
|
||||
version = "0.0.0"
|
||||
@@ -4586,6 +4594,7 @@ dependencies = [
|
||||
"base64 0.22.1",
|
||||
"chrono",
|
||||
"clap",
|
||||
"codex-network-policy-types",
|
||||
"codex-utils-absolute-path",
|
||||
"codex-utils-home-dir",
|
||||
"codex-utils-path-uri",
|
||||
@@ -4798,7 +4807,7 @@ dependencies = [
|
||||
"codex-execpolicy-rules",
|
||||
"codex-extension-items",
|
||||
"codex-http-client",
|
||||
"codex-network-proxy",
|
||||
"codex-network-policy-types",
|
||||
"codex-utils-absolute-path",
|
||||
"codex-utils-cached-str",
|
||||
"codex-utils-image",
|
||||
|
||||
@@ -99,6 +99,7 @@ members = [
|
||||
"model-provider-info",
|
||||
"mxc-sandbox",
|
||||
"models-manager",
|
||||
"network-policy-types",
|
||||
"network-proxy",
|
||||
"ollama",
|
||||
"process-hardening",
|
||||
@@ -286,6 +287,7 @@ codex-mcp-extension = { path = "ext/mcp" }
|
||||
codex-model-provider-info = { path = "model-provider-info" }
|
||||
codex-models-manager = { path = "models-manager" }
|
||||
codex-mxc-sandbox = { path = "mxc-sandbox" }
|
||||
codex-network-policy-types = { path = "network-policy-types" }
|
||||
codex-network-proxy = { path = "network-proxy" }
|
||||
codex-ollama = { path = "ollama" }
|
||||
codex-otel = { path = "otel" }
|
||||
|
||||
@@ -15,6 +15,7 @@ use codex_config::ConfigLayerStack;
|
||||
use codex_config::merge_toml_values;
|
||||
use codex_core::config::edit::ConfigEdit;
|
||||
use codex_network_proxy::CredentialProviderConfig;
|
||||
use codex_network_proxy::validate_credential_provider;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::BTreeSet;
|
||||
use toml::Value as TomlValue;
|
||||
@@ -215,7 +216,7 @@ impl CredentialProviderEdits {
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
if old.validate(id).is_ok() {
|
||||
if validate_credential_provider(id, &old).is_ok() {
|
||||
to_validate.insert(id.clone(), current.clone());
|
||||
}
|
||||
}
|
||||
@@ -255,7 +256,7 @@ impl CredentialProviderEdits {
|
||||
}
|
||||
for (id, definition) in to_validate {
|
||||
let provider: CredentialProviderConfig = definition.try_into()?;
|
||||
provider.validate(&id)?;
|
||||
validate_credential_provider(&id, &provider)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ use super::*;
|
||||
use codex_config::RequirementSource;
|
||||
use codex_network_proxy::NetworkProxyConstraints;
|
||||
use codex_network_proxy::build_config_state;
|
||||
use codex_network_proxy::environment_policy_from_config;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn environment_policy_presence_keeps_selected_and_managed_denials() {
|
||||
let mut configured_proxy = NetworkProxyConfig::default();
|
||||
configured_proxy.set_denied_domains(vec!["blocked.example".to_string()]);
|
||||
let expected = EnvironmentNetworkPolicy::from_config(
|
||||
let expected = environment_policy_from_config(
|
||||
&configured_proxy,
|
||||
/*managed_allowed_domains_only*/ false,
|
||||
);
|
||||
@@ -90,7 +91,7 @@ allow_local_binding = false
|
||||
);
|
||||
assert_eq!(
|
||||
validate_environment_network_policy(
|
||||
&EnvironmentNetworkPolicy::from_config(
|
||||
&environment_policy_from_config(
|
||||
&expected.to_network_proxy_config(),
|
||||
/*managed_allowed_domains_only*/ false,
|
||||
),
|
||||
@@ -162,7 +163,7 @@ action = ['redact']
|
||||
.expect("a disabled unmanaged profile can load unused selectors")
|
||||
.is_none()
|
||||
);
|
||||
let policy = EnvironmentNetworkPolicy::from_config(
|
||||
let policy = environment_policy_from_config(
|
||||
&configured_proxy,
|
||||
/*managed_allowed_domains_only*/ false,
|
||||
);
|
||||
@@ -195,7 +196,7 @@ action = ['redact']
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
policy,
|
||||
EnvironmentNetworkPolicy::from_config(
|
||||
environment_policy_from_config(
|
||||
&NetworkProxyConfig {
|
||||
enabled: true,
|
||||
unix_sockets: Some(Default::default()),
|
||||
|
||||
@@ -17,7 +17,9 @@ use codex_network_proxy::NetworkProxyConfig;
|
||||
use codex_network_proxy::NetworkProxyConstraints;
|
||||
use codex_network_proxy::NetworkProxyHandle;
|
||||
use codex_network_proxy::NetworkProxyState;
|
||||
use codex_network_proxy::apply_environment_policy;
|
||||
use codex_network_proxy::build_config_state;
|
||||
use codex_network_proxy::environment_policy_from_config;
|
||||
use codex_network_proxy::host_and_port_from_network_addr;
|
||||
#[cfg(any(target_os = "windows", test))]
|
||||
use codex_network_proxy::managed_proxy_ports;
|
||||
@@ -268,7 +270,7 @@ impl NetworkProxySpec {
|
||||
|
||||
/// Returns proxy activation and traffic policy without controller-owned runtime settings.
|
||||
pub fn environment_policy(&self) -> EnvironmentNetworkPolicy {
|
||||
EnvironmentNetworkPolicy::from_config(&self.config, self.hard_deny_allowlist_misses)
|
||||
environment_policy_from_config(&self.config, self.hard_deny_allowlist_misses)
|
||||
}
|
||||
|
||||
pub(crate) fn for_environment(
|
||||
@@ -320,7 +322,7 @@ impl NetworkProxySpec {
|
||||
permission_profile,
|
||||
)?,
|
||||
};
|
||||
policy.apply_to(&mut spec.config);
|
||||
apply_environment_policy(policy, &mut spec.config);
|
||||
spec.config.allow_local_binding =
|
||||
Some(routed_binding.unwrap_or_default().resolve(&spec.config));
|
||||
let protected_denials = spec.config.denied_domains().unwrap_or_default();
|
||||
|
||||
@@ -97,7 +97,7 @@ async fn saved_grant_cannot_open_loopback_under_fixed_allowlist() -> anyhow::Res
|
||||
async fn attachment_socket_grants_respect_configured_restrictions_at_remote_launch()
|
||||
-> anyhow::Result<()> {
|
||||
let profile = PermissionProfile::workspace_write();
|
||||
let owner = EnvironmentNetworkPolicy::from_config(
|
||||
let owner = environment_policy_from_config(
|
||||
&NetworkProxyConfig {
|
||||
dangerously_allow_all_unix_sockets: Some(true),
|
||||
..Default::default()
|
||||
@@ -330,7 +330,7 @@ fn environment_policy_replaces_soft_controller_allowlist_and_preserves_denials()
|
||||
owner.dangerously_allow_all_unix_sockets = Some(true);
|
||||
owner.allow_local_binding = Some(true);
|
||||
let owner_policy =
|
||||
EnvironmentNetworkPolicy::from_config(&owner, /*managed_allowed_domains_only*/ false);
|
||||
environment_policy_from_config(&owner, /*managed_allowed_domains_only*/ false);
|
||||
assert_eq!(
|
||||
validate_environment_network_policy(&owner_policy, &profile, Platform::Linux),
|
||||
Ok(())
|
||||
@@ -387,7 +387,7 @@ fn environment_policy_replaces_soft_controller_allowlist_and_preserves_denials()
|
||||
.insert(0, "controller-review.example".to_string());
|
||||
assert_eq!(
|
||||
restricted.environment_policy(),
|
||||
EnvironmentNetworkPolicy::from_config(&owner, /*managed_allowed_domains_only*/ false)
|
||||
environment_policy_from_config(&owner, /*managed_allowed_domains_only*/ false)
|
||||
);
|
||||
let external = PermissionProfile::External {
|
||||
network: NetworkSandboxPolicy::Enabled,
|
||||
@@ -416,7 +416,7 @@ fn environment_policy_replaces_soft_controller_allowlist_and_preserves_denials()
|
||||
assert!(compose(Some(&spec), &owner_policy, &external, &empty).is_err());
|
||||
owner.set_allowed_domains(vec!["*".to_string()]);
|
||||
let wildcard_policy =
|
||||
EnvironmentNetworkPolicy::from_config(&owner, /*managed_allowed_domains_only*/ false);
|
||||
environment_policy_from_config(&owner, /*managed_allowed_domains_only*/ false);
|
||||
assert!(compose(Some(&spec), &wildcard_policy, &profile, &empty).is_err());
|
||||
assert_eq!(
|
||||
validate_environment_network_policy(&wildcard_policy, &profile, Platform::Linux),
|
||||
@@ -424,7 +424,7 @@ fn environment_policy_replaces_soft_controller_allowlist_and_preserves_denials()
|
||||
);
|
||||
owner.set_allowed_domains(vec!["[".to_string()]);
|
||||
let malformed_policy =
|
||||
EnvironmentNetworkPolicy::from_config(&owner, /*managed_allowed_domains_only*/ false);
|
||||
environment_policy_from_config(&owner, /*managed_allowed_domains_only*/ false);
|
||||
assert_eq!(
|
||||
validate_environment_network_policy(&malformed_policy, &profile, Platform::Linux),
|
||||
Err(EnvironmentNetworkConfigError)
|
||||
@@ -932,8 +932,7 @@ async fn environment_local_binding_preserves_explicit_denials_and_inherits_omitt
|
||||
..Default::default()
|
||||
};
|
||||
owner_config.set_allowed_domains(vec!["example.com".to_string()]);
|
||||
let owner =
|
||||
EnvironmentNetworkPolicy::from_config(&owner_config, name == "managed_omitted");
|
||||
let owner = environment_policy_from_config(&owner_config, name == "managed_omitted");
|
||||
let composed = NetworkProxySpec::for_environment(
|
||||
controller.as_ref(),
|
||||
&owner,
|
||||
|
||||
@@ -33,12 +33,12 @@ use codex_execpolicy::Policy;
|
||||
use codex_execpolicy::RuleMatch;
|
||||
use codex_features::Feature;
|
||||
use codex_model_provider::create_model_provider;
|
||||
use codex_network_proxy::EnvironmentNetworkPolicy;
|
||||
use codex_network_proxy::NetworkDecision;
|
||||
use codex_network_proxy::NetworkDecisionSource;
|
||||
use codex_network_proxy::NetworkPolicyDecision;
|
||||
use codex_network_proxy::NetworkPolicyRequest;
|
||||
use codex_network_proxy::NetworkProtocol;
|
||||
use codex_network_proxy::environment_policy_from_config;
|
||||
use codex_protocol::config_types::ApprovalsReviewer;
|
||||
use codex_protocol::error::SandboxErr;
|
||||
use codex_protocol::models::AdditionalPermissionProfile as PermissionProfile;
|
||||
@@ -1082,7 +1082,7 @@ async fn sandbox_denied_retry_uses_the_action_policy_and_reviewer() {
|
||||
.primary()
|
||||
.expect("primary environment")
|
||||
.clone();
|
||||
environment.config_mut().network_policy = Some(EnvironmentNetworkPolicy::from_config(
|
||||
environment.config_mut().network_policy = Some(environment_policy_from_config(
|
||||
&NetworkProxyConfig {
|
||||
enabled: true,
|
||||
..Default::default()
|
||||
|
||||
@@ -474,7 +474,7 @@ async fn late_network_denial_grace_observes_cancellation_after_exit() -> anyhow:
|
||||
use crate::tools::network_approval::build_blocked_request_observer;
|
||||
use codex_network_proxy::BlockedRequest;
|
||||
use codex_network_proxy::BlockedRequestArgs;
|
||||
use codex_network_proxy::EnvironmentNetworkPolicy;
|
||||
use codex_network_proxy::environment_policy_from_config;
|
||||
use codex_tools::ToolName;
|
||||
|
||||
let (session, mut turn) = crate::session::tests::make_session_and_context().await;
|
||||
@@ -498,7 +498,7 @@ async fn late_network_denial_grace_observes_cancellation_after_exit() -> anyhow:
|
||||
codex_protocol::models::PermissionProfileSnapshot::legacy(
|
||||
codex_protocol::models::PermissionProfile::workspace_write(),
|
||||
);
|
||||
remote.config_mut().network_policy = Some(EnvironmentNetworkPolicy::from_config(
|
||||
remote.config_mut().network_policy = Some(environment_policy_from_config(
|
||||
&codex_network_proxy::NetworkProxyConfig {
|
||||
enabled: true,
|
||||
..Default::default()
|
||||
|
||||
@@ -4,6 +4,7 @@ use super::*;
|
||||
use crate::session::tests::make_session_and_context;
|
||||
use codex_network_proxy::NetworkMode;
|
||||
use codex_network_proxy::NetworkProxyConfig;
|
||||
use codex_network_proxy::environment_policy_from_config;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_protocol::models::PermissionProfileSnapshot;
|
||||
use codex_protocol::permissions::FileSystemAccessMode;
|
||||
@@ -148,7 +149,7 @@ async fn captured_network_changes_require_review() -> anyhow::Result<()> {
|
||||
);
|
||||
insta::assert_snapshot!("network_mode", permissions.approval_reason(expected)?);
|
||||
|
||||
environment.config_mut().network_policy = Some(EnvironmentNetworkPolicy::from_config(
|
||||
environment.config_mut().network_policy = Some(environment_policy_from_config(
|
||||
&proxy, /*managed_allowed_domains_only*/ false,
|
||||
));
|
||||
let current = TerminalPolicy::capture(
|
||||
|
||||
@@ -6,7 +6,6 @@ use codex_app_server_protocol as app;
|
||||
use codex_config::test_support::CloudConfigBundleFixture;
|
||||
use codex_config::types::ApprovalsReviewer;
|
||||
use codex_core::EnvironmentConfig;
|
||||
use codex_core::EnvironmentNetworkPolicy;
|
||||
use codex_core::StartThreadOptions;
|
||||
use codex_core::TurnInputRequest;
|
||||
use codex_core::config::Constrained;
|
||||
@@ -33,6 +32,7 @@ use codex_network_proxy::MitmHookConfig;
|
||||
use codex_network_proxy::MitmHookMatchConfig;
|
||||
use codex_network_proxy::NetworkProxyConfig;
|
||||
use codex_network_proxy::PROXY_ACTIVE_ENV_KEY;
|
||||
use codex_network_proxy::environment_policy_from_config;
|
||||
use codex_protocol::approvals::ExecApprovalKind;
|
||||
use codex_protocol::approvals::GuardianAssessmentAction;
|
||||
use codex_protocol::approvals::NetworkApprovalContext;
|
||||
@@ -2898,7 +2898,7 @@ async fn owner_network_policy_follows_the_selected_remote_command() -> Result<()
|
||||
use_legacy_landlock: test.config.features.use_legacy_landlock(),
|
||||
exec_policy: None,
|
||||
mcp_policy: None,
|
||||
network_policy: Some(EnvironmentNetworkPolicy::from_config(
|
||||
network_policy: Some(environment_policy_from_config(
|
||||
&proxy_config,
|
||||
/*managed_allowed_domains_only*/ suffix != "REVIEWED",
|
||||
)),
|
||||
@@ -3124,7 +3124,7 @@ async fn escalated_owner_network_terminal_requires_stdin_approval(
|
||||
use_legacy_landlock: test.config.features.use_legacy_landlock(),
|
||||
exec_policy: None,
|
||||
mcp_policy: None,
|
||||
network_policy: Some(EnvironmentNetworkPolicy::from_config(
|
||||
network_policy: Some(environment_policy_from_config(
|
||||
&proxy, /*managed_allowed_domains_only*/ true,
|
||||
)),
|
||||
selected_capability_roots: Vec::new(),
|
||||
|
||||
@@ -10,8 +10,8 @@ use base64::engine::general_purpose::STANDARD as BASE64_STANDARD;
|
||||
use codex_config::test_support::CloudConfigBundleFixture;
|
||||
use codex_core::TurnInputRequest;
|
||||
use codex_exec_server::ExecParams;
|
||||
use codex_network_proxy::EnvironmentNetworkPolicy;
|
||||
use codex_network_proxy::NetworkProxyConfig;
|
||||
use codex_network_proxy::environment_policy_from_config;
|
||||
use codex_protocol::config_types::ApprovalsReviewer;
|
||||
use codex_protocol::items::CommandExecutionStatus;
|
||||
use codex_protocol::items::TurnItem;
|
||||
@@ -291,7 +291,7 @@ mode = "full"
|
||||
);
|
||||
config.network_policy = Some(match controller {
|
||||
Some(spec) => spec.environment_policy(),
|
||||
None => EnvironmentNetworkPolicy::from_config(
|
||||
None => environment_policy_from_config(
|
||||
&NetworkProxyConfig {
|
||||
enabled: true,
|
||||
..Default::default()
|
||||
@@ -558,7 +558,7 @@ async fn interrupt_during_exec_startup_terminates_unregistered_process() -> Resu
|
||||
.await?;
|
||||
let selection = test.codex.environment_selections().await.pop().unwrap();
|
||||
let mut config = environment_config_for_selection(&test.config, &selection);
|
||||
config.network_policy = Some(EnvironmentNetworkPolicy::from_config(
|
||||
config.network_policy = Some(environment_policy_from_config(
|
||||
&NetworkProxyConfig {
|
||||
enabled: true,
|
||||
..Default::default()
|
||||
|
||||
@@ -15,7 +15,6 @@ use codex_api::AuthProvider;
|
||||
use codex_config::types::ApprovalsReviewer;
|
||||
use codex_core::CodexThreadSettingsOverrides;
|
||||
use codex_core::EnvironmentConfig;
|
||||
use codex_core::EnvironmentNetworkPolicy;
|
||||
use codex_core::StartThreadOptions;
|
||||
use codex_core::TurnInputRequest;
|
||||
use codex_core::TurnInputSubmission;
|
||||
@@ -51,6 +50,7 @@ use codex_history::RolloutItem;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
use codex_network_proxy::NetworkProxyConfig;
|
||||
use codex_network_proxy::environment_policy_from_config;
|
||||
use codex_protocol::approvals::GuardianAssessmentStatus;
|
||||
use codex_protocol::capabilities::CapabilityRootLocation;
|
||||
use codex_protocol::capabilities::SelectedCapabilityRoot;
|
||||
@@ -1900,7 +1900,7 @@ async fn owner_network_policy_rejects_unsupported_environment_authority() -> Res
|
||||
use_legacy_landlock: test.config.features.use_legacy_landlock(),
|
||||
exec_policy: None,
|
||||
mcp_policy: None,
|
||||
network_policy: Some(EnvironmentNetworkPolicy::from_config(
|
||||
network_policy: Some(environment_policy_from_config(
|
||||
&NetworkProxyConfig::default(),
|
||||
/*managed_allowed_domains_only*/ true,
|
||||
)),
|
||||
|
||||
@@ -13,7 +13,7 @@ path = "src/lib.rs"
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
codex-network-proxy = { workspace = true }
|
||||
codex-network-policy-types = { workspace = true }
|
||||
codex-protocol = { workspace = true }
|
||||
codex-utils-redacted-string = { workspace = true }
|
||||
schemars = { workspace = true }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::FeatureConfig;
|
||||
use crate::FeatureToml;
|
||||
use codex_network_proxy::CredentialProviderConfig;
|
||||
use codex_network_policy_types::CredentialProviderConfig;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_utils_redacted_string::RedactedString;
|
||||
use schemars::JsonSchema;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
load("//:defs.bzl", "codex_rust_crate")
|
||||
|
||||
codex_rust_crate(
|
||||
name = "network-policy-types",
|
||||
crate_name = "codex_network_policy_types",
|
||||
)
|
||||
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
name = "codex-network-policy-types"
|
||||
version.workspace = true
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
name = "codex_network_policy_types"
|
||||
path = "src/lib.rs"
|
||||
test = false
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
schemars = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
@@ -0,0 +1,199 @@
|
||||
//! Network policy and credential definitions shared by the protocol, configuration, and proxy.
|
||||
//! The proxy owns policy enforcement and credential validation.
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
use serde::Serializer;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// Managed proxy requirements supplied by the owner of one execution environment.
|
||||
///
|
||||
/// The owner can require proxy routing without granting direct network access.
|
||||
/// Listeners, network mode, MITM, and credentials remain controller-owned.
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EnvironmentNetworkPolicy {
|
||||
/// Requires managed proxy routing even when direct network access is restricted.
|
||||
/// False or omission leaves activation to the controller and command permissions.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub requires_proxy: bool,
|
||||
/// Route outbound TCP from managed Linux sandbox commands through the managed SOCKS5 proxy.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub transparent_tcp: bool,
|
||||
pub domains: Option<NetworkDomainPermissions>,
|
||||
/// Managed host selectors inherited by every execution in this environment.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub review_domains: Vec<String>,
|
||||
pub unix_sockets: Option<NetworkUnixSocketPermissions>,
|
||||
pub allow_upstream_proxy: bool,
|
||||
pub dangerously_allow_all_unix_sockets: bool,
|
||||
/// Omission inherits local-binding policy; an explicit false remains a restriction.
|
||||
pub allow_local_binding: Option<bool>,
|
||||
pub managed_allowed_domains_only: bool,
|
||||
}
|
||||
|
||||
/// Variant order encodes effective precedence for duplicate patterns:
|
||||
/// `None < Allow < Deny`, so deny wins over allow when entries conflict.
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NetworkDomainPermission {
|
||||
None,
|
||||
Allow,
|
||||
Deny,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct NetworkDomainPermissionEntry {
|
||||
pub pattern: String,
|
||||
pub permission: NetworkDomainPermission,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct NetworkDomainPermissions {
|
||||
pub entries: Vec<NetworkDomainPermissionEntry>,
|
||||
}
|
||||
|
||||
impl Serialize for NetworkDomainPermissions {
|
||||
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
self.effective_entries()
|
||||
.into_iter()
|
||||
.map(|entry| (entry.pattern, entry.permission))
|
||||
.collect::<BTreeMap<_, _>>()
|
||||
.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for NetworkDomainPermissions {
|
||||
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let entries = BTreeMap::<String, NetworkDomainPermission>::deserialize(deserializer)?
|
||||
.into_iter()
|
||||
.map(|(pattern, permission)| NetworkDomainPermissionEntry {
|
||||
pattern,
|
||||
permission,
|
||||
})
|
||||
.collect();
|
||||
Ok(Self { entries })
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkDomainPermissions {
|
||||
/// Resolve duplicate patterns by precedence, preserving their first-seen order.
|
||||
pub fn effective_entries(&self) -> Vec<NetworkDomainPermissionEntry> {
|
||||
let mut order = Vec::new();
|
||||
let mut effective_permissions = BTreeMap::new();
|
||||
|
||||
for entry in &self.entries {
|
||||
if !effective_permissions.contains_key(&entry.pattern) {
|
||||
order.push(entry.pattern.clone());
|
||||
}
|
||||
|
||||
let permission = effective_permissions
|
||||
.entry(entry.pattern.clone())
|
||||
.or_insert(entry.permission);
|
||||
if entry.permission > *permission {
|
||||
*permission = entry.permission;
|
||||
}
|
||||
}
|
||||
|
||||
order
|
||||
.into_iter()
|
||||
.filter_map(|pattern| {
|
||||
effective_permissions.remove(&pattern).map(|permission| {
|
||||
NetworkDomainPermissionEntry {
|
||||
pattern,
|
||||
permission,
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NetworkUnixSocketPermission {
|
||||
Allow,
|
||||
Deny,
|
||||
}
|
||||
|
||||
/// Socket policy keys are preserved across controller and executor hosts.
|
||||
/// Allow entries must be NUL-free and absolute according to the executor OS;
|
||||
/// Deny entries are retained without path validation or expansion.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
||||
pub struct NetworkUnixSocketPermissions {
|
||||
#[serde(flatten)]
|
||||
pub entries: BTreeMap<String, NetworkUnixSocketPermission>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NetworkPolicyDecision {
|
||||
Deny,
|
||||
Ask,
|
||||
}
|
||||
|
||||
impl NetworkPolicyDecision {
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Deny => "deny",
|
||||
Self::Ask => "ask",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum NetworkDecisionSource {
|
||||
BaselinePolicy,
|
||||
ModeGuard,
|
||||
ProxyState,
|
||||
Decider,
|
||||
}
|
||||
|
||||
impl NetworkDecisionSource {
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::BaselinePolicy => "baseline_policy",
|
||||
Self::ModeGuard => "mode_guard",
|
||||
Self::ProxyState => "proxy_state",
|
||||
Self::Decider => "decider",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Declarative description of an environment-backed credential family.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct CredentialProviderConfig {
|
||||
pub env: Vec<String>,
|
||||
pub patterns: Vec<String>,
|
||||
/// URL prefixes authorized for injection. Bare loopback hosts imply HTTP; other bare hosts
|
||||
/// imply HTTPS.
|
||||
pub url_prefixes: Vec<String>,
|
||||
/// Environment variable containing an additional URL prefix or hostname.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub url_prefix_from_env: Option<String>,
|
||||
pub auth: Vec<CredentialAuthMethod>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub header: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prefix: Option<String>,
|
||||
}
|
||||
|
||||
/// Authentication formats supported by declarative credential providers.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CredentialAuthMethod {
|
||||
Bearer,
|
||||
Token,
|
||||
Basic,
|
||||
Header,
|
||||
}
|
||||
@@ -23,6 +23,7 @@ aws-sigv4 = { workspace = true }
|
||||
base64 = { workspace = true }
|
||||
clap = { workspace = true, features = ["derive"] }
|
||||
chrono = { workspace = true }
|
||||
codex-network-policy-types = { workspace = true }
|
||||
codex-utils-absolute-path = { workspace = true }
|
||||
codex-utils-home-dir = { workspace = true }
|
||||
codex-utils-path-uri = { workspace = true }
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
mod standalone;
|
||||
|
||||
pub use codex_network_policy_types::NetworkDomainPermission;
|
||||
pub use codex_network_policy_types::NetworkDomainPermissionEntry;
|
||||
pub use codex_network_policy_types::NetworkDomainPermissions;
|
||||
pub use codex_network_policy_types::NetworkUnixSocketPermission;
|
||||
pub use codex_network_policy_types::NetworkUnixSocketPermissions;
|
||||
pub use standalone::StaticNetworkProxyConfig;
|
||||
|
||||
use anyhow::Context;
|
||||
@@ -7,9 +12,7 @@ use anyhow::Result;
|
||||
use anyhow::bail;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use serde::Deserialize;
|
||||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
use serde::Serializer;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
@@ -22,104 +25,6 @@ use crate::Platform;
|
||||
use crate::mitm_hook::MitmHookConfig;
|
||||
use crate::policy::normalize_host;
|
||||
|
||||
/// Variant order encodes effective precedence for duplicate patterns:
|
||||
/// `None < Allow < Deny`, so deny wins over allow when entries conflict.
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NetworkDomainPermission {
|
||||
None,
|
||||
Allow,
|
||||
Deny,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct NetworkDomainPermissionEntry {
|
||||
pub pattern: String,
|
||||
pub permission: NetworkDomainPermission,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct NetworkDomainPermissions {
|
||||
pub entries: Vec<NetworkDomainPermissionEntry>,
|
||||
}
|
||||
|
||||
impl Serialize for NetworkDomainPermissions {
|
||||
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
self.effective_entries()
|
||||
.into_iter()
|
||||
.map(|entry| (entry.pattern, entry.permission))
|
||||
.collect::<BTreeMap<_, _>>()
|
||||
.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for NetworkDomainPermissions {
|
||||
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let entries = BTreeMap::<String, NetworkDomainPermission>::deserialize(deserializer)?
|
||||
.into_iter()
|
||||
.map(|(pattern, permission)| NetworkDomainPermissionEntry {
|
||||
pattern,
|
||||
permission,
|
||||
})
|
||||
.collect();
|
||||
Ok(Self { entries })
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkDomainPermissions {
|
||||
fn effective_entries(&self) -> Vec<NetworkDomainPermissionEntry> {
|
||||
let mut order = Vec::new();
|
||||
let mut effective_permissions = BTreeMap::new();
|
||||
|
||||
for entry in &self.entries {
|
||||
if !effective_permissions.contains_key(&entry.pattern) {
|
||||
order.push(entry.pattern.clone());
|
||||
}
|
||||
|
||||
let permission = effective_permissions
|
||||
.entry(entry.pattern.clone())
|
||||
.or_insert(entry.permission);
|
||||
if entry.permission > *permission {
|
||||
*permission = entry.permission;
|
||||
}
|
||||
}
|
||||
|
||||
order
|
||||
.into_iter()
|
||||
.filter_map(|pattern| {
|
||||
effective_permissions.remove(&pattern).map(|permission| {
|
||||
NetworkDomainPermissionEntry {
|
||||
pattern,
|
||||
permission,
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NetworkUnixSocketPermission {
|
||||
Allow,
|
||||
Deny,
|
||||
}
|
||||
|
||||
/// Socket policy keys are preserved across controller and executor hosts.
|
||||
/// Allow entries must be NUL-free and absolute according to the executor OS;
|
||||
/// Deny entries are retained without path validation or expansion.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
|
||||
pub struct NetworkUnixSocketPermissions {
|
||||
#[serde(flatten)]
|
||||
pub entries: BTreeMap<String, NetworkUnixSocketPermission>,
|
||||
}
|
||||
|
||||
/// A caller-provided MITM CA for trusted proxy configuration, not sandbox `config.toml`.
|
||||
/// The private key file is readable only by the proxy process.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
|
||||
@@ -2,7 +2,6 @@ mod configured;
|
||||
mod destination;
|
||||
mod environment;
|
||||
mod matching;
|
||||
mod provider_config;
|
||||
mod providers;
|
||||
mod registry;
|
||||
mod replacement;
|
||||
@@ -26,6 +25,8 @@ use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
use url::Url;
|
||||
|
||||
pub use codex_network_policy_types::CredentialAuthMethod;
|
||||
pub use codex_network_policy_types::CredentialProviderConfig;
|
||||
pub use environment::CredentialBrokerContext;
|
||||
pub use environment::CredentialBrokerEnvironment;
|
||||
pub use environment::brokered_credential_binding_env_keys;
|
||||
@@ -37,8 +38,15 @@ pub use environment::credential_broker_provider_context_env_keys;
|
||||
pub use environment::credential_broker_provider_sources_allowed;
|
||||
pub use environment::is_credential_broker_provider_env_key;
|
||||
pub(crate) use environment::marked_credential_dummy_env_keys;
|
||||
pub use provider_config::CredentialAuthMethod;
|
||||
pub use provider_config::CredentialProviderConfig;
|
||||
|
||||
/// Validate a complete provider definition using the broker's compilation rules.
|
||||
pub fn validate_credential_provider(
|
||||
id: &str,
|
||||
config: &CredentialProviderConfig,
|
||||
) -> anyhow::Result<()> {
|
||||
configured::ConfiguredCredentialProvider::compile(id, config)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub const CREDENTIAL_BROKER_ACTIVE_ENV_KEY: &str = "CODEX_NETWORK_PROXY_CREDENTIAL_BROKER_ACTIVE";
|
||||
pub(crate) const BROKERED_CREDENTIALS_ENV_KEY: &str = "CODEX_NETWORK_PROXY_BROKERED_CREDENTIALS";
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
/// Declarative description of an environment-backed credential family.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct CredentialProviderConfig {
|
||||
pub env: Vec<String>,
|
||||
pub patterns: Vec<String>,
|
||||
/// URL prefixes authorized for injection. Bare loopback hosts imply HTTP; other bare hosts
|
||||
/// imply HTTPS.
|
||||
pub url_prefixes: Vec<String>,
|
||||
/// Environment variable containing an additional URL prefix or hostname.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub url_prefix_from_env: Option<String>,
|
||||
pub auth: Vec<CredentialAuthMethod>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub header: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prefix: Option<String>,
|
||||
}
|
||||
|
||||
impl CredentialProviderConfig {
|
||||
/// Validate a complete provider definition using the broker's compilation rules.
|
||||
pub fn validate(&self, id: &str) -> anyhow::Result<()> {
|
||||
super::configured::ConfiguredCredentialProvider::compile(id, self)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Authentication formats supported by declarative credential providers.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CredentialAuthMethod {
|
||||
Bearer,
|
||||
Token,
|
||||
Basic,
|
||||
Header,
|
||||
}
|
||||
@@ -1,121 +1,97 @@
|
||||
use crate::NetworkDomainPermissions;
|
||||
//! Project proxy settings into environment policies and compose them with controller restrictions.
|
||||
|
||||
use crate::EnvironmentNetworkPolicy;
|
||||
use crate::NetworkProxyConfig;
|
||||
use crate::NetworkUnixSocketPermission;
|
||||
use crate::NetworkUnixSocketPermissions;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
/// Managed proxy requirements supplied by the owner of one execution environment.
|
||||
///
|
||||
/// The owner can require proxy routing without granting direct network access.
|
||||
/// Listeners, network mode, MITM, and credentials remain controller-owned.
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EnvironmentNetworkPolicy {
|
||||
/// Requires managed proxy routing even when direct network access is restricted.
|
||||
/// False or omission leaves activation to the controller and command permissions.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub requires_proxy: bool,
|
||||
/// Route outbound TCP from managed Linux sandbox commands through the managed SOCKS5 proxy.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub transparent_tcp: bool,
|
||||
pub domains: Option<NetworkDomainPermissions>,
|
||||
/// Managed host selectors inherited by every execution in this environment.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub review_domains: Vec<String>,
|
||||
pub unix_sockets: Option<NetworkUnixSocketPermissions>,
|
||||
pub allow_upstream_proxy: bool,
|
||||
pub dangerously_allow_all_unix_sockets: bool,
|
||||
/// Omission inherits local-binding policy; an explicit false remains a restriction.
|
||||
pub allow_local_binding: Option<bool>,
|
||||
pub managed_allowed_domains_only: bool,
|
||||
}
|
||||
|
||||
impl EnvironmentNetworkPolicy {
|
||||
/// Captures proxy activation and traffic restrictions without controller runtime settings.
|
||||
pub fn from_config(config: &NetworkProxyConfig, managed_allowed_domains_only: bool) -> Self {
|
||||
Self {
|
||||
requires_proxy: config.enabled,
|
||||
transparent_tcp: config.transparent_tcp,
|
||||
domains: config.domains.clone(),
|
||||
review_domains: config.review_domains.clone(),
|
||||
unix_sockets: config.unix_sockets.clone(),
|
||||
allow_upstream_proxy: config.allow_upstream_proxy,
|
||||
dangerously_allow_all_unix_sockets: config
|
||||
.dangerously_allow_all_unix_sockets
|
||||
.unwrap_or(false),
|
||||
allow_local_binding: config.allow_local_binding,
|
||||
managed_allowed_domains_only,
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies attachment-owned traffic settings while preserving inherited denials and proxy setup.
|
||||
pub fn apply_to(&self, config: &mut NetworkProxyConfig) {
|
||||
config.transparent_tcp |= self.transparent_tcp;
|
||||
// Neither owner nor controller may remove the other's review selectors.
|
||||
for pattern in &self.review_domains {
|
||||
if !config
|
||||
.review_domains
|
||||
.iter()
|
||||
.any(|existing| existing.eq_ignore_ascii_case(pattern))
|
||||
{
|
||||
config.review_domains.push(pattern.clone());
|
||||
}
|
||||
}
|
||||
// Use the owner's domain rules without dropping controller denials.
|
||||
let inherited_denials = config.denied_domains().unwrap_or_default();
|
||||
config.domains.clone_from(&self.domains);
|
||||
for domain in inherited_denials {
|
||||
config.upsert_domain_permission(
|
||||
domain,
|
||||
crate::NetworkDomainPermission::Deny,
|
||||
crate::normalize_host,
|
||||
);
|
||||
}
|
||||
// An omitted controller policy leaves socket permissions to the attachment;
|
||||
// an explicitly empty socket map still supplies a restrictive ceiling.
|
||||
let inherited_allow_all = config
|
||||
/// Captures proxy activation and traffic restrictions without controller runtime settings.
|
||||
pub fn environment_policy_from_config(
|
||||
config: &NetworkProxyConfig,
|
||||
managed_allowed_domains_only: bool,
|
||||
) -> EnvironmentNetworkPolicy {
|
||||
EnvironmentNetworkPolicy {
|
||||
requires_proxy: config.enabled,
|
||||
transparent_tcp: config.transparent_tcp,
|
||||
domains: config.domains.clone(),
|
||||
review_domains: config.review_domains.clone(),
|
||||
unix_sockets: config.unix_sockets.clone(),
|
||||
allow_upstream_proxy: config.allow_upstream_proxy,
|
||||
dangerously_allow_all_unix_sockets: config
|
||||
.dangerously_allow_all_unix_sockets
|
||||
.unwrap_or(config.unix_sockets.is_none());
|
||||
let inherited_sockets = config.unix_sockets.take().unwrap_or_default();
|
||||
let mut effective_sockets = self.unix_sockets.clone().unwrap_or_default();
|
||||
|
||||
// "Allow all" cannot override a socket denied by either policy.
|
||||
let inherited_permits_all = inherited_allow_all
|
||||
&& !inherited_sockets
|
||||
.entries
|
||||
.values()
|
||||
.any(|permission| matches!(permission, NetworkUnixSocketPermission::Deny));
|
||||
let owner_permits_all = self.dangerously_allow_all_unix_sockets
|
||||
&& !effective_sockets
|
||||
.entries
|
||||
.values()
|
||||
.any(|permission| matches!(permission, NetworkUnixSocketPermission::Deny));
|
||||
|
||||
// Keep shared socket grants; controller denials always take priority.
|
||||
effective_sockets.entries.retain(|path, permission| {
|
||||
matches!(permission, NetworkUnixSocketPermission::Deny)
|
||||
|| inherited_permits_all
|
||||
|| matches!(
|
||||
inherited_sockets.entries.get(path),
|
||||
Some(NetworkUnixSocketPermission::Allow)
|
||||
)
|
||||
});
|
||||
for (path, permission) in inherited_sockets.entries {
|
||||
if owner_permits_all || matches!(permission, NetworkUnixSocketPermission::Deny) {
|
||||
effective_sockets.entries.insert(path, permission);
|
||||
}
|
||||
}
|
||||
|
||||
// Socket and upstream-proxy permissions require both controller and owner grants.
|
||||
config.unix_sockets = (!effective_sockets.entries.is_empty()).then_some(effective_sockets);
|
||||
config.dangerously_allow_all_unix_sockets =
|
||||
Some(inherited_permits_all && owner_permits_all);
|
||||
config.allow_upstream_proxy &= self.allow_upstream_proxy;
|
||||
// Either explicit denial wins; defer unresolved defaults to the executor.
|
||||
config.allow_local_binding = match (config.allow_local_binding, self.allow_local_binding) {
|
||||
(Some(controller), Some(owner)) => Some(controller && owner),
|
||||
(controller, owner) => controller.or(owner),
|
||||
};
|
||||
.unwrap_or(false),
|
||||
allow_local_binding: config.allow_local_binding,
|
||||
managed_allowed_domains_only,
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies attachment-owned traffic settings while preserving inherited denials and proxy setup.
|
||||
pub fn apply_environment_policy(
|
||||
policy: &EnvironmentNetworkPolicy,
|
||||
config: &mut NetworkProxyConfig,
|
||||
) {
|
||||
config.transparent_tcp |= policy.transparent_tcp;
|
||||
// Neither owner nor controller may remove the other's review selectors.
|
||||
for pattern in &policy.review_domains {
|
||||
if !config
|
||||
.review_domains
|
||||
.iter()
|
||||
.any(|existing| existing.eq_ignore_ascii_case(pattern))
|
||||
{
|
||||
config.review_domains.push(pattern.clone());
|
||||
}
|
||||
}
|
||||
// Use the owner's domain rules without dropping controller denials.
|
||||
let inherited_denials = config.denied_domains().unwrap_or_default();
|
||||
config.domains.clone_from(&policy.domains);
|
||||
for domain in inherited_denials {
|
||||
config.upsert_domain_permission(
|
||||
domain,
|
||||
crate::NetworkDomainPermission::Deny,
|
||||
crate::normalize_host,
|
||||
);
|
||||
}
|
||||
// An omitted controller policy leaves socket permissions to the attachment;
|
||||
// an explicitly empty socket map still supplies a restrictive ceiling.
|
||||
let inherited_allow_all = config
|
||||
.dangerously_allow_all_unix_sockets
|
||||
.unwrap_or(config.unix_sockets.is_none());
|
||||
let inherited_sockets = config.unix_sockets.take().unwrap_or_default();
|
||||
let mut effective_sockets = policy.unix_sockets.clone().unwrap_or_default();
|
||||
|
||||
// "Allow all" cannot override a socket denied by either policy.
|
||||
let inherited_permits_all = inherited_allow_all
|
||||
&& !inherited_sockets
|
||||
.entries
|
||||
.values()
|
||||
.any(|permission| matches!(permission, NetworkUnixSocketPermission::Deny));
|
||||
let owner_permits_all = policy.dangerously_allow_all_unix_sockets
|
||||
&& !effective_sockets
|
||||
.entries
|
||||
.values()
|
||||
.any(|permission| matches!(permission, NetworkUnixSocketPermission::Deny));
|
||||
|
||||
// Keep shared socket grants; controller denials always take priority.
|
||||
effective_sockets.entries.retain(|path, permission| {
|
||||
matches!(permission, NetworkUnixSocketPermission::Deny)
|
||||
|| inherited_permits_all
|
||||
|| matches!(
|
||||
inherited_sockets.entries.get(path),
|
||||
Some(NetworkUnixSocketPermission::Allow)
|
||||
)
|
||||
});
|
||||
for (path, permission) in inherited_sockets.entries {
|
||||
if owner_permits_all || matches!(permission, NetworkUnixSocketPermission::Deny) {
|
||||
effective_sockets.entries.insert(path, permission);
|
||||
}
|
||||
}
|
||||
|
||||
// Socket and upstream-proxy permissions require both controller and owner grants.
|
||||
config.unix_sockets = (!effective_sockets.entries.is_empty()).then_some(effective_sockets);
|
||||
config.dangerously_allow_all_unix_sockets = Some(inherited_permits_all && owner_permits_all);
|
||||
config.allow_upstream_proxy &= policy.allow_upstream_proxy;
|
||||
// Either explicit denial wins; defer unresolved defaults to the executor.
|
||||
config.allow_local_binding = match (config.allow_local_binding, policy.allow_local_binding) {
|
||||
(Some(controller), Some(owner)) => Some(controller && owner),
|
||||
(controller, owner) => controller.or(owner),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ pub use aws_sigv4::ProxySecretSource;
|
||||
pub use certs::CHILD_ONLY_CA_ENV_KEYS;
|
||||
pub use certs::CUSTOM_CA_ENV_KEYS;
|
||||
pub use certs::is_managed_mitm_ca_trust_bundle_path;
|
||||
pub use codex_network_policy_types::EnvironmentNetworkPolicy;
|
||||
pub use codex_utils_path_uri::Platform;
|
||||
pub use config::NetworkDomainPermission;
|
||||
pub use config::NetworkDomainPermissionEntry;
|
||||
@@ -73,10 +74,12 @@ pub use credential_broker::brokered_credential_value_env_keys;
|
||||
pub use credential_broker::credential_broker_provider_context_env_keys;
|
||||
pub use credential_broker::credential_broker_provider_sources_allowed;
|
||||
pub use credential_broker::is_credential_broker_provider_env_key;
|
||||
pub use credential_broker::validate_credential_provider;
|
||||
pub use domain_matcher::canonical_allow_pattern;
|
||||
pub use domain_matcher::canonical_deny_pattern;
|
||||
pub use domain_matcher::canonical_review_pattern;
|
||||
pub use environment_policy::EnvironmentNetworkPolicy;
|
||||
pub use environment_policy::apply_environment_policy;
|
||||
pub use environment_policy::environment_policy_from_config;
|
||||
pub use mitm_hook::InjectedHeaderConfig;
|
||||
pub use mitm_hook::MitmHookActionsConfig;
|
||||
pub use mitm_hook::MitmHookBodyConfig;
|
||||
|
||||
@@ -8,6 +8,8 @@ use crate::state::NetworkProxyState;
|
||||
use anyhow::Result;
|
||||
use chrono::SecondsFormat;
|
||||
use chrono::Utc;
|
||||
pub use codex_network_policy_types::NetworkDecisionSource;
|
||||
pub use codex_network_policy_types::NetworkPolicyDecision;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
@@ -62,42 +64,6 @@ impl NetworkProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NetworkPolicyDecision {
|
||||
Deny,
|
||||
Ask,
|
||||
}
|
||||
|
||||
impl NetworkPolicyDecision {
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Deny => "deny",
|
||||
Self::Ask => "ask",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum NetworkDecisionSource {
|
||||
BaselinePolicy,
|
||||
ModeGuard,
|
||||
ProxyState,
|
||||
Decider,
|
||||
}
|
||||
|
||||
impl NetworkDecisionSource {
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::BaselinePolicy => "baseline_policy",
|
||||
Self::ModeGuard => "mode_guard",
|
||||
Self::ProxyState => "proxy_state",
|
||||
Self::Decider => "decider",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct NetworkPolicyRequest {
|
||||
pub protocol: NetworkProtocol,
|
||||
|
||||
@@ -1103,7 +1103,7 @@ impl NetworkProxy {
|
||||
}
|
||||
}
|
||||
if let Some(policy) = environment_policy {
|
||||
policy.apply_to(&mut config);
|
||||
crate::apply_environment_policy(policy, &mut config);
|
||||
}
|
||||
config.allow_local_binding = Some(local_binding_policy.resolve(&config));
|
||||
anyhow::ensure!(
|
||||
@@ -2138,7 +2138,7 @@ mod tests {
|
||||
"remote",
|
||||
"execution-1",
|
||||
"token-1".to_string(),
|
||||
Some(crate::EnvironmentNetworkPolicy::from_config(
|
||||
Some(crate::environment_policy_from_config(
|
||||
&owner_config,
|
||||
/*managed_allowed_domains_only*/ false,
|
||||
)),
|
||||
@@ -2195,7 +2195,7 @@ mod tests {
|
||||
"owner-environment",
|
||||
"execution-3",
|
||||
"token-3".to_string(),
|
||||
Some(crate::EnvironmentNetworkPolicy::from_config(
|
||||
Some(crate::environment_policy_from_config(
|
||||
&owner_config,
|
||||
/*managed_allowed_domains_only*/ true,
|
||||
)),
|
||||
@@ -2716,7 +2716,7 @@ mod tests {
|
||||
"remote-env",
|
||||
"execution-2",
|
||||
"token-2".to_string(),
|
||||
Some(crate::EnvironmentNetworkPolicy::from_config(
|
||||
Some(crate::environment_policy_from_config(
|
||||
&owner_config,
|
||||
/*managed_allowed_domains_only*/ false,
|
||||
)),
|
||||
|
||||
@@ -19,7 +19,7 @@ codex-async-utils = { workspace = true }
|
||||
codex-execpolicy-rules = { workspace = true }
|
||||
codex-extension-items = { workspace = true }
|
||||
codex-http-client = { workspace = true }
|
||||
codex-network-proxy = { workspace = true }
|
||||
codex-network-policy-types = { workspace = true }
|
||||
codex-utils-absolute-path = { workspace = true }
|
||||
codex-utils-cached-str = { workspace = true }
|
||||
codex-utils-image = { workspace = true }
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::models::PermissionProfileSnapshot;
|
||||
use crate::protocol::AskForApproval;
|
||||
use crate::sandbox::SandboxType;
|
||||
use codex_execpolicy_rules::RequirementsExecPolicy;
|
||||
use codex_network_proxy::EnvironmentNetworkPolicy;
|
||||
use codex_network_policy_types::EnvironmentNetworkPolicy;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::approvals::NetworkApprovalProtocol;
|
||||
use codex_network_proxy::NetworkDecisionSource;
|
||||
use codex_network_proxy::NetworkPolicyDecision;
|
||||
use codex_network_policy_types::NetworkDecisionSource;
|
||||
use codex_network_policy_types::NetworkPolicyDecision;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
||||
|
||||
Reference in New Issue
Block a user