Honor attachment-owned permissions for MCP servers (#40728)

## Why

MCP servers attached to executor environments must retain their owner's
permission profile instead of inheriting the thread-wide sandbox authority.

## What changed

- Resolve and capture a permission profile for each enabled MCP server when
  publishing the runtime, and reject calls or elicitations when that authority
  is unavailable.
- Use the captured server profile for tool approval decisions, elicitation, and
  sandbox metadata, including after runtime refreshes.
- Materialize `:workspace_roots` from `PathUri` values so permissions preserve
  the path convention of remote executor environments.
- Give threadless app discovery and resource reads an explicit default
  permission profile.

## Testing

Added coverage for per-server elicitation authority, unresolved attachments,
runtime refreshes, restricted tool calls, and foreign-platform workspace roots.

GitOrigin-RevId: 6b188d4b08b29e9971ff7aa68a7785a0cdf9e394
This commit is contained in:
sayan-oai authored and copyberry committed 2026-08-25 22:50:49 +00:00
1 parent 0b94751cc4
commit 4213b38f3c
25 files changed
+805 -136

No files matched your search

+57
View File
@@ -16,6 +16,7 @@ use pretty_assertions::assert_eq;
use std::collections::HashMap;
use std::collections::HashSet;
use std::path::PathBuf;
use std::sync::Arc;
pub(crate) fn test_mcp_config(codex_home: PathBuf) -> McpConfig {
McpConfig {
@@ -32,6 +33,7 @@ pub(crate) fn test_mcp_config(codex_home: PathBuf) -> McpConfig {
config_layer_stack: codex_config::ConfigLayerStack::default(),
approvals_reviewer: codex_config::types::ApprovalsReviewer::default(),
environment_cwds: HashMap::new(),
server_permission_profiles: HashMap::new(),
codex_linux_sandbox_exe: None,
use_legacy_landlock: false,
apps_enabled: false,
@@ -44,6 +46,20 @@ pub(crate) fn test_mcp_config(codex_home: PathBuf) -> McpConfig {
}
}
pub(crate) fn test_elicitation_config(
server_name: &str,
approval_policy: AskForApproval,
permission_profile: PermissionProfile,
) -> Arc<McpConfig> {
let mut config = test_mcp_config(PathBuf::new());
config.approval_policy = Constrained::allow_any(approval_policy);
config.permission_profile = permission_profile.clone();
config
.server_permission_profiles
.insert(server_name.to_string(), permission_profile);
Arc::new(config)
}
#[test]
fn qualified_mcp_tool_name_prefix_sanitizes_server_names_without_lowercasing() {
assert_eq!(
@@ -52,6 +68,47 @@ fn qualified_mcp_tool_name_prefix_sanitizes_server_names_without_lowercasing() {
);
}
#[test]
fn mcp_server_permissions_handle_unattached_and_threadless_servers() {
let mut config = test_mcp_config(PathBuf::new());
config.permission_profile = PermissionProfile::Disabled;
let mut missing_server = codex_apps_mcp_server_config(
"https://example.com",
/*apps_mcp_product_sku*/ None,
/*originator*/ None,
);
missing_server.environment_id = "missing".to_string();
let mut selected_server = missing_server.clone();
selected_server.environment_id = "unattached".to_string();
let mut catalog = ResolvedMcpCatalog::builder();
catalog.register(McpServerRegistration::from_config(
"missing".to_string(),
missing_server,
));
catalog.register(McpServerRegistration::from_selected_plugin(
"selected".to_string(),
McpPluginAttribution::new("selected@test".to_string(), "Selected".to_string()),
/*selection_order*/ 0,
selected_server,
));
config.mcp_server_catalog = catalog.build();
let servers = effective_mcp_servers(&config, /*auth*/ None);
assert_eq!(config.permission_profile_for_server("selected"), None);
config.set_server_permission_profiles(&servers, std::iter::empty());
assert_eq!(
config.permission_profile_for_server("selected"),
Some(&PermissionProfile::Disabled)
);
assert_eq!(config.permission_profile_for_server("missing"), None);
let config = config.for_threadless_operations(&servers);
assert_eq!(
config.permission_profile_for_server("selected"),
Some(&PermissionProfile::default())
);
}
#[test]
fn mcp_prompt_auto_approval_honors_unrestricted_managed_profiles() {
assert!(mcp_permission_prompt_is_auto_approved(