mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Restrict enterprise MCP auth and fail closed on config refresh (#49260)
## Why Configuration reloads must honor current managed restrictions without granting new enterprise MCP authority to existing sessions or overwriting newer configuration with stale snapshots. ## What changed - Allow enterprise managed authentication only for configured MCP servers. Remove plugin `ema_auth` overlays from the schema and disable servers that still use them. - Refresh ordinary MCP settings while preserving session settings and initially admitted enterprise registrations. Disable enterprise MCP when its registration changes, policy revokes access, or configuration loading or resolution fails; require a new session to restore enterprise authority. - Publish refreshes only when their captured configuration is still current, with bounded retries in app-server reloads. Preserve updated managed restrictions even when a refresh is rejected. - Finish processing other thread refreshes before `config/mcpServer/reload` reports a rejection, and document that an error can accompany partially applied changes. ## Testing Add regression coverage for stale refreshes, bounded retries, managed-policy revocation, persistent enterprise disablement, ordinary MCP transport changes, and rejection of plugin enterprise authentication. Verify that denied enterprise servers receive no requests. GitOrigin-RevId: 34429cd339c1ec152a2ee8697cb29f0cff5d9e5f
This commit is contained in:
@@ -966,9 +966,9 @@ async fn load_plugin(
|
||||
}
|
||||
|
||||
fn apply_plugin_mcp_server_policy(config: &mut McpServerConfig, policy: &PluginMcpServerConfig) {
|
||||
config.enabled = policy.enabled;
|
||||
if let Some(ema) = &policy.ema_auth {
|
||||
ema.apply(config);
|
||||
config.enabled = policy.enabled && !policy.has_unsupported_ema_auth;
|
||||
if policy.has_unsupported_ema_auth {
|
||||
config.auth = codex_config::McpServerAuth::EmaAuth;
|
||||
}
|
||||
if let Some(approval_mode) = policy.default_tools_approval_mode {
|
||||
config.default_tools_approval_mode = Some(approval_mode);
|
||||
@@ -1437,9 +1437,9 @@ pub fn apply_configured_plugin_mcp_server_policies(
|
||||
) {
|
||||
for (name, server) in servers {
|
||||
if let Some(policy) = policies.get(name) {
|
||||
server.enabled &= policy.enabled;
|
||||
if let Some(ema) = &policy.ema_auth {
|
||||
ema.apply(server);
|
||||
server.enabled &= policy.enabled && !policy.has_unsupported_ema_auth;
|
||||
if policy.has_unsupported_ema_auth {
|
||||
server.auth = codex_config::McpServerAuth::EmaAuth;
|
||||
}
|
||||
let declared_approval_mode = server.default_tools_approval_mode.unwrap_or_default();
|
||||
|
||||
|
||||
@@ -27,102 +27,6 @@ fn user_layer(path: AbsolutePathBuf, config: &str) -> ConfigLayerEntry {
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn ema_policy_overlays_native_and_agent_plugins_without_changing_endpoints() {
|
||||
let temp_dir = TempDir::new().expect("tempdir");
|
||||
let policy_config = r#"
|
||||
[plugins."sample@test".mcp_servers.example]
|
||||
enabled = true
|
||||
[plugins."sample@test".mcp_servers.example.ema_auth]
|
||||
url = "https://resource.example/mcp"
|
||||
client_id = "resource-client"
|
||||
authorization_server_issuer = "https://as.example"
|
||||
resource = "https://resource.example"
|
||||
scopes = ["tools"]
|
||||
"#;
|
||||
let stack = ConfigLayerStack::new(
|
||||
vec![ConfigLayerEntry::new(
|
||||
ConfigLayerSource::EnterpriseManaged {
|
||||
id: "ema-policy".to_string(),
|
||||
name: "EMA policy".to_string(),
|
||||
},
|
||||
toml::from_str(policy_config).expect("managed policy toml"),
|
||||
)],
|
||||
ConfigRequirements::default(),
|
||||
ConfigRequirementsToml::default(),
|
||||
)
|
||||
.expect("valid trusted policy stack");
|
||||
let policies = configured_plugins_from_stack(&stack, temp_dir.path())
|
||||
.remove("sample@test")
|
||||
.expect("configured plugin")
|
||||
.mcp_servers;
|
||||
|
||||
for (name, manifest_path, manifest, mcp_path, mcp) in [
|
||||
(
|
||||
"native",
|
||||
".codex-plugin/plugin.json",
|
||||
r#"{"name":"native"}"#,
|
||||
".mcp.json",
|
||||
r#"{"mcpServers":{"example":{"url":"https://resource.example/mcp"}}}"#,
|
||||
),
|
||||
(
|
||||
"agent",
|
||||
"plugin.json",
|
||||
r#"{"$schema":"https://agent-plugins.org/schemas/1.0.0/plugin.schema.json","name":"agent"}"#,
|
||||
"mcp.json",
|
||||
r#"{"$schema":"https://agent-plugins.org/schemas/1.0.0/mcp.schema.json","mcpServers":{"example":{"type":"streamable-http","url":"https://resource.example/mcp"}}}"#,
|
||||
),
|
||||
] {
|
||||
for endpoint in [
|
||||
"https://resource.example/mcp",
|
||||
"https://resource.example/mcp/other",
|
||||
"https://resource.example/mcp?tenant=other",
|
||||
"https://other.example/mcp",
|
||||
] {
|
||||
let root = temp_dir.path().join(name);
|
||||
write_file(&root.join(manifest_path), manifest);
|
||||
write_file(
|
||||
&root.join(mcp_path),
|
||||
&mcp.replace("https://resource.example/mcp", endpoint),
|
||||
);
|
||||
let declared = load_plugin_mcp_servers(&root, /*auth_mode*/ None).await;
|
||||
let transport = declared["example"].transport.clone();
|
||||
let installed = load_plugin_mcp_servers_with_policy(
|
||||
&root,
|
||||
/*auth_mode*/ None,
|
||||
Some(&policies),
|
||||
)
|
||||
.await;
|
||||
let mut selected = declared;
|
||||
apply_configured_plugin_mcp_server_policies(&policies, &mut selected);
|
||||
assert_eq!(installed, selected);
|
||||
let server = &selected["example"];
|
||||
assert_eq!(server.transport, transport);
|
||||
assert_eq!(server.enabled, endpoint == "https://resource.example/mcp");
|
||||
assert_eq!(server.auth, codex_config::McpServerAuth::EmaAuth);
|
||||
assert_eq!(
|
||||
server.oauth,
|
||||
Some(codex_config::McpServerOAuthConfig {
|
||||
client_id: Some("resource-client".into()),
|
||||
authorization_server_issuer: Some("https://as.example".into()),
|
||||
ema_registration_error: (endpoint != "https://resource.example/mcp")
|
||||
.then_some("plugin endpoint does not match its EMA registration"),
|
||||
..Default::default()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
server.oauth_resource.as_deref(),
|
||||
Some("https://resource.example")
|
||||
);
|
||||
assert_eq!(
|
||||
server.scopes.as_deref(),
|
||||
Some(["tools".to_string()].as_slice())
|
||||
);
|
||||
assert_eq!(server.oauth_idp(), None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn agent_plugin_overlay_apps_are_not_runtime_active() {
|
||||
let temp_dir = TempDir::new().expect("tempdir");
|
||||
@@ -492,6 +396,54 @@ fn configured_plugins_from_stack_merges_enabled_effective_layers() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn legacy_ema_policy_disables_installed_and_selected_plugin_servers() {
|
||||
let temp_dir = TempDir::new().expect("tempdir");
|
||||
let plugin_root = temp_dir.path().join("plugin");
|
||||
write_file(
|
||||
&plugin_root.join(".codex-plugin/plugin.json"),
|
||||
r#"{"name":"plugin","mcpServers":"./mcp.json"}"#,
|
||||
);
|
||||
write_file(
|
||||
&plugin_root.join("mcp.json"),
|
||||
r#"{"mcpServers":{"example":{"url":"https://resource.example/mcp"}}}"#,
|
||||
);
|
||||
for endpoint in ["https://resource.example/mcp", "https://other.example/mcp"] {
|
||||
let stack = ConfigLayerStack::new(
|
||||
vec![user_layer(
|
||||
user_config_path(&temp_dir, "config.toml"),
|
||||
&format!(
|
||||
"[plugins.\"plugin@market\".mcp_servers.example.ema_auth]\nurl = '{endpoint}'"
|
||||
),
|
||||
)],
|
||||
ConfigRequirements::default(),
|
||||
ConfigRequirementsToml::default(),
|
||||
)
|
||||
.expect("legacy policy stack");
|
||||
let policies = configured_plugin_mcp_server_policies(&stack);
|
||||
let policy = policies.get("plugin@market").expect("plugin policy");
|
||||
let installed = load_plugin_mcp_servers_with_policy(
|
||||
&plugin_root,
|
||||
/*auth_mode*/ None,
|
||||
Some(policy),
|
||||
)
|
||||
.await;
|
||||
let mut selected = load_plugin_mcp_servers(&plugin_root, /*auth_mode*/ None).await;
|
||||
assert!(selected["example"].enabled);
|
||||
apply_configured_plugin_mcp_server_policies(policy, &mut selected);
|
||||
assert!(!installed["example"].enabled);
|
||||
assert_eq!(installed, selected);
|
||||
|
||||
let round_trip: HashMap<String, PluginMcpServerConfig> =
|
||||
toml::from_str(&toml::to_string(policy).expect("serialize policy"))
|
||||
.expect("deserialize policy");
|
||||
assert_eq!(
|
||||
&round_trip, policy,
|
||||
"serialization must preserve the denial"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn hooks_only_scope_shares_plugin_resolution_without_loading_other_capabilities() {
|
||||
let temp_dir = TempDir::new().expect("tempdir");
|
||||
|
||||
Reference in New Issue
Block a user