aKode fase 2b-2: rimosso login ChatGPT e tutti i sottosistemi solo-ChatGPT
- Login: resta solo chiave API (+ header, Bedrock). Rimossi OAuth/browser, device code, refresh/revoke su auth.openai.com, PAT, agent/workload identity, runtime agent instance, backend-client e openapi-models, workspace routing. - Rimossi: generazione immagini (ext + skill imagegen), history notes, plugin remoti (catalogo, sync, share), cyber access program, daybreak, cloud config e requirements (config_server ora fail-closed), attestation, frozen cloud skills, EMA MCP auth, Codex Apps/connettori, ricerca ospitata, header/zstd/ routing/cookie del backend Codex, fallback OPENAI_API_KEY del realtime. - Messaggi d'errore senza link a chatgpt.com. - Chiavi di config legacy accettate e ignorate; feature rimosse = Stage::Removed. - Test: cancellati solo quelli del codice rimosso; test di sicurezza (sandbox estensioni, permessi, redazione, auth storage, requirements) adattati. Restano solo fallimenti d'ambiente (code-mode-host/V8, ~/.agents). - Istruzioni di sistema invariate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,6 @@ use std::path::PathBuf;
|
||||
use std::process::Stdio;
|
||||
|
||||
use anyhow::Context as _;
|
||||
use codex_config::CloudConfigBundleLoader;
|
||||
use codex_config::LoaderOverrides;
|
||||
use codex_core::config::Config;
|
||||
use codex_core::config::ConfigBuilder;
|
||||
@@ -666,7 +665,6 @@ async fn load_debug_sandbox_config(
|
||||
codex_linux_sandbox_exe,
|
||||
options,
|
||||
/*codex_home*/ None,
|
||||
CloudConfigBundleLoader::default(),
|
||||
strict_config,
|
||||
)
|
||||
.await
|
||||
@@ -677,7 +675,6 @@ async fn load_debug_sandbox_config_with_codex_home(
|
||||
codex_linux_sandbox_exe: Option<PathBuf>,
|
||||
options: DebugSandboxConfigOptions,
|
||||
codex_home: Option<PathBuf>,
|
||||
cloud_config_bundle: CloudConfigBundleLoader,
|
||||
strict_config: bool,
|
||||
) -> anyhow::Result<Config> {
|
||||
let DebugSandboxConfigOptions {
|
||||
@@ -711,7 +708,6 @@ async fn load_debug_sandbox_config_with_codex_home(
|
||||
codex_home.clone(),
|
||||
managed_requirements_mode,
|
||||
loader_overrides.clone(),
|
||||
cloud_config_bundle.clone(),
|
||||
strict_config,
|
||||
)
|
||||
.await?;
|
||||
@@ -731,7 +727,6 @@ async fn load_debug_sandbox_config_with_codex_home(
|
||||
codex_home,
|
||||
managed_requirements_mode,
|
||||
loader_overrides,
|
||||
cloud_config_bundle,
|
||||
strict_config,
|
||||
)
|
||||
.await
|
||||
@@ -744,13 +739,11 @@ async fn build_debug_sandbox_config_with_loader_overrides(
|
||||
codex_home: Option<PathBuf>,
|
||||
managed_requirements_mode: ManagedRequirementsMode,
|
||||
mut loader_overrides: LoaderOverrides,
|
||||
cloud_config_bundle: CloudConfigBundleLoader,
|
||||
strict_config: bool,
|
||||
) -> std::io::Result<Config> {
|
||||
let mut builder = ConfigBuilder::default()
|
||||
.cli_overrides(cli_overrides)
|
||||
.harness_overrides(harness_overrides)
|
||||
.cloud_config_bundle(cloud_config_bundle)
|
||||
.strict_config(strict_config);
|
||||
if matches!(managed_requirements_mode, ManagedRequirementsMode::Ignore) {
|
||||
loader_overrides.ignore_managed_requirements = true;
|
||||
@@ -782,20 +775,20 @@ fn cli_overrides_use_legacy_sandbox_mode(cli_overrides: &[(String, TomlValue)])
|
||||
mod tests {
|
||||
use super::*;
|
||||
use codex_config::ConfigRequirementsToml;
|
||||
use codex_config::test_support::CloudConfigBundleFixture;
|
||||
use codex_config::test_support::ManagedConfigFixture;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::TempDir;
|
||||
|
||||
const CLOUD_MANAGED_PERMISSION_PROFILE_REQUIREMENTS: &str = r#"
|
||||
default_permissions = "managed-cloud"
|
||||
const MANAGED_PERMISSION_PROFILE_REQUIREMENTS: &str = r#"
|
||||
default_permissions = "managed-profile"
|
||||
|
||||
[allowed_permission_profiles]
|
||||
managed-cloud = true
|
||||
managed-profile = true
|
||||
|
||||
[permissions.managed-cloud]
|
||||
[permissions.managed-profile]
|
||||
extends = ":workspace"
|
||||
|
||||
[permissions.managed-cloud.network]
|
||||
[permissions.managed-profile.network]
|
||||
enabled = true
|
||||
"#;
|
||||
|
||||
@@ -812,7 +805,6 @@ enabled = true
|
||||
codex_home,
|
||||
managed_requirements_mode,
|
||||
LoaderOverrides::default(),
|
||||
CloudConfigBundleLoader::default(),
|
||||
strict_config,
|
||||
)
|
||||
.await
|
||||
@@ -896,7 +888,6 @@ enabled = true
|
||||
loader_overrides: LoaderOverrides::default(),
|
||||
},
|
||||
Some(codex_home_path),
|
||||
CloudConfigBundleLoader::default(),
|
||||
/*strict_config*/ false,
|
||||
)
|
||||
.await?;
|
||||
@@ -940,7 +931,6 @@ enabled = true
|
||||
Some(codex_home_path.clone()),
|
||||
ManagedRequirementsMode::Include,
|
||||
loader_overrides.clone(),
|
||||
CloudConfigBundleLoader::default(),
|
||||
/*strict_config*/ false,
|
||||
)
|
||||
.await?;
|
||||
@@ -967,7 +957,6 @@ enabled = true
|
||||
loader_overrides,
|
||||
},
|
||||
Some(codex_home_path),
|
||||
CloudConfigBundleLoader::default(),
|
||||
/*strict_config*/ false,
|
||||
)
|
||||
.await?;
|
||||
@@ -1026,7 +1015,6 @@ enabled = true
|
||||
loader_overrides: LoaderOverrides::default(),
|
||||
},
|
||||
Some(codex_home_path),
|
||||
CloudConfigBundleLoader::default(),
|
||||
/*strict_config*/ false,
|
||||
)
|
||||
.await?;
|
||||
@@ -1086,7 +1074,6 @@ enabled = true
|
||||
loader_overrides: LoaderOverrides::default(),
|
||||
},
|
||||
Some(codex_home_path),
|
||||
CloudConfigBundleLoader::default(),
|
||||
/*strict_config*/ false,
|
||||
)
|
||||
.await?;
|
||||
@@ -1115,7 +1102,6 @@ enabled = true
|
||||
loader_overrides: LoaderOverrides::default(),
|
||||
},
|
||||
Some(codex_home.path().to_path_buf()),
|
||||
CloudConfigBundleLoader::default(),
|
||||
/*strict_config*/ false,
|
||||
)
|
||||
.await?;
|
||||
@@ -1138,7 +1124,7 @@ enabled = true
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn debug_sandbox_honors_explicit_cloud_managed_permission_profile() -> anyhow::Result<()>
|
||||
async fn debug_sandbox_honors_explicit_managed_permission_profile() -> anyhow::Result<()>
|
||||
{
|
||||
let codex_home = TempDir::new()?;
|
||||
|
||||
@@ -1147,15 +1133,15 @@ enabled = true
|
||||
/*codex_linux_sandbox_exe*/ None,
|
||||
DebugSandboxConfigOptions {
|
||||
sandbox_state: Default::default(),
|
||||
permissions_profile: Some("managed-cloud".to_string()),
|
||||
permissions_profile: Some("managed-profile".to_string()),
|
||||
cwd: None,
|
||||
managed_requirements_mode: ManagedRequirementsMode::Include,
|
||||
loader_overrides: LoaderOverrides::without_managed_config_for_tests(),
|
||||
loader_overrides: ManagedConfigFixture::requirements(
|
||||
MANAGED_PERMISSION_PROFILE_REQUIREMENTS,
|
||||
)
|
||||
.loader_overrides_for_tests(codex_home.path())?,
|
||||
},
|
||||
Some(codex_home.path().to_path_buf()),
|
||||
CloudConfigBundleFixture::loader_with_enterprise_requirement(
|
||||
CLOUD_MANAGED_PERMISSION_PROFILE_REQUIREMENTS,
|
||||
),
|
||||
/*strict_config*/ false,
|
||||
)
|
||||
.await?;
|
||||
@@ -1165,7 +1151,7 @@ enabled = true
|
||||
.permissions
|
||||
.active_permission_profile()
|
||||
.map(|profile| profile.id),
|
||||
Some("managed-cloud".to_string()),
|
||||
Some("managed-profile".to_string()),
|
||||
);
|
||||
assert_eq!(
|
||||
config.permissions.network_sandbox_policy(),
|
||||
@@ -1174,7 +1160,7 @@ enabled = true
|
||||
assert_eq!(
|
||||
config.config_layer_stack.requirements_toml(),
|
||||
&toml::from_str::<ConfigRequirementsToml>(
|
||||
CLOUD_MANAGED_PERMISSION_PROFILE_REQUIREMENTS,
|
||||
MANAGED_PERMISSION_PROFILE_REQUIREMENTS,
|
||||
)?,
|
||||
);
|
||||
|
||||
@@ -1182,7 +1168,7 @@ enabled = true
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn debug_sandbox_ignores_cloud_managed_permission_profiles_by_default()
|
||||
async fn debug_sandbox_ignores_managed_permission_profiles_by_default()
|
||||
-> anyhow::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
|
||||
@@ -1194,12 +1180,12 @@ enabled = true
|
||||
permissions_profile: Some(":workspace".to_string()),
|
||||
cwd: None,
|
||||
managed_requirements_mode: ManagedRequirementsMode::Ignore,
|
||||
loader_overrides: LoaderOverrides::without_managed_config_for_tests(),
|
||||
loader_overrides: ManagedConfigFixture::requirements(
|
||||
MANAGED_PERMISSION_PROFILE_REQUIREMENTS,
|
||||
)
|
||||
.loader_overrides_for_tests(codex_home.path())?,
|
||||
},
|
||||
Some(codex_home.path().to_path_buf()),
|
||||
CloudConfigBundleFixture::loader_with_enterprise_requirement(
|
||||
CLOUD_MANAGED_PERMISSION_PROFILE_REQUIREMENTS,
|
||||
),
|
||||
/*strict_config*/ false,
|
||||
)
|
||||
.await?;
|
||||
@@ -1242,7 +1228,6 @@ enabled = true
|
||||
loader_overrides: LoaderOverrides::default(),
|
||||
},
|
||||
Some(codex_home.path().to_path_buf()),
|
||||
CloudConfigBundleLoader::default(),
|
||||
/*strict_config*/ false,
|
||||
)
|
||||
.await?;
|
||||
@@ -1283,7 +1268,6 @@ enabled = true
|
||||
loader_overrides: LoaderOverrides::default(),
|
||||
},
|
||||
Some(codex_home.path().to_path_buf()),
|
||||
CloudConfigBundleLoader::default(),
|
||||
/*strict_config*/ false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -41,7 +41,6 @@ use codex_core::config::ConfigOverrides;
|
||||
use codex_core::config::LoaderOverrides;
|
||||
use codex_core::config::find_codex_home;
|
||||
use codex_features::FEATURES;
|
||||
use codex_features::Feature;
|
||||
use codex_http_client::ClientRouteClass;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OpenAiDestination;
|
||||
@@ -54,7 +53,6 @@ use codex_install_context::InstallMethod;
|
||||
use codex_install_context::StandalonePlatform;
|
||||
use codex_login::AuthDotJson;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::CODEX_ACCESS_TOKEN_ENV_VAR;
|
||||
use codex_login::CODEX_API_KEY_ENV_VAR;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_login::OPENAI_API_KEY_ENV_VAR;
|
||||
@@ -642,7 +640,7 @@ async fn load_config(
|
||||
..config_overrides_from_interactive(interactive, arg0_paths)
|
||||
};
|
||||
|
||||
let config = crate::cloud_config::config_builder(
|
||||
let config = crate::local_config::config_builder(
|
||||
&root_config_overrides,
|
||||
LoaderOverrides::default(),
|
||||
overrides,
|
||||
@@ -1119,7 +1117,7 @@ fn codex_path_entries() -> Vec<String> {
|
||||
fn config_check(config: &Config) -> DoctorCheck {
|
||||
let mut details = Vec::new();
|
||||
details
|
||||
.push("configuration scope: invocation config, including cloud-managed policy".to_string());
|
||||
.push("configuration scope: invocation config, including managed policy".to_string());
|
||||
details.push("active thread overrides: not inspected".to_string());
|
||||
details.push(format!("CODEX_HOME: {}", config.codex_home.display()));
|
||||
details.push(format!("cwd: {}", config.cwd.display()));
|
||||
@@ -1232,14 +1230,10 @@ fn auth_check(config: &Config) -> DoctorCheck {
|
||||
));
|
||||
details.push(format!("auth file: {}", auth_path.display()));
|
||||
|
||||
let env_auth_vars = [
|
||||
OPENAI_API_KEY_ENV_VAR,
|
||||
CODEX_API_KEY_ENV_VAR,
|
||||
CODEX_ACCESS_TOKEN_ENV_VAR,
|
||||
]
|
||||
.into_iter()
|
||||
.filter(|name| env_var_present(name))
|
||||
.collect::<Vec<_>>();
|
||||
let env_auth_vars = [OPENAI_API_KEY_ENV_VAR, CODEX_API_KEY_ENV_VAR]
|
||||
.into_iter()
|
||||
.filter(|name| env_var_present(name))
|
||||
.collect::<Vec<_>>();
|
||||
if !env_auth_vars.is_empty() {
|
||||
details.push(format!(
|
||||
"auth env vars present: {}",
|
||||
@@ -1264,11 +1258,6 @@ fn auth_check(config: &Config) -> DoctorCheck {
|
||||
Ok(Some(auth)) => {
|
||||
details.push(format!("stored auth mode: {}", stored_auth_mode(&auth)));
|
||||
details.push(format!("stored API key: {}", auth.openai_api_key.is_some()));
|
||||
details.push(format!("stored ChatGPT tokens: {}", auth.tokens.is_some()));
|
||||
details.push(format!(
|
||||
"stored agent identity: {}",
|
||||
auth.agent_identity.is_some()
|
||||
));
|
||||
let auth_issues = stored_auth_issues(&auth, env_var_present);
|
||||
details.extend(
|
||||
auth_issues
|
||||
@@ -1296,7 +1285,9 @@ fn auth_check(config: &Config) -> DoctorCheck {
|
||||
DoctorCheck::new("auth.credentials", "auth", status, summary).details(details);
|
||||
if status == CheckStatus::Fail {
|
||||
check =
|
||||
check.remediation("Run codex login again or provide a supported auth env var.");
|
||||
check.remediation(
|
||||
"Run codex login --with-api-key again or provide a supported auth env var.",
|
||||
);
|
||||
}
|
||||
check
|
||||
}
|
||||
@@ -1314,7 +1305,9 @@ fn auth_check(config: &Config) -> DoctorCheck {
|
||||
"no Codex credentials were found",
|
||||
)
|
||||
.details(details)
|
||||
.remediation("Run codex login or provide an API key through a supported auth env var."),
|
||||
.remediation(
|
||||
"Run codex login --with-api-key or provide an API key through a supported auth env var.",
|
||||
),
|
||||
Err(err) => DoctorCheck::new(
|
||||
"auth.credentials",
|
||||
"auth",
|
||||
@@ -1383,31 +1376,27 @@ fn provider_specific_auth_check(
|
||||
|
||||
fn stored_auth_mode(auth: &codex_login::AuthDotJson) -> &'static str {
|
||||
match stored_auth_mode_value(auth) {
|
||||
AuthMode::ApiKey => "api_key",
|
||||
AuthMode::Chatgpt => "chatgpt",
|
||||
AuthMode::ChatgptAuthTokens => "chatgpt_auth_tokens",
|
||||
AuthMode::Headers => "headers",
|
||||
AuthMode::AgentIdentity => "agent_identity",
|
||||
AuthMode::PersonalAccessToken => "personal_access_token",
|
||||
AuthMode::BedrockApiKey => "bedrock_api_key",
|
||||
AuthMode::BedrockAccessKeys => "bedrock_access_keys",
|
||||
Some(AuthMode::ApiKey) => "api_key",
|
||||
Some(AuthMode::Headers) => "headers",
|
||||
Some(AuthMode::BedrockApiKey) => "bedrock_api_key",
|
||||
Some(AuthMode::BedrockAccessKeys) => "bedrock_access_keys",
|
||||
None => "unsupported",
|
||||
}
|
||||
}
|
||||
|
||||
fn stored_auth_mode_value(auth: &AuthDotJson) -> AuthMode {
|
||||
/// Returns `None` for records written by sign-in methods that are no longer supported.
|
||||
fn stored_auth_mode_value(auth: &AuthDotJson) -> Option<AuthMode> {
|
||||
if let Some(mode) = auth.auth_mode {
|
||||
return mode;
|
||||
return Some(mode);
|
||||
}
|
||||
if auth.personal_access_token.is_some() {
|
||||
AuthMode::PersonalAccessToken
|
||||
} else if auth.bedrock_api_key.is_some() {
|
||||
AuthMode::BedrockApiKey
|
||||
if auth.bedrock_api_key.is_some() {
|
||||
Some(AuthMode::BedrockApiKey)
|
||||
} else if auth.bedrock_access_keys.is_some() {
|
||||
AuthMode::BedrockAccessKeys
|
||||
Some(AuthMode::BedrockAccessKeys)
|
||||
} else if auth.openai_api_key.is_some() {
|
||||
AuthMode::ApiKey
|
||||
Some(AuthMode::ApiKey)
|
||||
} else {
|
||||
AuthMode::Chatgpt
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1416,7 +1405,13 @@ fn stored_auth_issues(
|
||||
env_var_present: impl Fn(&str) -> bool,
|
||||
) -> Vec<&'static str> {
|
||||
let mut issues = Vec::new();
|
||||
match stored_auth_mode_value(auth) {
|
||||
let Some(mode) = stored_auth_mode_value(auth) else {
|
||||
issues.push(
|
||||
"stored credentials use an unsupported sign-in method; run codex logout and codex login --with-api-key",
|
||||
);
|
||||
return issues;
|
||||
};
|
||||
match mode {
|
||||
AuthMode::ApiKey => {
|
||||
let stored_key_present = auth
|
||||
.openai_api_key
|
||||
@@ -1428,59 +1423,9 @@ fn stored_auth_issues(
|
||||
issues.push("API key auth is missing an API key");
|
||||
}
|
||||
}
|
||||
AuthMode::Chatgpt => {
|
||||
match auth.tokens.as_ref() {
|
||||
Some(tokens) => {
|
||||
if tokens.access_token.trim().is_empty() {
|
||||
issues.push("ChatGPT auth is missing an access token");
|
||||
}
|
||||
if tokens.refresh_token.trim().is_empty() {
|
||||
issues.push("ChatGPT auth is missing a refresh token");
|
||||
}
|
||||
}
|
||||
None => issues.push("ChatGPT auth is missing token data"),
|
||||
}
|
||||
if auth.last_refresh.is_none() {
|
||||
issues.push("ChatGPT auth is missing refresh metadata");
|
||||
}
|
||||
}
|
||||
AuthMode::ChatgptAuthTokens => {
|
||||
match auth.tokens.as_ref() {
|
||||
Some(tokens) => {
|
||||
if tokens.access_token.trim().is_empty() {
|
||||
issues.push("external ChatGPT auth is missing an access token");
|
||||
}
|
||||
if tokens.account_id.is_none() && tokens.id_token.chatgpt_account_id.is_none() {
|
||||
issues.push("external ChatGPT auth is missing a ChatGPT account id");
|
||||
}
|
||||
}
|
||||
None => issues.push("external ChatGPT auth is missing token data"),
|
||||
}
|
||||
if auth.last_refresh.is_none() {
|
||||
issues.push("external ChatGPT auth is missing refresh metadata");
|
||||
}
|
||||
}
|
||||
AuthMode::Headers => {
|
||||
issues.push("header auth cannot be loaded from auth storage");
|
||||
}
|
||||
AuthMode::AgentIdentity => {
|
||||
if auth
|
||||
.agent_identity
|
||||
.as_ref()
|
||||
.is_none_or(|agent_identity| !agent_identity.has_auth_material())
|
||||
{
|
||||
issues.push("agent identity auth is missing an agent identity token");
|
||||
}
|
||||
}
|
||||
AuthMode::PersonalAccessToken => {
|
||||
if auth
|
||||
.personal_access_token
|
||||
.as_deref()
|
||||
.is_none_or(|token| token.trim().is_empty())
|
||||
{
|
||||
issues.push("personal access token auth is missing a personal access token");
|
||||
}
|
||||
}
|
||||
AuthMode::BedrockApiKey => {
|
||||
if auth.bedrock_api_key.is_none() {
|
||||
issues.push("Bedrock API key auth is missing a Bedrock API key");
|
||||
@@ -2357,31 +2302,13 @@ async fn websocket_reachability_check(
|
||||
));
|
||||
|
||||
let setup = async {
|
||||
let runtime_auth = if config.features.enabled(Feature::RuntimeAgentInstances)
|
||||
&& let Some(credentials) = &auth_manager
|
||||
{
|
||||
let installation_id = codex_core::resolve_installation_id(&config.codex_home).await?;
|
||||
codex_core::build_runtime_auth_manager(
|
||||
config,
|
||||
Arc::clone(credentials),
|
||||
&installation_id,
|
||||
)
|
||||
.map(|runtime| (runtime, config.runtime_auth_mode))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let runtime_provider = match auth_manager {
|
||||
Some(credentials) => codex_model_provider::ProviderAuthContext {
|
||||
credentials,
|
||||
runtime_auth,
|
||||
}
|
||||
.model_provider(provider.clone()),
|
||||
Some(credentials) => codex_model_provider::ProviderAuthContext { credentials }
|
||||
.model_provider(provider.clone()),
|
||||
None => create_model_provider(provider.clone(), /*auth_manager*/ None),
|
||||
};
|
||||
codex_model_provider::resolve_request(
|
||||
runtime_provider.as_ref(),
|
||||
/*scope*/ None,
|
||||
Some(&config.workspace_routing_context()),
|
||||
config.http_client_factory(),
|
||||
)
|
||||
.await
|
||||
@@ -2565,11 +2492,7 @@ fn close_reason_detail(reason: &str) -> &'static str {
|
||||
fn auth_mode_name(auth: &CodexAuth) -> &'static str {
|
||||
match auth.auth_mode() {
|
||||
AuthMode::ApiKey => "api_key",
|
||||
AuthMode::Chatgpt => "chatgpt",
|
||||
AuthMode::ChatgptAuthTokens => "chatgpt_auth_tokens",
|
||||
AuthMode::Headers => "headers",
|
||||
AuthMode::AgentIdentity => "agent_identity",
|
||||
AuthMode::PersonalAccessToken => "personal_access_token",
|
||||
AuthMode::BedrockApiKey => "bedrock_api_key",
|
||||
AuthMode::BedrockAccessKeys => "bedrock_access_keys",
|
||||
}
|
||||
@@ -2641,7 +2564,6 @@ struct ReachabilityEndpoint {
|
||||
enum ProviderAuthReachabilityMode {
|
||||
NotRequired,
|
||||
ApiKey,
|
||||
Chatgpt,
|
||||
}
|
||||
|
||||
impl ProviderAuthReachabilityMode {
|
||||
@@ -2649,7 +2571,6 @@ impl ProviderAuthReachabilityMode {
|
||||
match self {
|
||||
Self::NotRequired => "provider auth",
|
||||
Self::ApiKey => "API key auth",
|
||||
Self::Chatgpt => "ChatGPT auth",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2716,21 +2637,11 @@ fn provider_auth_reachability_mode_from_auth(
|
||||
{
|
||||
return ProviderAuthReachabilityMode::ApiKey;
|
||||
}
|
||||
if env_var_present(CODEX_ACCESS_TOKEN_ENV_VAR) {
|
||||
return ProviderAuthReachabilityMode::Chatgpt;
|
||||
}
|
||||
match stored_auth.map(stored_auth_mode_value) {
|
||||
match stored_auth.and_then(stored_auth_mode_value) {
|
||||
Some(AuthMode::ApiKey | AuthMode::BedrockApiKey | AuthMode::BedrockAccessKeys) => {
|
||||
ProviderAuthReachabilityMode::ApiKey
|
||||
}
|
||||
Some(
|
||||
AuthMode::Chatgpt
|
||||
| AuthMode::ChatgptAuthTokens
|
||||
| AuthMode::Headers
|
||||
| AuthMode::AgentIdentity
|
||||
| AuthMode::PersonalAccessToken,
|
||||
)
|
||||
| None => ProviderAuthReachabilityMode::Chatgpt,
|
||||
Some(AuthMode::Headers) | None => ProviderAuthReachabilityMode::NotRequired,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2809,7 +2720,7 @@ async fn provider_reachability_check(plan: ReachabilityPlan) -> DoctorCheck {
|
||||
.details(details);
|
||||
}
|
||||
|
||||
let client = RouteAwareClientPool::with_chatgpt_cloudflare_cookies_without_request_logging(
|
||||
let client = RouteAwareClientPool::new_without_request_logging(
|
||||
plan.http_client_factory,
|
||||
ClientRouteClass::Api,
|
||||
)
|
||||
@@ -3776,10 +3687,6 @@ mod tests {
|
||||
let auth = AuthDotJson {
|
||||
auth_mode: Some(AuthMode::ApiKey),
|
||||
openai_api_key: None,
|
||||
tokens: None,
|
||||
last_refresh: None,
|
||||
agent_identity: None,
|
||||
personal_access_token: None,
|
||||
bedrock_api_key: None,
|
||||
bedrock_access_keys: None,
|
||||
};
|
||||
@@ -3792,60 +3699,28 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stored_auth_validation_rejects_missing_chatgpt_tokens() {
|
||||
let auth = AuthDotJson {
|
||||
auth_mode: None,
|
||||
openai_api_key: None,
|
||||
tokens: None,
|
||||
last_refresh: None,
|
||||
agent_identity: None,
|
||||
personal_access_token: None,
|
||||
bedrock_api_key: None,
|
||||
bedrock_access_keys: None,
|
||||
};
|
||||
fn stored_auth_validation_flags_unsupported_legacy_credentials() {
|
||||
let auth: AuthDotJson = serde_json::from_value(serde_json::json!({
|
||||
"auth_mode": "chatgpt",
|
||||
"OPENAI_API_KEY": null,
|
||||
"tokens": {"access_token": "legacy", "refresh_token": "legacy"},
|
||||
}))
|
||||
.expect("legacy auth.json still parses");
|
||||
|
||||
assert_eq!(stored_auth_mode(&auth), "unsupported");
|
||||
assert_eq!(
|
||||
stored_auth_issues(&auth, |_| false),
|
||||
vec![
|
||||
"ChatGPT auth is missing token data",
|
||||
"ChatGPT auth is missing refresh metadata",
|
||||
"stored credentials use an unsupported sign-in method; run codex logout and codex login --with-api-key"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stored_auth_validation_handles_personal_access_token() {
|
||||
let mut auth = AuthDotJson {
|
||||
auth_mode: None,
|
||||
openai_api_key: None,
|
||||
tokens: None,
|
||||
last_refresh: None,
|
||||
agent_identity: None,
|
||||
personal_access_token: Some("at-test".to_string()),
|
||||
bedrock_api_key: None,
|
||||
bedrock_access_keys: None,
|
||||
};
|
||||
|
||||
assert_eq!(stored_auth_mode(&auth), "personal_access_token");
|
||||
assert!(stored_auth_issues(&auth, |_| false).is_empty());
|
||||
|
||||
auth.auth_mode = Some(AuthMode::PersonalAccessToken);
|
||||
auth.personal_access_token = None;
|
||||
assert_eq!(
|
||||
stored_auth_issues(&auth, |_| false),
|
||||
vec!["personal access token auth is missing a personal access token"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn provider_reachability_mode_uses_api_key_auth() {
|
||||
let api_key_auth = AuthDotJson {
|
||||
auth_mode: Some(AuthMode::ApiKey),
|
||||
openai_api_key: Some("sk-test".to_string()),
|
||||
tokens: None,
|
||||
last_refresh: None,
|
||||
agent_identity: None,
|
||||
personal_access_token: None,
|
||||
bedrock_api_key: None,
|
||||
bedrock_access_keys: None,
|
||||
};
|
||||
@@ -3871,8 +3746,8 @@ mod tests {
|
||||
ProviderAuthReachabilityMode::ApiKey
|
||||
);
|
||||
|
||||
let chatgpt_auth = AuthDotJson {
|
||||
auth_mode: Some(AuthMode::Chatgpt),
|
||||
let env_key_auth = AuthDotJson {
|
||||
auth_mode: Some(AuthMode::Headers),
|
||||
openai_api_key: None,
|
||||
..api_key_auth
|
||||
};
|
||||
@@ -3882,9 +3757,9 @@ mod tests {
|
||||
/*provider_env_key*/ None,
|
||||
Some("https://custom.example/v1"),
|
||||
|name| name == OPENAI_API_KEY_ENV_VAR,
|
||||
Some(&chatgpt_auth),
|
||||
Some(&env_key_auth),
|
||||
),
|
||||
ProviderAuthReachabilityMode::Chatgpt
|
||||
ProviderAuthReachabilityMode::NotRequired
|
||||
);
|
||||
assert_eq!(
|
||||
provider_auth_reachability_mode_from_auth(
|
||||
@@ -3892,7 +3767,7 @@ mod tests {
|
||||
Some(OPENAI_API_KEY_ENV_VAR),
|
||||
Some("https://custom.example/v1"),
|
||||
|name| name == OPENAI_API_KEY_ENV_VAR,
|
||||
Some(&chatgpt_auth),
|
||||
Some(&env_key_auth),
|
||||
),
|
||||
ProviderAuthReachabilityMode::ApiKey
|
||||
);
|
||||
@@ -3902,7 +3777,7 @@ mod tests {
|
||||
/*provider_env_key*/ None,
|
||||
/*provider_base_url*/ None,
|
||||
|name| name == CODEX_API_KEY_ENV_VAR,
|
||||
Some(&chatgpt_auth),
|
||||
Some(&env_key_auth),
|
||||
),
|
||||
ProviderAuthReachabilityMode::ApiKey
|
||||
);
|
||||
@@ -3938,7 +3813,7 @@ mod tests {
|
||||
|
||||
for (mode, description) in [
|
||||
(ProviderAuthReachabilityMode::NotRequired, "provider auth"),
|
||||
(ProviderAuthReachabilityMode::Chatgpt, "ChatGPT auth"),
|
||||
(ProviderAuthReachabilityMode::ApiKey, "API key auth"),
|
||||
] {
|
||||
assert_eq!(
|
||||
provider_reachability_plan_from_parts(
|
||||
@@ -4000,7 +3875,7 @@ mod tests {
|
||||
"https://chatgpt.com/backend-api/",
|
||||
] {
|
||||
let plan = provider_reachability_plan_from_parts(
|
||||
ProviderAuthReachabilityMode::Chatgpt,
|
||||
ProviderAuthReachabilityMode::NotRequired,
|
||||
"openai",
|
||||
"OpenAI",
|
||||
Some(base_url),
|
||||
|
||||
@@ -83,7 +83,6 @@ pub(super) fn sandbox_check(config: &Config, arg0_paths: &Arg0DispatchPaths) ->
|
||||
{
|
||||
None => "none",
|
||||
Some(RequirementSource::Unknown) => "unknown",
|
||||
Some(RequirementSource::EnterpriseManaged { .. }) => "cloud",
|
||||
Some(RequirementSource::Composite { .. }) => "multiple layers",
|
||||
Some(RequirementSource::MdmManagedPreferences { .. }) => "MDM",
|
||||
Some(RequirementSource::SystemRequirementsToml { .. }) => "system",
|
||||
|
||||
@@ -142,7 +142,6 @@ fn terminal_title_item_id(item: &str) -> Option<&'static str> {
|
||||
"total-output-tokens" => Some("total-output-tokens"),
|
||||
"thread-id" | "session-id" => Some("thread-id"),
|
||||
"fast-mode" => Some("fast-mode"),
|
||||
"daybreak" => Some("daybreak"),
|
||||
"model" | "model-name" => Some("model"),
|
||||
"model-with-reasoning" => Some("model-with-reasoning"),
|
||||
"reasoning" => Some("reasoning"),
|
||||
@@ -315,7 +314,7 @@ mod tests {
|
||||
configured_items: Some(vec![
|
||||
"thread-credits".to_string(),
|
||||
"estimated-thread-cost".to_string(),
|
||||
"daybreak".to_string(),
|
||||
"fast-mode".to_string(),
|
||||
]),
|
||||
cwd: PathBuf::from("/workspace/project"),
|
||||
project_root: None,
|
||||
@@ -324,7 +323,7 @@ mod tests {
|
||||
assert_eq!(check.status, CheckStatus::Ok);
|
||||
assert_eq!(check.summary, "terminal title configured");
|
||||
assert!(check.details.contains(
|
||||
&"terminal title items: thread-credits, estimated-thread-cost, daybreak".to_string()
|
||||
&"terminal title items: thread-credits, estimated-thread-cost, fast-mode".to_string()
|
||||
));
|
||||
assert!(check.issues.is_empty());
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
//! Snapshot coverage for the public exec command's argument help.
|
||||
|
||||
use super::MultitoolCli;
|
||||
use clap::CommandFactory;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn exec_help_documents_cyber_access_program() {
|
||||
let help = MultitoolCli::command()
|
||||
.term_width(80)
|
||||
.try_get_matches_from(["codex", "exec", "--help"])
|
||||
.expect_err("help should short-circuit");
|
||||
assert_eq!(help.kind(), clap::error::ErrorKind::DisplayHelp);
|
||||
let program_help = help
|
||||
.to_string()
|
||||
.lines()
|
||||
.skip_while(|line| !line.contains("--cyber-access-program"))
|
||||
.take_while(|line| !line.is_empty())
|
||||
.map(str::trim_end)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
insta::assert_snapshot!(program_help.trim(), @r"
|
||||
--cyber-access-program <PROGRAM>
|
||||
Request an experimental Cyber access program for this turn (OpenAI
|
||||
provider only). Omit to use server defaults. Not supported with
|
||||
review; fork requires a prompt
|
||||
|
||||
[possible values: standard, daybreak_blue, daybreak_red]
|
||||
");
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
pub mod cloud_config;
|
||||
pub mod local_config;
|
||||
pub(crate) mod debug_sandbox;
|
||||
mod exit_status;
|
||||
pub(crate) mod login;
|
||||
@@ -13,14 +13,9 @@ use std::path::PathBuf;
|
||||
pub use debug_sandbox::run_command_under_landlock;
|
||||
pub use debug_sandbox::run_command_under_seatbelt;
|
||||
pub use debug_sandbox::run_command_under_windows_sandbox;
|
||||
pub use login::read_access_token_from_stdin;
|
||||
pub use login::read_api_key_from_stdin;
|
||||
pub use login::run_login_status;
|
||||
pub use login::run_login_with_access_token;
|
||||
pub use login::run_login_with_api_key;
|
||||
pub use login::run_login_with_browser;
|
||||
pub use login::run_login_with_device_code;
|
||||
pub use login::run_login_with_device_code_fallback_to_browser;
|
||||
pub use login::run_logout;
|
||||
|
||||
#[derive(Debug, Default, Args)]
|
||||
|
||||
@@ -7,31 +7,16 @@
|
||||
//! into a one-shot CLI command while still producing a durable `codex-login.log` artifact that
|
||||
//! support can request from users.
|
||||
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_core::config::Config;
|
||||
use codex_core::config::edit::ConfigEdit;
|
||||
use codex_core::config::edit::ConfigEditsBuilder;
|
||||
use codex_login::AuthKeyringBackendKind;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::AuthRouteConfig;
|
||||
use codex_login::CLIENT_ID;
|
||||
use codex_login::ServerOptions;
|
||||
use codex_login::is_workload_identity_selected;
|
||||
use codex_login::login_with_access_token;
|
||||
use codex_login::login_with_api_key;
|
||||
use codex_login::logout_with_revoke;
|
||||
use codex_login::run_device_code_login;
|
||||
use codex_login::run_login_server;
|
||||
use codex_mcp::ema_auth_scope;
|
||||
use codex_protocol::auth::AuthMode;
|
||||
use codex_protocol::config_types::ForcedLoginMethod;
|
||||
use codex_rmcp_client::EnterpriseOAuthCredentialGuard;
|
||||
use codex_utils_cli::CliConfigOverrides;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::IsTerminal;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use tracing_appender::non_blocking;
|
||||
use tracing_appender::non_blocking::WorkerGuard;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
@@ -39,13 +24,8 @@ use tracing_subscriber::Layer;
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
const CHATGPT_LOGIN_DISABLED_MESSAGE: &str =
|
||||
"ChatGPT login is disabled. Use API key login instead.";
|
||||
const API_KEY_LOGIN_DISABLED_MESSAGE: &str =
|
||||
"API key login is disabled. Use ChatGPT login instead.";
|
||||
const ACCESS_TOKEN_LOGIN_DISABLED_MESSAGE: &str =
|
||||
"Access token login is disabled. Use API key login instead.";
|
||||
const LOGIN_SUCCESS_MESSAGE: &str = "Successfully logged in";
|
||||
"API key login is disabled by the configured login restrictions.";
|
||||
const API_KEY_AUTHENTICATION_NOTICE: &str = "Authentication is checked when you send a request.";
|
||||
const DEFAULT_LOGIN_LOG_FILTER: &str =
|
||||
"codex_cli=info,codex_core=info,codex_login=info,codex_otel::auth_storage=warn";
|
||||
@@ -118,60 +98,6 @@ fn init_login_file_logging(config: &Config) -> Option<WorkerGuard> {
|
||||
Some(guard)
|
||||
}
|
||||
|
||||
fn print_login_server_start(actual_port: u16, auth_url: &str) {
|
||||
eprintln!(
|
||||
"Starting local login server on http://localhost:{actual_port}.\nIf your browser did not open, navigate to this URL to authenticate:\n\n{auth_url}\n\nOn a remote or headless machine? Use `codex login --device-auth` instead."
|
||||
);
|
||||
}
|
||||
|
||||
async fn clear_existing_auth_before_login(
|
||||
codex_home: &Path,
|
||||
auth_credentials_store_mode: AuthCredentialsStoreMode,
|
||||
auth_keyring_backend_kind: AuthKeyringBackendKind,
|
||||
auth_route_config: &AuthRouteConfig,
|
||||
) {
|
||||
if let Err(err) = logout_with_revoke(
|
||||
codex_home,
|
||||
auth_credentials_store_mode,
|
||||
auth_keyring_backend_kind,
|
||||
auth_route_config,
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::warn!("failed to clear existing auth before login: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn login_with_chatgpt(
|
||||
codex_home: PathBuf,
|
||||
forced_chatgpt_workspace_id: Option<Vec<String>>,
|
||||
cli_auth_credentials_store_mode: AuthCredentialsStoreMode,
|
||||
auth_keyring_backend_kind: AuthKeyringBackendKind,
|
||||
auth_route_config: AuthRouteConfig,
|
||||
) -> std::io::Result<()> {
|
||||
clear_existing_auth_before_login(
|
||||
&codex_home,
|
||||
cli_auth_credentials_store_mode,
|
||||
auth_keyring_backend_kind,
|
||||
&auth_route_config,
|
||||
)
|
||||
.await;
|
||||
|
||||
let opts = ServerOptions::new(
|
||||
codex_home,
|
||||
CLIENT_ID.to_string(),
|
||||
forced_chatgpt_workspace_id,
|
||||
cli_auth_credentials_store_mode,
|
||||
auth_keyring_backend_kind,
|
||||
auth_route_config,
|
||||
);
|
||||
let server = run_login_server(opts)?;
|
||||
|
||||
print_login_server_start(server.actual_port, &server.auth_url);
|
||||
|
||||
server.block_until_done().await
|
||||
}
|
||||
|
||||
/// Remote managed configuration (config server / cloud bundles) is not
|
||||
/// supported in aKode: requirements that demand it cannot be satisfied.
|
||||
async fn sign_in_to_config_server_and_reload_config(
|
||||
@@ -186,10 +112,7 @@ async fn sign_in_to_config_server_and_reload_config(
|
||||
|
||||
fn finish_login(result: std::io::Result<()>) -> ! {
|
||||
match result {
|
||||
Ok(_) => {
|
||||
eprintln!("{LOGIN_SUCCESS_MESSAGE}");
|
||||
std::process::exit(0);
|
||||
}
|
||||
Ok(_) => std::process::exit(0),
|
||||
Err(e) => {
|
||||
eprintln!("Error logging in: {e}");
|
||||
std::process::exit(1);
|
||||
@@ -197,54 +120,6 @@ fn finish_login(result: std::io::Result<()>) -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_interactive_login<F>(
|
||||
cli_config_overrides: CliConfigOverrides,
|
||||
chatgpt_login: impl FnOnce(Config) -> F,
|
||||
) -> !
|
||||
where
|
||||
F: std::future::Future<Output = std::io::Result<()>>,
|
||||
{
|
||||
let mut config = load_config_or_exit(cli_config_overrides.clone()).await;
|
||||
if !config
|
||||
.config_layer_stack
|
||||
.requirements_toml()
|
||||
.requires_remote_config()
|
||||
{
|
||||
let _login_log_guard = init_login_file_logging(&config);
|
||||
finish_login(chatgpt_login(config).await);
|
||||
}
|
||||
|
||||
let result =
|
||||
sign_in_to_config_server_and_reload_config(&mut config, &cli_config_overrides).await;
|
||||
let _login_log_guard = init_login_file_logging(&config);
|
||||
finish_login(result)
|
||||
}
|
||||
|
||||
pub async fn run_login_with_browser(cli_config_overrides: CliConfigOverrides) -> ! {
|
||||
run_interactive_login(cli_config_overrides, |config| async move {
|
||||
tracing::info!("starting browser login flow");
|
||||
|
||||
if !config
|
||||
.auth_config()
|
||||
.is_login_method_allowed(ForcedLoginMethod::Chatgpt)
|
||||
{
|
||||
eprintln!("{CHATGPT_LOGIN_DISABLED_MESSAGE}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let effective_chatgpt_workspaces = config.auth_config().effective_chatgpt_workspaces();
|
||||
login_with_chatgpt(
|
||||
config.codex_home.to_path_buf(),
|
||||
effective_chatgpt_workspaces,
|
||||
config.cli_auth_credentials_store_mode,
|
||||
config.auth_keyring_backend_kind(),
|
||||
config.auth_route_config(),
|
||||
)
|
||||
.await
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn run_login_with_api_key(
|
||||
cli_config_overrides: CliConfigOverrides,
|
||||
api_key: String,
|
||||
@@ -278,46 +153,6 @@ pub async fn run_login_with_api_key(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run_login_with_access_token(
|
||||
cli_config_overrides: CliConfigOverrides,
|
||||
access_token: String,
|
||||
) -> ! {
|
||||
let config = load_managed_login_config_or_exit(cli_config_overrides).await;
|
||||
let _login_log_guard = init_login_file_logging(&config);
|
||||
tracing::info!("starting access token login flow");
|
||||
|
||||
if !config
|
||||
.auth_config()
|
||||
.is_login_method_allowed(ForcedLoginMethod::Chatgpt)
|
||||
{
|
||||
eprintln!("{ACCESS_TOKEN_LOGIN_DISABLED_MESSAGE}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let auth_route_config = config.auth_route_config();
|
||||
let effective_chatgpt_workspaces = config.auth_config().effective_chatgpt_workspaces();
|
||||
match login_with_access_token(
|
||||
&config.codex_home,
|
||||
&access_token,
|
||||
config.cli_auth_credentials_store_mode,
|
||||
effective_chatgpt_workspaces.as_deref(),
|
||||
Some(&config.chatgpt_base_url),
|
||||
config.auth_keyring_backend_kind(),
|
||||
&auth_route_config,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
eprintln!("{LOGIN_SUCCESS_MESSAGE}");
|
||||
std::process::exit(0);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error logging in with access token: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_api_key_from_stdin() -> String {
|
||||
read_stdin_secret(
|
||||
"--with-api-key expects the API key on stdin. Try piping it, e.g. `printenv OPENAI_API_KEY | codex login --with-api-key`.",
|
||||
@@ -326,14 +161,6 @@ pub fn read_api_key_from_stdin() -> String {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn read_access_token_from_stdin() -> String {
|
||||
read_stdin_secret(
|
||||
"--with-access-token expects the access token on stdin. Try piping it, e.g. `printenv CODEX_ACCESS_TOKEN | codex login --with-access-token`.",
|
||||
"Reading access token from stdin...",
|
||||
"No access token provided via stdin.",
|
||||
)
|
||||
}
|
||||
|
||||
fn read_stdin_secret(terminal_message: &str, reading_message: &str, empty_message: &str) -> String {
|
||||
let mut stdin = std::io::stdin();
|
||||
|
||||
@@ -360,138 +187,9 @@ fn read_stdin_secret(terminal_message: &str, reading_message: &str, empty_messag
|
||||
}
|
||||
|
||||
/// Login using the OAuth device code flow.
|
||||
pub async fn run_login_with_device_code(
|
||||
cli_config_overrides: CliConfigOverrides,
|
||||
issuer_base_url: Option<String>,
|
||||
client_id: Option<String>,
|
||||
) -> ! {
|
||||
run_interactive_login(cli_config_overrides, |config| async move {
|
||||
tracing::info!("starting device code login flow");
|
||||
if !config
|
||||
.auth_config()
|
||||
.is_login_method_allowed(ForcedLoginMethod::Chatgpt)
|
||||
{
|
||||
eprintln!("{CHATGPT_LOGIN_DISABLED_MESSAGE}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
let auth_route_config = config.auth_route_config();
|
||||
clear_existing_auth_before_login(
|
||||
&config.codex_home,
|
||||
config.cli_auth_credentials_store_mode,
|
||||
config.auth_keyring_backend_kind(),
|
||||
&auth_route_config,
|
||||
)
|
||||
.await;
|
||||
let effective_chatgpt_workspaces = config.auth_config().effective_chatgpt_workspaces();
|
||||
let mut opts = ServerOptions::new(
|
||||
config.codex_home.to_path_buf(),
|
||||
client_id.unwrap_or(CLIENT_ID.to_string()),
|
||||
effective_chatgpt_workspaces,
|
||||
config.cli_auth_credentials_store_mode,
|
||||
config.auth_keyring_backend_kind(),
|
||||
auth_route_config,
|
||||
);
|
||||
if let Some(iss) = issuer_base_url {
|
||||
opts.issuer = iss;
|
||||
}
|
||||
run_device_code_login(opts).await
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// Prefers device-code login (with `open_browser = false`) when headless environment is detected, but keeps
|
||||
/// `codex login` working in environments where device-code may be disabled/feature-gated.
|
||||
/// If `run_device_code_login` returns `ErrorKind::NotFound` ("device-code unsupported"), this
|
||||
/// falls back to starting the local browser login server.
|
||||
pub async fn run_login_with_device_code_fallback_to_browser(
|
||||
cli_config_overrides: CliConfigOverrides,
|
||||
issuer_base_url: Option<String>,
|
||||
client_id: Option<String>,
|
||||
) -> ! {
|
||||
let config = load_config_or_exit(cli_config_overrides).await;
|
||||
let _login_log_guard = init_login_file_logging(&config);
|
||||
tracing::info!("starting login flow with device code fallback");
|
||||
if !config
|
||||
.auth_config()
|
||||
.is_login_method_allowed(ForcedLoginMethod::Chatgpt)
|
||||
{
|
||||
eprintln!("{CHATGPT_LOGIN_DISABLED_MESSAGE}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
let auth_route_config = config.auth_route_config();
|
||||
clear_existing_auth_before_login(
|
||||
&config.codex_home,
|
||||
config.cli_auth_credentials_store_mode,
|
||||
config.auth_keyring_backend_kind(),
|
||||
&auth_route_config,
|
||||
)
|
||||
.await;
|
||||
|
||||
let effective_chatgpt_workspaces = config.auth_config().effective_chatgpt_workspaces();
|
||||
let mut opts = ServerOptions::new(
|
||||
config.codex_home.to_path_buf(),
|
||||
client_id.unwrap_or(CLIENT_ID.to_string()),
|
||||
effective_chatgpt_workspaces,
|
||||
config.cli_auth_credentials_store_mode,
|
||||
config.auth_keyring_backend_kind(),
|
||||
auth_route_config,
|
||||
);
|
||||
if let Some(iss) = issuer_base_url {
|
||||
opts.issuer = iss;
|
||||
}
|
||||
opts.open_browser = false;
|
||||
|
||||
match run_device_code_login(opts.clone()).await {
|
||||
Ok(()) => {
|
||||
eprintln!("{LOGIN_SUCCESS_MESSAGE}");
|
||||
std::process::exit(0);
|
||||
}
|
||||
Err(e) => {
|
||||
if e.kind() == std::io::ErrorKind::NotFound {
|
||||
eprintln!("Device code login is not enabled; falling back to browser login.");
|
||||
match run_login_server(opts) {
|
||||
Ok(server) => {
|
||||
print_login_server_start(server.actual_port, &server.auth_url);
|
||||
match server.block_until_done().await {
|
||||
Ok(()) => {
|
||||
eprintln!("{LOGIN_SUCCESS_MESSAGE}");
|
||||
std::process::exit(0);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error logging in: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error logging in: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eprintln!("Error logging in with device code: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
|
||||
let config = load_config_or_exit(cli_config_overrides).await;
|
||||
|
||||
if is_workload_identity_selected() {
|
||||
match AuthManager::shared_from_config(&config, /*enable_codex_api_key_env*/ false).await {
|
||||
Ok(_) => {
|
||||
eprintln!("Logged in using workload identity");
|
||||
std::process::exit(0);
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error checking login status: {err}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let auth_config = config.auth_config();
|
||||
match auth_config
|
||||
.load_auth(/*enable_codex_api_key_env*/ false)
|
||||
@@ -509,21 +207,9 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
|
||||
std::process::exit(1);
|
||||
}
|
||||
},
|
||||
AuthMode::Chatgpt | AuthMode::ChatgptAuthTokens => {
|
||||
eprintln!("Logged in using ChatGPT");
|
||||
std::process::exit(0);
|
||||
}
|
||||
AuthMode::Headers => {
|
||||
unreachable!("header auth cannot be loaded from auth storage")
|
||||
}
|
||||
AuthMode::AgentIdentity => {
|
||||
eprintln!("Logged in using access token");
|
||||
std::process::exit(0);
|
||||
}
|
||||
AuthMode::PersonalAccessToken => {
|
||||
eprintln!("Logged in using personal access token");
|
||||
std::process::exit(0);
|
||||
}
|
||||
AuthMode::BedrockApiKey => {
|
||||
eprintln!("Logged in using Amazon Bedrock API key");
|
||||
std::process::exit(0);
|
||||
@@ -546,53 +232,17 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
|
||||
|
||||
pub async fn run_logout(cli_config_overrides: CliConfigOverrides) -> ! {
|
||||
let config = load_config_or_exit(cli_config_overrides).await;
|
||||
let auth_route_config = config.auth_route_config();
|
||||
// Cleanup is independent of the current feature gate. Retain the grant lock
|
||||
// through account removal so another process cannot commit a late login.
|
||||
let enterprise_guard = async {
|
||||
let Some(profile) = &config.mcp_enterprise_managed_auth else {
|
||||
return Ok::<_, anyhow::Error>(None);
|
||||
};
|
||||
let auth = config
|
||||
.auth_config()
|
||||
.load_auth(/*enable_codex_api_key_env*/ false)
|
||||
.await?;
|
||||
let Some(scope) = ema_auth_scope(auth.as_ref()) else {
|
||||
return Ok(None);
|
||||
};
|
||||
EnterpriseOAuthCredentialGuard::acquire(
|
||||
&profile.idp.credential_name(&scope),
|
||||
&profile.idp.issuer,
|
||||
config.auth_keyring_backend_kind(),
|
||||
)
|
||||
.await
|
||||
.map(Some)
|
||||
}
|
||||
.await;
|
||||
let cleanup_failed = match &enterprise_guard {
|
||||
Ok(Some(guard)) => guard.delete_tokens().is_err(),
|
||||
Ok(None) => false,
|
||||
Err(_) => true,
|
||||
};
|
||||
if cleanup_failed {
|
||||
eprintln!("Warning: failed to remove enterprise authorization; continuing account logout");
|
||||
}
|
||||
|
||||
let logged_out = match logout_with_revoke(
|
||||
let logged_out = match codex_login::logout(
|
||||
&config.codex_home,
|
||||
config.cli_auth_credentials_store_mode,
|
||||
config.auth_keyring_backend_kind(),
|
||||
&auth_route_config,
|
||||
)
|
||||
.await
|
||||
{
|
||||
) {
|
||||
Ok(logged_out) => logged_out,
|
||||
Err(err) => {
|
||||
eprintln!("Error logging out: {err}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
drop(enterprise_guard);
|
||||
|
||||
let cleared_bedrock_config =
|
||||
if let Some(paths) = ConfigEditsBuilder::bedrock_provider_config_paths_to_clear(&config) {
|
||||
@@ -673,44 +323,10 @@ mod storage_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_login::AuthKeyringBackendKind;
|
||||
use codex_login::load_auth_dot_json;
|
||||
use codex_login::login_with_api_key;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::tempdir;
|
||||
|
||||
use super::clear_existing_auth_before_login;
|
||||
use super::safe_format_key;
|
||||
|
||||
#[tokio::test]
|
||||
async fn clears_existing_auth_before_login() {
|
||||
let codex_home = tempdir().expect("create temporary Codex home");
|
||||
login_with_api_key(
|
||||
codex_home.path(),
|
||||
"sk-existing",
|
||||
AuthCredentialsStoreMode::File,
|
||||
AuthKeyringBackendKind::default(),
|
||||
)
|
||||
.expect("save existing auth");
|
||||
|
||||
clear_existing_auth_before_login(
|
||||
codex_home.path(),
|
||||
AuthCredentialsStoreMode::File,
|
||||
AuthKeyringBackendKind::default(),
|
||||
&codex_login::test_support::transport_default_auth_route_config(),
|
||||
)
|
||||
.await;
|
||||
|
||||
let auth = load_auth_dot_json(
|
||||
codex_home.path(),
|
||||
AuthCredentialsStoreMode::File,
|
||||
AuthKeyringBackendKind::default(),
|
||||
)
|
||||
.expect("load auth after cleanup");
|
||||
assert_eq!(auth, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formats_long_key() {
|
||||
let key = "sk-proj-1234567890ABCDE";
|
||||
|
||||
@@ -7,14 +7,10 @@ use codex_app_server_daemon::BootstrapOptions as AppServerBootstrapOptions;
|
||||
use codex_app_server_daemon::LifecycleCommand as AppServerLifecycleCommand;
|
||||
use codex_arg0::Arg0DispatchPaths;
|
||||
use codex_arg0::arg0_dispatch_or_else;
|
||||
use codex_cli::cloud_config;
|
||||
use codex_cli::read_access_token_from_stdin;
|
||||
use codex_cli::local_config;
|
||||
use codex_cli::read_api_key_from_stdin;
|
||||
use codex_cli::run_login_status;
|
||||
use codex_cli::run_login_with_access_token;
|
||||
use codex_cli::run_login_with_api_key;
|
||||
use codex_cli::run_login_with_browser;
|
||||
use codex_cli::run_login_with_device_code;
|
||||
use codex_cli::run_logout;
|
||||
use codex_exec::Cli as ExecCli;
|
||||
use codex_exec::Command as ExecCommand;
|
||||
@@ -50,9 +46,6 @@ mod config_override_args;
|
||||
mod daemon_install;
|
||||
mod doctor;
|
||||
#[cfg(test)]
|
||||
#[path = "exec_args_tests.rs"]
|
||||
mod exec_args_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "exec_server_args_tests.rs"]
|
||||
mod exec_server_args_tests;
|
||||
mod marketplace_cmd;
|
||||
@@ -498,12 +491,6 @@ struct LoginCommand {
|
||||
)]
|
||||
with_api_key: bool,
|
||||
|
||||
#[arg(
|
||||
long = "with-access-token",
|
||||
help = "Read the access token from stdin (e.g. `printenv CODEX_ACCESS_TOKEN | codex login --with-access-token`)"
|
||||
)]
|
||||
with_access_token: bool,
|
||||
|
||||
#[arg(
|
||||
long = "api-key",
|
||||
num_args = 0..=1,
|
||||
@@ -514,18 +501,6 @@ struct LoginCommand {
|
||||
)]
|
||||
api_key: Option<String>,
|
||||
|
||||
#[arg(long = "device-auth")]
|
||||
use_device_code: bool,
|
||||
|
||||
/// EXPERIMENTAL: Use custom OAuth issuer base URL (advanced)
|
||||
/// Override the OAuth issuer base URL (advanced)
|
||||
#[arg(long = "experimental_issuer", value_name = "URL", hide = true)]
|
||||
issuer_base_url: Option<String>,
|
||||
|
||||
/// EXPERIMENTAL: Use custom OAuth client ID (advanced)
|
||||
#[arg(long = "experimental_client-id", value_name = "CLIENT_ID", hide = true)]
|
||||
client_id: Option<String>,
|
||||
|
||||
#[command(subcommand)]
|
||||
action: Option<LoginSubcommand>,
|
||||
}
|
||||
@@ -547,9 +522,6 @@ struct AppServerCommand {
|
||||
#[command(flatten)]
|
||||
startup_config: codex_app_server::StartupConfigArgs,
|
||||
|
||||
/// Load frozen cloud skills from a JSON snapshot instead of a live skill service.
|
||||
#[arg(long, value_name = "PATH")]
|
||||
cloud_skills_snapshot: Option<PathBuf>,
|
||||
/// Omit to run the app server; specify a subcommand for tooling.
|
||||
#[command(subcommand)]
|
||||
subcommand: Option<AppServerSubcommand>,
|
||||
@@ -1185,7 +1157,6 @@ async fn dispatch_cli(
|
||||
Some(Subcommand::AppServer(app_server_cli)) => {
|
||||
let AppServerCommand {
|
||||
startup_config,
|
||||
cloud_skills_snapshot,
|
||||
subcommand,
|
||||
code_mode_host,
|
||||
strict_config: app_server_strict_config,
|
||||
@@ -1234,7 +1205,6 @@ async fn dispatch_cli(
|
||||
let _ = codex_app_server_daemon::maintain_stderr_log();
|
||||
}
|
||||
let runtime_options = codex_app_server::AppServerRuntimeOptions {
|
||||
cloud_skills_snapshot,
|
||||
code_mode_host_transport: code_mode_host.into(),
|
||||
managed_daemon,
|
||||
// aKode: remote control (chatgpt.com relay) is never started.
|
||||
@@ -1543,19 +1513,7 @@ async fn dispatch_cli(
|
||||
run_login_status(login_cli.config_overrides).await;
|
||||
}
|
||||
None => {
|
||||
if login_cli.with_api_key && login_cli.with_access_token {
|
||||
eprintln!(
|
||||
"Choose one login credential source: --with-api-key or --with-access-token."
|
||||
);
|
||||
std::process::exit(1);
|
||||
} else if login_cli.use_device_code {
|
||||
run_login_with_device_code(
|
||||
login_cli.config_overrides,
|
||||
login_cli.issuer_base_url,
|
||||
login_cli.client_id,
|
||||
)
|
||||
.await;
|
||||
} else if login_cli.api_key.is_some() {
|
||||
if login_cli.api_key.is_some() {
|
||||
eprintln!(
|
||||
"The --api-key flag is no longer supported. Pipe the key instead, e.g. `printenv OPENAI_API_KEY | codex login --with-api-key`."
|
||||
);
|
||||
@@ -1563,11 +1521,11 @@ async fn dispatch_cli(
|
||||
} else if login_cli.with_api_key {
|
||||
let api_key = read_api_key_from_stdin();
|
||||
run_login_with_api_key(login_cli.config_overrides, api_key).await;
|
||||
} else if login_cli.with_access_token {
|
||||
let access_token = read_access_token_from_stdin();
|
||||
run_login_with_access_token(login_cli.config_overrides, access_token).await;
|
||||
} else {
|
||||
run_login_with_browser(login_cli.config_overrides).await;
|
||||
eprintln!(
|
||||
"Only API key login is supported. Pipe the key on stdin, e.g. `printenv OPENAI_API_KEY | codex login --with-api-key`."
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1768,7 +1726,7 @@ async fn dispatch_cli(
|
||||
}
|
||||
|
||||
let config =
|
||||
cloud_config::load_config(&root_config_overrides, LoaderOverrides::default())
|
||||
local_config::load_config(&root_config_overrides, LoaderOverrides::default())
|
||||
.await?;
|
||||
let mut rows = Vec::with_capacity(FEATURES.len());
|
||||
let mut name_width = 0;
|
||||
@@ -2003,7 +1961,6 @@ async fn run_debug_prompt_input_command(
|
||||
.enabled(codex_features::Feature::OmitSkillDescriptions),
|
||||
max_context_tokens: config.skill_max_context_tokens,
|
||||
bundled_skills_enabled: config.bundled_skills_enabled(),
|
||||
cloud_skill_enabled: config.cloud_skill_enabled,
|
||||
shadow_selection_enabled: config
|
||||
.features
|
||||
.enabled(codex_features::Feature::SkillSearch),
|
||||
@@ -2038,21 +1995,7 @@ async fn run_debug_models_command(
|
||||
.await?;
|
||||
let auth_manager =
|
||||
AuthManager::shared_from_config(&config, /*enable_codex_api_key_env*/ true).await?;
|
||||
let runtime_auth = if config.model_catalog.is_none()
|
||||
&& config
|
||||
.features
|
||||
.enabled(codex_features::Feature::RuntimeAgentInstances)
|
||||
{
|
||||
let installation_id = codex_core::resolve_installation_id(&config.codex_home).await?;
|
||||
codex_core::build_runtime_auth_manager(
|
||||
&config,
|
||||
Arc::clone(&auth_manager),
|
||||
&installation_id,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let models_manager = build_models_manager(&config, auth_manager, runtime_auth);
|
||||
let models_manager = build_models_manager(&config, auth_manager);
|
||||
models_manager
|
||||
.raw_model_catalog(
|
||||
RefreshStrategy::OnlineIfUncached,
|
||||
@@ -4157,7 +4100,6 @@ enabled = true
|
||||
"--name",
|
||||
"forwarded",
|
||||
"--strict-config",
|
||||
"--use-agent-identity-auth",
|
||||
])
|
||||
.expect("parse forward");
|
||||
assert!(cli.remote.remote.is_none());
|
||||
|
||||
@@ -24,7 +24,7 @@ use std::collections::HashSet;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::cloud_config;
|
||||
use crate::local_config;
|
||||
use crate::plugin_cmd::JsonMarketplaceSource;
|
||||
use crate::plugin_cmd::configured_marketplace_snapshot_issues;
|
||||
use crate::plugin_cmd::configured_marketplace_sources;
|
||||
@@ -129,7 +129,7 @@ impl MarketplaceCli {
|
||||
subcommand,
|
||||
} = self;
|
||||
|
||||
let builder = cloud_config::config_builder(
|
||||
let builder = local_config::config_builder(
|
||||
&config_overrides,
|
||||
LoaderOverrides::default(),
|
||||
ConfigOverrides::default(),
|
||||
|
||||
@@ -29,7 +29,6 @@ use codex_mcp::McpRuntimeContext;
|
||||
use codex_mcp::apply_http_headers_helper;
|
||||
use codex_mcp::compute_auth_statuses;
|
||||
use codex_mcp::discover_supported_scopes;
|
||||
use codex_mcp::ema_auth_scope;
|
||||
use codex_mcp::oauth_login_support;
|
||||
use codex_mcp::resolve_oauth_callback;
|
||||
use codex_mcp::resolve_oauth_scopes;
|
||||
@@ -38,14 +37,13 @@ use codex_rmcp_client::McpOAuthCallbackMode;
|
||||
use codex_rmcp_client::McpOAuthClientRegistration;
|
||||
use codex_rmcp_client::OAuthDiscoveryTimeout;
|
||||
use codex_rmcp_client::StreamableHttpRedirectMode;
|
||||
use codex_rmcp_client::delete_enterprise_oauth_tokens;
|
||||
use codex_rmcp_client::delete_oauth_tokens;
|
||||
use codex_rmcp_client::resolve_mcp_oauth_callback_url;
|
||||
use codex_utils_cli::CliConfigOverrides;
|
||||
use codex_utils_cli::format_env_display;
|
||||
use codex_utils_redacted_string::RedactedString;
|
||||
|
||||
use crate::cloud_config;
|
||||
use crate::local_config;
|
||||
use crate::mcp_login::McpLoginMode;
|
||||
use crate::mcp_login::perform_oauth_login_retry_without_scopes;
|
||||
|
||||
@@ -249,26 +247,26 @@ impl McpCli {
|
||||
|
||||
match subcommand {
|
||||
McpSubcommand::List(args) => {
|
||||
let config = cloud_config::load_config(&config_overrides, loader_overrides).await?;
|
||||
let config = local_config::load_config(&config_overrides, loader_overrides).await?;
|
||||
run_list(&config, args).await?;
|
||||
}
|
||||
McpSubcommand::Get(args) => {
|
||||
let config = cloud_config::load_config(&config_overrides, loader_overrides).await?;
|
||||
let config = local_config::load_config(&config_overrides, loader_overrides).await?;
|
||||
run_get(&config, args).await?;
|
||||
}
|
||||
McpSubcommand::Add(args) => {
|
||||
let config = cloud_config::load_config(&config_overrides, loader_overrides).await?;
|
||||
let config = local_config::load_config(&config_overrides, loader_overrides).await?;
|
||||
run_add(&config, args).await?;
|
||||
}
|
||||
McpSubcommand::Remove(args) => {
|
||||
run_remove(&config_overrides, args).await?;
|
||||
}
|
||||
McpSubcommand::Login(args) => {
|
||||
let config = cloud_config::load_config(&config_overrides, loader_overrides).await?;
|
||||
let config = local_config::load_config(&config_overrides, loader_overrides).await?;
|
||||
run_login(&config, args).await?;
|
||||
}
|
||||
McpSubcommand::Logout(args) => {
|
||||
let config = cloud_config::load_config(&config_overrides, loader_overrides).await?;
|
||||
let config = local_config::load_config(&config_overrides, loader_overrides).await?;
|
||||
run_logout(&config, args).await?;
|
||||
}
|
||||
}
|
||||
@@ -558,9 +556,7 @@ async fn run_login(config: &Config, login_args: LoginArgs) -> Result<()> {
|
||||
};
|
||||
|
||||
if matches!(server.auth, codex_config::types::McpServerAuth::EmaAuth) {
|
||||
bail!(
|
||||
"Enterprise MCP authorization is managed by Codex account sign-in. Open Codex to sign in."
|
||||
);
|
||||
bail!("Enterprise-managed MCP authorization (`auth = \"ema_auth\"`) is not supported.");
|
||||
}
|
||||
|
||||
let (url, http_headers, env_http_headers) = match &server.transport {
|
||||
@@ -635,33 +631,7 @@ async fn run_logout(config: &Config, logout_args: LogoutArgs) -> Result<()> {
|
||||
.ok_or_else(|| anyhow!("No MCP server named '{name}' found in configuration."))?;
|
||||
|
||||
if matches!(server.auth, McpServerAuth::EmaAuth) {
|
||||
let auth_manager =
|
||||
AuthManager::shared_from_config(config, /*enable_codex_api_key_env*/ true).await?;
|
||||
let auth = auth_manager.auth().await;
|
||||
let scope = ema_auth_scope(auth.as_ref())
|
||||
.context("Sign in to your Codex account before removing enterprise authorization")?;
|
||||
// Cleanup must remain available even when this server is no longer eligible
|
||||
// for EMA (for example, after disabling the feature or changing its transport).
|
||||
let profile = config
|
||||
.mcp_enterprise_managed_auth
|
||||
.as_ref()
|
||||
.context("EMA logout requires a trusted enterprise IdP profile")?;
|
||||
let idp = &profile.idp;
|
||||
let credential_name = idp.credential_name(&scope);
|
||||
match delete_enterprise_oauth_tokens(
|
||||
&credential_name,
|
||||
&idp.issuer,
|
||||
config.auth_keyring_backend_kind(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(true) => println!(
|
||||
"Removed the shared enterprise authorization used by EMA MCP servers (selected via '{name}')."
|
||||
),
|
||||
Ok(false) => println!("No shared enterprise authorization is stored."),
|
||||
Err(_) => return Err(anyhow!("failed to delete enterprise authorization")),
|
||||
}
|
||||
return Ok(());
|
||||
bail!("Enterprise-managed MCP authorization (`auth = \"ema_auth\"`) is not supported.");
|
||||
}
|
||||
|
||||
let url = match &server.transport {
|
||||
@@ -710,8 +680,6 @@ async fn run_list(config: &Config, list_args: ListArgs) -> Result<()> {
|
||||
config.mcp_oauth_credentials_store_mode,
|
||||
config.auth_keyring_backend_kind(),
|
||||
auth.as_ref(),
|
||||
Some(&auth_manager),
|
||||
&runtime_config.ema_state,
|
||||
&runtime_context,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -120,7 +120,7 @@ async fn config_with_application_network(
|
||||
)?;
|
||||
let requirements_path = home.join("requirements.toml");
|
||||
std::fs::write(&requirements_path, requirements)?;
|
||||
crate::cloud_config::load_config(
|
||||
crate::local_config::load_config(
|
||||
&codex_utils_cli::CliConfigOverrides::default(),
|
||||
codex_core::config::LoaderOverrides {
|
||||
system_config_path: Some(home.join("absent-system-config.toml")),
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::bail;
|
||||
use anyhow::ensure;
|
||||
use clap::Parser;
|
||||
use codex_app_server_protocol::PluginAuthPolicy;
|
||||
use codex_app_server_protocol::PluginInstallPolicy;
|
||||
use codex_core::config::Config;
|
||||
use codex_core::config::find_codex_home;
|
||||
use codex_core::plugins_manager_for_config;
|
||||
use codex_core::plugins_manager_for_config_with_runtime;
|
||||
use codex_core_plugins::ConfiguredMarketplace;
|
||||
use codex_core_plugins::OPENAI_BUNDLED_MARKETPLACE_NAME;
|
||||
use codex_core_plugins::PluginInstallOutcome;
|
||||
use codex_core_plugins::PluginInstallRequest;
|
||||
use codex_core_plugins::PluginsConfigInput;
|
||||
use codex_core_plugins::PluginsManager;
|
||||
use codex_core_plugins::RemotePluginInstallRequest;
|
||||
use codex_core_plugins::allowed_configured_marketplace_names;
|
||||
use codex_core_plugins::installed_marketplaces::marketplace_install_root;
|
||||
use codex_core_plugins::installed_marketplaces::resolve_configured_marketplace_root;
|
||||
@@ -24,14 +19,7 @@ use codex_core_plugins::marketplace::MarketplacePluginAuthPolicy;
|
||||
use codex_core_plugins::marketplace::MarketplacePluginInstallPolicy;
|
||||
use codex_core_plugins::marketplace::MarketplacePluginSource;
|
||||
use codex_core_plugins::marketplace::find_marketplace_manifest_path;
|
||||
use codex_core_plugins::remote;
|
||||
use codex_core_plugins::remote::REMOTE_GLOBAL_MARKETPLACE_NAME;
|
||||
use codex_core_plugins::remote::RemoteMarketplace;
|
||||
use codex_core_plugins::remote::RemoteMarketplaceSource;
|
||||
use codex_core_plugins::remote::RemotePluginCatalogCacheMode;
|
||||
use codex_core_plugins::remote::RemotePluginSummary;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_plugin::PluginId;
|
||||
use codex_plugin::validate_plugin_segment;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
@@ -61,13 +49,13 @@ pub struct PluginCli {
|
||||
|
||||
#[derive(Debug, clap::Subcommand)]
|
||||
pub enum PluginSubcommand {
|
||||
/// Install a plugin from a configured or remote marketplace.
|
||||
/// Install a plugin from a configured marketplace.
|
||||
///
|
||||
/// Pass either `PLUGIN@MARKETPLACE` or pass `PLUGIN` with
|
||||
/// `--marketplace MARKETPLACE`.
|
||||
Add(AddPluginArgs),
|
||||
|
||||
/// List plugins available from configured and remote marketplaces.
|
||||
/// List plugins available from configured marketplaces.
|
||||
List(ListPluginsArgs),
|
||||
|
||||
/// Add, list, upgrade, or remove configured plugin marketplaces.
|
||||
@@ -147,63 +135,24 @@ pub async fn run_plugin_add(
|
||||
json,
|
||||
} = args;
|
||||
let selection = parse_plugin_selection(plugin, marketplace_name)?;
|
||||
let context = load_plugin_command_context(overrides, Some(&selection.marketplace_name)).await?;
|
||||
let outcome = if selection.marketplace_name == REMOTE_GLOBAL_MARKETPLACE_NAME {
|
||||
let mut listing = fetch_remote_marketplaces(
|
||||
&context,
|
||||
Some(&selection.marketplace_name),
|
||||
RemotePluginCatalogCacheMode::PreferFreshCache,
|
||||
let context = load_plugin_command_context(overrides).await?;
|
||||
let marketplace = find_marketplace_for_plugin(
|
||||
&context.manager,
|
||||
context.codex_home.as_path(),
|
||||
&context.plugins_input,
|
||||
&selection.marketplace_name,
|
||||
&selection.plugin_name,
|
||||
)?;
|
||||
let outcome = context
|
||||
.manager
|
||||
.install_plugin(
|
||||
&context.plugins_input.config_layer_stack,
|
||||
PluginInstallRequest {
|
||||
plugin_name: selection.plugin_name,
|
||||
marketplace_path: marketplace.path,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
// A newly published plugin may be missing from an otherwise fresh catalog cache.
|
||||
if listing.catalog_cache_used
|
||||
&& !listing
|
||||
.marketplaces
|
||||
.iter()
|
||||
.flat_map(|marketplace| &marketplace.plugins)
|
||||
.any(|plugin| plugin.name == selection.plugin_name)
|
||||
{
|
||||
listing = fetch_remote_marketplaces(
|
||||
&context,
|
||||
Some(&selection.marketplace_name),
|
||||
RemotePluginCatalogCacheMode::ForceRefetch,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
let plugin = resolve_remote_plugin(listing.marketplaces, &selection)?;
|
||||
context
|
||||
.manager
|
||||
.install_remote_plugin(
|
||||
&context.plugins_input,
|
||||
context.auth.as_ref(),
|
||||
RemotePluginInstallRequest {
|
||||
marketplace_name: selection.marketplace_name,
|
||||
remote_plugin_id: plugin.remote_plugin_id,
|
||||
install_attempt_id: None,
|
||||
},
|
||||
/*on_effective_plugins_changed*/ None,
|
||||
)
|
||||
.await?
|
||||
.installed
|
||||
} else {
|
||||
let marketplace = find_marketplace_for_plugin(
|
||||
&context.manager,
|
||||
context.codex_home.as_path(),
|
||||
&context.plugins_input,
|
||||
&selection.marketplace_name,
|
||||
&selection.plugin_name,
|
||||
)?;
|
||||
context
|
||||
.manager
|
||||
.install_plugin(
|
||||
&context.plugins_input.config_layer_stack,
|
||||
PluginInstallRequest {
|
||||
plugin_name: selection.plugin_name,
|
||||
marketplace_path: marketplace.path,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
};
|
||||
let output = JsonPluginAddOutput::from_outcome(outcome);
|
||||
|
||||
if json {
|
||||
@@ -248,13 +197,7 @@ pub async fn run_plugin_list(
|
||||
overrides: Vec<(String, toml::Value)>,
|
||||
args: ListPluginsArgs,
|
||||
) -> Result<()> {
|
||||
let context = load_plugin_command_context(overrides, args.marketplace_name.as_deref()).await?;
|
||||
let remote_listing = fetch_remote_marketplaces(
|
||||
&context,
|
||||
args.marketplace_name.as_deref(),
|
||||
RemotePluginCatalogCacheMode::PreferFreshCache,
|
||||
)
|
||||
.await?;
|
||||
let context = load_plugin_command_context(overrides).await?;
|
||||
let PluginCommandContext {
|
||||
codex_home,
|
||||
plugins_input,
|
||||
@@ -262,11 +205,7 @@ pub async fn run_plugin_list(
|
||||
..
|
||||
} = context;
|
||||
let outcome = manager
|
||||
.list_marketplaces_for_config(
|
||||
&plugins_input,
|
||||
&[],
|
||||
/*include_openai_curated*/ !remote_listing.uses_global_catalog,
|
||||
)
|
||||
.list_marketplaces_for_config(&plugins_input, &[], /*include_openai_curated*/ true)
|
||||
.context("failed to list marketplace plugins")?;
|
||||
ensure_configured_marketplace_snapshots_loaded(
|
||||
codex_home.as_path(),
|
||||
@@ -294,15 +233,9 @@ pub async fn run_plugin_list(
|
||||
})
|
||||
.collect(),
|
||||
name: marketplace.name,
|
||||
path: Some(marketplace.path),
|
||||
path: marketplace.path,
|
||||
}
|
||||
})
|
||||
.chain(
|
||||
remote_listing
|
||||
.marketplaces
|
||||
.into_iter()
|
||||
.map(PluginListMarketplace::from),
|
||||
)
|
||||
.filter(|marketplace| {
|
||||
args.marketplace_name
|
||||
.as_ref()
|
||||
@@ -371,7 +304,6 @@ fn render_plugin_list(
|
||||
};
|
||||
let installed_version = plugin.display_version.clone().unwrap_or_default();
|
||||
let path = match &plugin.source {
|
||||
JsonPluginSource::Remote { id } => id.clone(),
|
||||
JsonPluginSource::Local { path } => path.clone(),
|
||||
JsonPluginSource::Git { url, ref_name, sha }
|
||||
| JsonPluginSource::GitSubdir {
|
||||
@@ -414,11 +346,7 @@ fn render_plugin_list(
|
||||
writeln!(writer)?;
|
||||
}
|
||||
writeln!(writer, "Marketplace `{}`", marketplace.name)?;
|
||||
if let Some(path) = &marketplace.path {
|
||||
writeln!(writer, "{}", path.display())?;
|
||||
} else {
|
||||
writeln!(writer, "Remote catalog")?;
|
||||
}
|
||||
writeln!(writer, "{}", marketplace.path.display())?;
|
||||
writeln!(writer)?;
|
||||
writeln!(
|
||||
writer,
|
||||
@@ -439,48 +367,10 @@ fn render_plugin_list(
|
||||
|
||||
struct PluginListMarketplace {
|
||||
name: String,
|
||||
path: Option<AbsolutePathBuf>,
|
||||
path: AbsolutePathBuf,
|
||||
plugins: Vec<PluginListEntry>,
|
||||
}
|
||||
|
||||
impl From<RemoteMarketplace> for PluginListMarketplace {
|
||||
fn from(marketplace: RemoteMarketplace) -> Self {
|
||||
Self {
|
||||
plugins: marketplace
|
||||
.plugins
|
||||
.into_iter()
|
||||
.map(|plugin| {
|
||||
let version = plugin.local_version.or(plugin.version);
|
||||
PluginListEntry {
|
||||
plugin_id: plugin.id,
|
||||
name: plugin.name,
|
||||
marketplace_name: marketplace.name.clone(),
|
||||
display_version: version.clone(),
|
||||
version,
|
||||
installed: plugin.installed,
|
||||
enabled: plugin.enabled,
|
||||
source: JsonPluginSource::Remote {
|
||||
id: plugin.remote_plugin_id,
|
||||
},
|
||||
marketplace_source: None,
|
||||
install_policy: match plugin.install_policy {
|
||||
PluginInstallPolicy::NotAvailable => "NOT_AVAILABLE",
|
||||
PluginInstallPolicy::Available => "AVAILABLE",
|
||||
PluginInstallPolicy::InstalledByDefault => "INSTALLED_BY_DEFAULT",
|
||||
},
|
||||
auth_policy: match plugin.auth_policy {
|
||||
PluginAuthPolicy::OnInstall => "ON_INSTALL",
|
||||
PluginAuthPolicy::OnUse => "ON_USE",
|
||||
},
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
name: marketplace.name,
|
||||
path: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct JsonPluginListOutput {
|
||||
@@ -558,9 +448,6 @@ impl PluginListEntry {
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(tag = "source", rename_all = "kebab-case")]
|
||||
enum JsonPluginSource {
|
||||
Remote {
|
||||
id: String,
|
||||
},
|
||||
Local {
|
||||
path: String,
|
||||
},
|
||||
@@ -689,43 +576,12 @@ pub async fn run_plugin_remove(
|
||||
json,
|
||||
} = args;
|
||||
let selection = parse_plugin_selection(plugin, marketplace_name)?;
|
||||
let context = load_plugin_command_context(overrides, Some(&selection.marketplace_name)).await?;
|
||||
let context = load_plugin_command_context(overrides).await?;
|
||||
|
||||
if selection.marketplace_name == REMOTE_GLOBAL_MARKETPLACE_NAME {
|
||||
ensure!(
|
||||
context.plugins_input.plugins_enabled,
|
||||
"remote plugins are not enabled"
|
||||
);
|
||||
let auth = context.auth.as_ref();
|
||||
// Installed plugins may no longer appear in the directory or curated collection.
|
||||
let marketplaces = context
|
||||
.manager
|
||||
.build_and_cache_remote_installed_plugin_marketplaces(
|
||||
&context.plugins_input,
|
||||
auth,
|
||||
&[REMOTE_GLOBAL_MARKETPLACE_NAME],
|
||||
/*on_effective_plugins_changed*/ None,
|
||||
)
|
||||
.await?;
|
||||
let plugin = resolve_remote_plugin(marketplaces, &selection)?;
|
||||
let outcome = context
|
||||
.manager
|
||||
.uninstall_remote_plugin(
|
||||
&context.plugins_input,
|
||||
auth,
|
||||
&plugin.remote_plugin_id,
|
||||
/*on_effective_plugins_changed*/ None,
|
||||
)
|
||||
.await?;
|
||||
if let Some(err) = outcome.cache_removal_error {
|
||||
return Err(err.into());
|
||||
}
|
||||
} else {
|
||||
context
|
||||
.manager
|
||||
.uninstall_plugin(selection.plugin_key.clone())
|
||||
.await?;
|
||||
}
|
||||
context
|
||||
.manager
|
||||
.uninstall_plugin(selection.plugin_key.clone())
|
||||
.await?;
|
||||
if json {
|
||||
let output = JsonPluginRemoveOutput::from_selection(selection);
|
||||
println!("{}", serde_json::to_string_pretty(&output)?);
|
||||
@@ -762,12 +618,10 @@ struct PluginCommandContext {
|
||||
codex_home: PathBuf,
|
||||
plugins_input: PluginsConfigInput,
|
||||
manager: Arc<PluginsManager>,
|
||||
auth: Option<CodexAuth>,
|
||||
}
|
||||
|
||||
async fn load_plugin_command_context(
|
||||
overrides: Vec<(String, toml::Value)>,
|
||||
marketplace_name: Option<&str>,
|
||||
) -> Result<PluginCommandContext> {
|
||||
let codex_home = find_codex_home().context("failed to resolve CODEX_HOME")?;
|
||||
let config = Config::load_with_cli_overrides(overrides)
|
||||
@@ -775,20 +629,11 @@ async fn load_plugin_command_context(
|
||||
.context("failed to load configuration")?;
|
||||
let plugins_input = config.plugins_config_input();
|
||||
let auth_manager = load_cli_auth_manager(&config).await?;
|
||||
let auth = auth_manager.auth().await;
|
||||
let uses_remote_catalog = plugins_input.plugins_enabled
|
||||
&& auth.as_ref().is_some_and(CodexAuth::uses_codex_backend)
|
||||
&& marketplace_name.is_none_or(|name| name == REMOTE_GLOBAL_MARKETPLACE_NAME);
|
||||
let manager = Arc::new(if uses_remote_catalog {
|
||||
plugins_manager_for_config_with_runtime(&config, Arc::clone(&auth_manager)).await?
|
||||
} else {
|
||||
plugins_manager_for_config(&config, Arc::clone(&auth_manager))
|
||||
});
|
||||
let manager = Arc::new(plugins_manager_for_config(&config, auth_manager));
|
||||
Ok(PluginCommandContext {
|
||||
codex_home: codex_home.to_path_buf(),
|
||||
plugins_input,
|
||||
manager,
|
||||
auth,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -840,98 +685,6 @@ fn parse_plugin_selection(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct RemoteMarketplaceListing {
|
||||
marketplaces: Vec<RemoteMarketplace>,
|
||||
// A successful global catalog replaces the local curated catalog even when it is empty.
|
||||
uses_global_catalog: bool,
|
||||
catalog_cache_used: bool,
|
||||
}
|
||||
|
||||
async fn fetch_remote_marketplaces(
|
||||
context: &PluginCommandContext,
|
||||
marketplace_name: Option<&str>,
|
||||
cache_mode: RemotePluginCatalogCacheMode,
|
||||
) -> Result<RemoteMarketplaceListing> {
|
||||
if marketplace_name.is_some_and(|name| name != REMOTE_GLOBAL_MARKETPLACE_NAME) {
|
||||
return Ok(RemoteMarketplaceListing::default());
|
||||
}
|
||||
if !context.plugins_input.plugins_enabled {
|
||||
ensure!(marketplace_name.is_none(), "remote plugins are not enabled");
|
||||
return Ok(RemoteMarketplaceListing::default());
|
||||
}
|
||||
let auth = context.auth.as_ref();
|
||||
if !auth.is_some_and(CodexAuth::uses_codex_backend) {
|
||||
ensure!(
|
||||
marketplace_name.is_none(),
|
||||
"chatgpt authentication required for remote plugin catalog"
|
||||
);
|
||||
return Ok(RemoteMarketplaceListing::default());
|
||||
}
|
||||
let service = context
|
||||
.manager
|
||||
.remote_plugin_service_config(&context.plugins_input);
|
||||
let result = if context.plugins_input.remote_plugin_enabled {
|
||||
remote::fetch_remote_marketplaces(
|
||||
&service,
|
||||
auth,
|
||||
&[RemoteMarketplaceSource::Global],
|
||||
/*catalog_cache_root*/ Some(context.codex_home.as_path()),
|
||||
cache_mode,
|
||||
)
|
||||
.await
|
||||
.map(|outcome| RemoteMarketplaceListing {
|
||||
marketplaces: outcome.marketplaces,
|
||||
uses_global_catalog: true,
|
||||
catalog_cache_used: outcome.catalog_cache_used,
|
||||
})
|
||||
} else {
|
||||
remote::fetch_openai_curated_remote_collection_marketplace(
|
||||
&service,
|
||||
auth,
|
||||
/*catalog_cache_root*/ Some(context.codex_home.as_path()),
|
||||
cache_mode,
|
||||
)
|
||||
.await
|
||||
.map(|outcome| RemoteMarketplaceListing {
|
||||
marketplaces: outcome.marketplace.into_iter().collect(),
|
||||
uses_global_catalog: false,
|
||||
catalog_cache_used: outcome.catalog_cache_used,
|
||||
})
|
||||
};
|
||||
match result {
|
||||
Ok(listing) => Ok(listing),
|
||||
Err(err) if marketplace_name.is_none() => {
|
||||
eprintln!("Warning: failed to list remote marketplace plugins: {err}");
|
||||
Ok(RemoteMarketplaceListing::default())
|
||||
}
|
||||
Err(err) => Err(err).context("failed to list remote marketplace plugins"),
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_remote_plugin(
|
||||
marketplaces: Vec<RemoteMarketplace>,
|
||||
selection: &PluginSelection,
|
||||
) -> Result<RemotePluginSummary> {
|
||||
let matches = marketplaces
|
||||
.into_iter()
|
||||
.flat_map(|marketplace| marketplace.plugins)
|
||||
.filter(|plugin| plugin.name == selection.plugin_name)
|
||||
.collect::<Vec<_>>();
|
||||
match matches.as_slice() {
|
||||
[plugin] => Ok(plugin.clone()),
|
||||
[] => bail!(
|
||||
"plugin `{}` was not found in remote marketplace `{}`",
|
||||
selection.plugin_name,
|
||||
selection.marketplace_name
|
||||
),
|
||||
_ => bail!(
|
||||
"plugin `{}` matched multiple remote plugins",
|
||||
selection.plugin_key
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn find_marketplace_for_plugin(
|
||||
manager: &PluginsManager,
|
||||
codex_home: &std::path::Path,
|
||||
|
||||
@@ -95,10 +95,6 @@ Options:
|
||||
--name <NAME>
|
||||
Human-readable environment name
|
||||
|
||||
--use-agent-identity-auth
|
||||
Use Agent Identity auth from CODEX_ACCESS_TOKEN for remote
|
||||
registration
|
||||
|
||||
--registration-bearer-stdin
|
||||
Read one registration bearer from stdin
|
||||
|
||||
@@ -106,12 +102,6 @@ Options:
|
||||
Read rotating executor credentials from stdin; exit when the pipe
|
||||
closes
|
||||
|
||||
--chatgpt-token-stdin
|
||||
Read a ChatGPT access token from stdin for HTTPS registration
|
||||
|
||||
--chatgpt-account-id <ID>
|
||||
ChatGPT account ID. Must match the token's account claim when present
|
||||
|
||||
--aws-sigv4
|
||||
Sign Direct registration and WebSocket handshake requests with AWS
|
||||
SigV4
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
source: cli/src/login_storage_tests.rs
|
||||
assertion_line: 47
|
||||
assertion_line: 52
|
||||
expression: "logs.replace(home.path().join(\"secrets\").to_str().unwrap(),\n\"[SECRETS_PATH]\").replace(&cause, \"[OS_ERROR]\")"
|
||||
---
|
||||
WARN codex_login::auth::storage: failed to save auth to keyring, falling back to file storage: failed to write OAuth tokens to encrypted auth storage: failed to create secrets dir [SECRETS_PATH]: [OS_ERROR]
|
||||
WARN codex_login::auth::storage: failed to save auth to keyring, falling back to file storage: failed to write CLI auth to encrypted auth storage: failed to create secrets dir [SECRETS_PATH]: [OS_ERROR]
|
||||
WARN codex_otel::auth_storage: credential storage file fallback completed credential_kind="codex" store_mode="auto" selected_store="secrets" actual_store="file" operation="save" secure_outcome="error" outcome="success" fallback_reason="secure_error" secure_error="other" storage_phase="policy" originator="none"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
source: cli/src/login_storage_tests.rs
|
||||
assertion_line: 58
|
||||
assertion_line: 81
|
||||
expression: "message.replace(secrets_path.to_str().unwrap(),\n\"[SECRETS_PATH]\").replace(&cause, \"[OS_ERROR]\")"
|
||||
---
|
||||
failed to write OAuth tokens to encrypted auth storage: failed to create secrets dir [SECRETS_PATH]: [OS_ERROR]
|
||||
failed to write CLI auth to encrypted auth storage: failed to create secrets dir [SECRETS_PATH]: [OS_ERROR]
|
||||
|
||||
Reference in New Issue
Block a user