Isolate MCP OAuth credentials by environment (#36310)

## Why

MCP servers running in an executor must not reuse host-owned OAuth credentials,
even when they have the same configured server name and URL.

## What changed

- Derive environment-scoped credential names for executor-owned MCP servers and
  use them consistently for login, logout, authentication, and connection setup.
- Mark executor-owned entries in the file credential store and fail closed when
  loading or saving an entry could cross the host/executor boundary.
- Preserve compatibility with existing local OAuth credentials, including local
  server names that overlap the new reserved prefixes.

## Testing

- Extend the executor MCP integration test to verify that executor requests use
  the executor token, never send the host token, and persist both credentials
  separately.

GitOrigin-RevId: 4fc92d0533b0fe2e0df34f6d47b81e3d20d07807
This commit is contained in:
jif
2026-07-31 11:23:46 +00:00
committed by copyberry
parent 5e8b22488f
commit 164b3bfeab
12 changed files with 194 additions and 39 deletions
+18
View File
@@ -1,9 +1,12 @@
//! MCP server configuration types.
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt;
use std::time::Duration;
use base64::Engine;
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
use codex_utils_path_uri::LegacyAppPathString;
use schemars::JsonSchema;
use serde::Deserialize;
@@ -227,6 +230,21 @@ impl McpServerConfig {
self.environment_id == DEFAULT_MCP_SERVER_ENVIRONMENT_ID
}
/// Keeps local OAuth credentials compatible while isolating executor-owned servers.
pub fn oauth_credential_name<'a>(&self, server_name: &'a str) -> Cow<'a, str> {
if self.is_local_environment() {
if server_name.starts_with("executor:") || server_name.starts_with("local:") {
Cow::Owned(format!("local:{server_name}"))
} else {
Cow::Borrowed(server_name)
}
} else {
let environment = URL_SAFE_NO_PAD.encode(self.environment_id.as_bytes());
let server = URL_SAFE_NO_PAD.encode(server_name.as_bytes());
Cow::Owned(format!("executor:{environment}:{server}"))
}
}
pub fn oauth_client_id(&self) -> Option<&str> {
self.oauth
.as_ref()