mirror of
https://github.com/openai/codex.git
synced 2026-12-04 00:51:02 +00:00
## Why Cached executor MCP declarations must not gain access to host environment credentials when reconnecting to an executor that lacks environment credential resolution. ## What changed - Retain credential policy through MCP registration, catalog materialization, and runtime setup. Derive selected HTTP plugin policy from the plugin's source environment. - Reject host bearer-token fallback and transports requiring host environment headers or helpers for executor-owned declarations. Preserve host-configured credential resolution. - Include credential policy in connection and tool catalog cache identities, and avoid reading host environment values for executor-only identities. ## Testing Add regression coverage for legacy executors, cached declarations after a capability downgrade, policy preservation through catalog rebuilds, and connection and tool cache isolation. GitOrigin-RevId: 2d5b85e4e98668c637c538cbe528914c936bd831
164 lines
5.4 KiB
Rust
164 lines
5.4 KiB
Rust
use codex_connectors::parse_plugin_app_config;
|
|
use codex_core_plugins::manifest::UriPluginManifest;
|
|
use codex_core_plugins::manifest::parse_plugin_manifest_uri;
|
|
use codex_exec_server::CapabilityRootDiscovery;
|
|
use codex_exec_server::DiscoveredPluginFiles;
|
|
use codex_extension_api::SelectedPluginContribution;
|
|
use codex_mcp::parse_executor_plugin_mcp_config;
|
|
use codex_plugin::manifest::PluginManifestMcpServers;
|
|
use codex_protocol::capabilities::CapabilityRootLocation;
|
|
use codex_protocol::capabilities::SelectedCapabilityRoot;
|
|
|
|
pub(super) fn manifest_from_discovery<'a>(
|
|
selected_root: &SelectedCapabilityRoot,
|
|
discovery: &'a CapabilityRootDiscovery,
|
|
) -> Option<(UriPluginManifest, &'a DiscoveredPluginFiles)> {
|
|
for warning in &discovery.warnings {
|
|
tracing::warn!(
|
|
selected_root = selected_root.id,
|
|
warning,
|
|
"exec-server capability discovery warning"
|
|
);
|
|
}
|
|
if let Some(error) = &discovery.error {
|
|
tracing::warn!(
|
|
selected_root = selected_root.id,
|
|
error,
|
|
"exec-server capability discovery failed"
|
|
);
|
|
return None;
|
|
}
|
|
let plugin_files = discovery.plugin.as_ref()?;
|
|
match parse_plugin_manifest_uri(
|
|
&discovery.path,
|
|
&plugin_files.manifest.path,
|
|
&plugin_files.manifest.contents,
|
|
) {
|
|
Ok(manifest) => Some((manifest, plugin_files)),
|
|
Err(error) => {
|
|
tracing::warn!(
|
|
selected_root = selected_root.id,
|
|
path = %plugin_files.manifest.path,
|
|
%error,
|
|
"failed to parse exec-server-discovered plugin manifest"
|
|
);
|
|
None
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(super) fn metadata_from_discovery(
|
|
selected_root: &SelectedCapabilityRoot,
|
|
discovery: &CapabilityRootDiscovery,
|
|
plugin_files: &DiscoveredPluginFiles,
|
|
manifest: UriPluginManifest,
|
|
) -> SelectedPluginContribution {
|
|
let CapabilityRootLocation::Environment { environment_id, .. } = &selected_root.location;
|
|
let servers = match manifest.paths.mcp_servers.as_ref() {
|
|
Some(PluginManifestMcpServers::Object(contents)) => {
|
|
parse_mcp_servers(selected_root, &discovery.path, contents, environment_id)
|
|
}
|
|
Some(PluginManifestMcpServers::Path(path)) => plugin_files
|
|
.mcp_config
|
|
.as_ref()
|
|
.filter(|file| file.path == *path)
|
|
.map(|file| {
|
|
parse_mcp_servers(
|
|
selected_root,
|
|
&discovery.path,
|
|
&file.contents,
|
|
environment_id,
|
|
)
|
|
})
|
|
.unwrap_or_else(|| {
|
|
tracing::warn!(
|
|
selected_root = selected_root.id,
|
|
path = %path,
|
|
"exec-server capability bundle omitted declared MCP config"
|
|
);
|
|
Vec::new()
|
|
}),
|
|
None => plugin_files
|
|
.mcp_config
|
|
.as_ref()
|
|
.map(|file| {
|
|
parse_mcp_servers(
|
|
selected_root,
|
|
&discovery.path,
|
|
&file.contents,
|
|
environment_id,
|
|
)
|
|
})
|
|
.unwrap_or_default(),
|
|
};
|
|
let connector_ids = manifest
|
|
.paths
|
|
.apps
|
|
.as_ref()
|
|
.and_then(|path| {
|
|
plugin_files
|
|
.apps_config
|
|
.as_ref()
|
|
.filter(|file| file.path == *path)
|
|
.or_else(|| {
|
|
tracing::warn!(
|
|
selected_root = selected_root.id,
|
|
path = %path,
|
|
"exec-server capability bundle omitted declared connector config"
|
|
);
|
|
None
|
|
})
|
|
})
|
|
.and_then(|file| match parse_plugin_app_config(&file.contents) {
|
|
Ok(declarations) => Some(declarations),
|
|
Err(error) => {
|
|
tracing::warn!(
|
|
selected_root = selected_root.id,
|
|
path = %file.path,
|
|
%error,
|
|
"failed to parse exec-server-discovered connector config"
|
|
);
|
|
None
|
|
}
|
|
})
|
|
.unwrap_or_default()
|
|
.into_iter()
|
|
.map(|declaration| declaration.connector_id.0)
|
|
.collect();
|
|
|
|
SelectedPluginContribution {
|
|
plugin_display_name: manifest.display_name().to_string(),
|
|
source_environment_id: environment_id.clone(),
|
|
servers,
|
|
connector_ids,
|
|
}
|
|
}
|
|
|
|
fn parse_mcp_servers(
|
|
selected_root: &SelectedCapabilityRoot,
|
|
plugin_root: &codex_utils_path_uri::PathUri,
|
|
contents: &str,
|
|
environment_id: &str,
|
|
) -> Vec<(String, codex_config::McpServerConfig)> {
|
|
let parsed = match parse_executor_plugin_mcp_config(plugin_root, contents, environment_id) {
|
|
Ok(parsed) => parsed,
|
|
Err(error) => {
|
|
tracing::warn!(
|
|
selected_root = selected_root.id,
|
|
%error,
|
|
"failed to parse exec-server-discovered MCP config"
|
|
);
|
|
return Vec::new();
|
|
}
|
|
};
|
|
for error in parsed.errors {
|
|
tracing::warn!(
|
|
selected_root = selected_root.id,
|
|
server = error.name,
|
|
error = error.message,
|
|
"ignoring invalid exec-server-discovered MCP server"
|
|
);
|
|
}
|
|
parsed.servers.into_iter().collect()
|
|
}
|