mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Harden cloud runtime local access boundaries
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
co-authored by
Codex
parent
326e31ab65
commit
af2e9b3b04
@@ -574,7 +574,12 @@ async fn make_rmcp_client(
|
||||
let remote_environment = match experimental_environment.as_deref() {
|
||||
None | Some("local") => false,
|
||||
Some("remote") => {
|
||||
if !runtime_environment.environment().is_remote() {
|
||||
let Some(environment) = runtime_environment.environment() else {
|
||||
return Err(StartupOutcomeError::from(anyhow!(
|
||||
"remote MCP server `{server_name}` requires an environment"
|
||||
)));
|
||||
};
|
||||
if !environment.is_remote() {
|
||||
return Err(StartupOutcomeError::from(anyhow!(
|
||||
"remote MCP server `{server_name}` requires a remote environment"
|
||||
)));
|
||||
@@ -604,11 +609,21 @@ async fn make_rmcp_client(
|
||||
.collect::<HashMap<_, _>>()
|
||||
});
|
||||
let launcher = if remote_environment {
|
||||
let Some(environment) = runtime_environment.environment() else {
|
||||
return Err(StartupOutcomeError::from(anyhow!(
|
||||
"remote MCP server `{server_name}` requires an environment"
|
||||
)));
|
||||
};
|
||||
Arc::new(ExecutorStdioServerLauncher::new(
|
||||
runtime_environment.environment().get_exec_backend(),
|
||||
environment.get_exec_backend(),
|
||||
runtime_environment.fallback_cwd(),
|
||||
))
|
||||
} else {
|
||||
if runtime_environment.environment().is_none() {
|
||||
return Err(StartupOutcomeError::from(anyhow!(
|
||||
"local stdio MCP server `{server_name}` is disabled because no local environment is available"
|
||||
)));
|
||||
}
|
||||
Arc::new(LocalStdioServerLauncher::new(
|
||||
runtime_environment.fallback_cwd(),
|
||||
)) as Arc<dyn StdioServerLauncher>
|
||||
@@ -628,7 +643,12 @@ async fn make_rmcp_client(
|
||||
bearer_token_env_var,
|
||||
} => {
|
||||
let http_client: Arc<dyn HttpClient> = if remote_environment {
|
||||
runtime_environment.environment().get_http_client()
|
||||
let Some(environment) = runtime_environment.environment() else {
|
||||
return Err(StartupOutcomeError::from(anyhow!(
|
||||
"remote MCP server `{server_name}` requires an environment"
|
||||
)));
|
||||
};
|
||||
environment.get_http_client()
|
||||
} else {
|
||||
Arc::new(ReqwestHttpClient)
|
||||
};
|
||||
@@ -659,6 +679,32 @@ mod tests {
|
||||
use rmcp::model::JsonObject;
|
||||
use rmcp::model::Meta;
|
||||
|
||||
fn stdio_server_config(command: &str) -> McpServerConfig {
|
||||
McpServerConfig {
|
||||
transport: McpServerTransportConfig::Stdio {
|
||||
command: command.to_string(),
|
||||
args: Vec::new(),
|
||||
env: None,
|
||||
env_vars: Vec::new(),
|
||||
cwd: None,
|
||||
},
|
||||
experimental_environment: None,
|
||||
enabled: true,
|
||||
required: false,
|
||||
supports_parallel_tool_calls: false,
|
||||
disabled_reason: None,
|
||||
startup_timeout_sec: None,
|
||||
tool_timeout_sec: None,
|
||||
default_tools_approval_mode: None,
|
||||
enabled_tools: None,
|
||||
disabled_tools: None,
|
||||
scopes: None,
|
||||
oauth: None,
|
||||
oauth_resource: None,
|
||||
tools: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn tool_with_connector_meta() -> RmcpTool {
|
||||
RmcpTool {
|
||||
name: "capture_file_upload".to_string().into(),
|
||||
@@ -724,6 +770,32 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn stdio_mcp_fails_closed_without_local_environment() {
|
||||
let server = EffectiveMcpServer::configured(stdio_server_config("echo"));
|
||||
let runtime_environment = McpRuntimeEnvironment::without_environment(
|
||||
std::env::current_dir().expect("current dir"),
|
||||
);
|
||||
|
||||
let result = make_rmcp_client(
|
||||
"local-test",
|
||||
server,
|
||||
OAuthCredentialsStoreMode::File,
|
||||
runtime_environment,
|
||||
/*runtime_auth_provider*/ None,
|
||||
)
|
||||
.await;
|
||||
let Err(err) = result else {
|
||||
panic!("stdio MCP should be disabled without an environment");
|
||||
};
|
||||
|
||||
assert!(err.to_string().contains("local stdio MCP server"));
|
||||
assert!(
|
||||
err.to_string()
|
||||
.contains("no local environment is available")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn codex_apps_connector_metadata_is_preserved() {
|
||||
let mut tool = tool_with_connector_meta();
|
||||
|
||||
@@ -38,20 +38,27 @@ pub struct SandboxState {
|
||||
/// process working directory.
|
||||
#[derive(Clone)]
|
||||
pub struct McpRuntimeEnvironment {
|
||||
environment: Arc<Environment>,
|
||||
environment: Option<Arc<Environment>>,
|
||||
fallback_cwd: PathBuf,
|
||||
}
|
||||
|
||||
impl McpRuntimeEnvironment {
|
||||
pub fn new(environment: Arc<Environment>, fallback_cwd: PathBuf) -> Self {
|
||||
Self {
|
||||
environment,
|
||||
environment: Some(environment),
|
||||
fallback_cwd,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn environment(&self) -> Arc<Environment> {
|
||||
Arc::clone(&self.environment)
|
||||
pub fn without_environment(fallback_cwd: PathBuf) -> Self {
|
||||
Self {
|
||||
environment: None,
|
||||
fallback_cwd,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn environment(&self) -> Option<Arc<Environment>> {
|
||||
self.environment.as_ref().map(Arc::clone)
|
||||
}
|
||||
|
||||
pub(crate) fn fallback_cwd(&self) -> PathBuf {
|
||||
|
||||
Reference in New Issue
Block a user