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:
andrea.difonzo
2026-11-10 16:20:15 +01:00
parent 82347a58ed
commit 6089fbde91
1573 changed files with 10289 additions and 177679 deletions

View File

@@ -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),