mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:22:05 +00:00
Enforce environment MCP policies (#39335)
## What changed - Add environment-provided MCP restrictions for configured and plugin-provided servers. - Disable attachment-scoped servers while their environment configuration is pending, failed, or unselected, while preserving selected-plugin access and the controller-owned Apps server. - Apply the resolved policy to runtime startup, model tool exposure, telemetry, OAuth flows, and skill dependency installation. ## Testing - Cover policy filtering for configured and plugin servers, environment state transitions, Apps ownership, and managed OAuth rejection. GitOrigin-RevId: 7ca5d4dda14068e758497f88835d5cba685e159e
This commit is contained in:
1 parent
d35e5495f9
commit
fde2156057
36 files changed
+650
-88
No files matched your search
@@ -1,3 +1,4 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -6,8 +7,13 @@ use codex_config::DEFAULT_MCP_SERVER_ENVIRONMENT_ID;
|
||||
use codex_config::McpServerConfig;
|
||||
use codex_config::McpServerToolConfig;
|
||||
use codex_config::McpServerTransportConfig;
|
||||
use codex_protocol::mcp_policy::EnvironmentMcpPolicy;
|
||||
use codex_protocol::mcp_policy::PluginMcpRequirements;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::CODEX_APPS_MCP_SERVER_NAME;
|
||||
|
||||
use super::McpEnvironmentAuthority;
|
||||
use super::McpPluginAttribution;
|
||||
use super::McpServerConflict;
|
||||
use super::McpServerConflictAction;
|
||||
@@ -65,7 +71,10 @@ fn compatibility_source(id: &str) -> McpServerSource {
|
||||
}
|
||||
|
||||
fn extension_source(id: &str) -> McpServerSource {
|
||||
McpServerSource::Extension { id: id.to_string() }
|
||||
McpServerSource::Extension {
|
||||
id: id.to_string(),
|
||||
host_owned_apps: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn register(source: McpServerSource) -> McpServerConflictAction {
|
||||
@@ -117,6 +126,7 @@ fn source_precedence_preserves_the_winning_registration() {
|
||||
resolved.source(),
|
||||
&McpServerSource::Extension {
|
||||
id: "hosted".to_string(),
|
||||
host_owned_apps: false,
|
||||
}
|
||||
);
|
||||
assert_eq!(resolved.config(), &extension);
|
||||
@@ -407,3 +417,79 @@ fn equal_precedence_uses_insertion_order_not_source_identity() {
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn environment_policy_exempts_only_explicitly_host_owned_apps() {
|
||||
let policy = EnvironmentMcpPolicy {
|
||||
servers: Some(BTreeMap::new()),
|
||||
plugins: None,
|
||||
};
|
||||
for (registration, expected) in [
|
||||
(
|
||||
McpServerRegistration::from_extension(
|
||||
CODEX_APPS_MCP_SERVER_NAME.to_string(),
|
||||
"apps",
|
||||
/*contribution_order*/ 0,
|
||||
server("https://apps.example/mcp"),
|
||||
),
|
||||
false,
|
||||
),
|
||||
(
|
||||
McpServerRegistration::from_hosted_apps(
|
||||
"apps",
|
||||
/*contribution_order*/ 0,
|
||||
server("https://apps.example/mcp"),
|
||||
),
|
||||
true,
|
||||
),
|
||||
] {
|
||||
let mut builder = ResolvedMcpCatalog::builder();
|
||||
builder.register(registration);
|
||||
let catalog = builder
|
||||
.build_with_environment_authority(|_| McpEnvironmentAuthority::Restricted(&policy));
|
||||
assert_eq!(
|
||||
catalog
|
||||
.server(CODEX_APPS_MCP_SERVER_NAME)
|
||||
.expect("Apps registration")
|
||||
.config()
|
||||
.enabled,
|
||||
expected
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn environment_policy_preserves_selected_plugin_and_empty_server_allowlist_semantics() {
|
||||
let mut builder = ResolvedMcpCatalog::builder();
|
||||
builder.register(McpServerRegistration::from_selected_plugin(
|
||||
"selected".to_string(),
|
||||
plugin("selected-plugin"),
|
||||
/*selection_order*/ 0,
|
||||
server("https://plugin.example/mcp"),
|
||||
));
|
||||
let metadata_only_policy = EnvironmentMcpPolicy {
|
||||
servers: None,
|
||||
plugins: Some(BTreeMap::from([(
|
||||
"metadata-only-plugin".to_string(),
|
||||
PluginMcpRequirements { mcp_servers: None },
|
||||
)])),
|
||||
};
|
||||
let deny_all_policy = EnvironmentMcpPolicy {
|
||||
servers: Some(BTreeMap::new()),
|
||||
plugins: None,
|
||||
};
|
||||
|
||||
for (policy, expected) in [(&metadata_only_policy, true), (&deny_all_policy, false)] {
|
||||
let resolved = builder
|
||||
.clone()
|
||||
.build_with_environment_authority(|_| McpEnvironmentAuthority::Restricted(policy));
|
||||
assert_eq!(
|
||||
resolved
|
||||
.server("selected")
|
||||
.expect("selected plugin")
|
||||
.config()
|
||||
.enabled,
|
||||
expected
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user