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:
@@ -2,9 +2,6 @@
|
||||
#[path = "exec_server/pid_namespace_tests.rs"]
|
||||
mod pid_namespace_tests;
|
||||
|
||||
#[path = "exec_server/auth_refresh_tests.rs"]
|
||||
mod auth_refresh_tests;
|
||||
|
||||
use std::collections::HashMap;
|
||||
#[cfg(unix)]
|
||||
use std::io::BufRead as _;
|
||||
@@ -206,250 +203,6 @@ fn local_exec_server_allows_disabled_parent_lifetime_environment_variable() -> R
|
||||
Ok(())
|
||||
}
|
||||
|
||||
enum PatCredentialChange {
|
||||
Rotate,
|
||||
SwitchAccount,
|
||||
Logout,
|
||||
Unchanged,
|
||||
UnavailableReplacement,
|
||||
SlowReplacement,
|
||||
}
|
||||
|
||||
async fn assert_pat_registry_reload(change: PatCredentialChange) -> Result<()> {
|
||||
let home = TempDir::new()?;
|
||||
let config_server = MockServer::start().await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/backend-api/wham/config/bundle"))
|
||||
.and(header("authorization", "Bearer at-synthetic-executor-pat"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"config_toml": {"enterprise_managed": []},
|
||||
"requirements_toml": {"enterprise_managed": []},
|
||||
})))
|
||||
.expect(1)
|
||||
.mount(&config_server)
|
||||
.await;
|
||||
std::fs::write(
|
||||
home.path().join("config.toml"),
|
||||
format!(
|
||||
"cli_auth_credentials_store = 'file'\nchatgpt_base_url = '{}/backend-api'\n",
|
||||
config_server.uri(),
|
||||
),
|
||||
)?;
|
||||
let auth_path = home.path().join("auth.json");
|
||||
std::fs::write(
|
||||
&auth_path,
|
||||
serde_json::to_vec(&serde_json::json!({
|
||||
"personal_access_token": "at-synthetic-executor-pat",
|
||||
}))?,
|
||||
)?;
|
||||
let auth_server = MockServer::start().await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/v1/user-auth-credential/whoami"))
|
||||
.and(header("authorization", "Bearer at-synthetic-executor-pat"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"chatgpt_user_id": "user-pat-test",
|
||||
"chatgpt_account_id": "account-pat-test",
|
||||
"chatgpt_plan_type": "enterprise",
|
||||
"chatgpt_account_is_fedramp": false,
|
||||
})))
|
||||
// Cloud-config bootstrap and executor startup each hydrate once.
|
||||
// Later registry requests must reuse metadata for the unchanged PAT.
|
||||
.with_priority(1)
|
||||
.up_to_n_times(2)
|
||||
.expect(2)
|
||||
.mount(&auth_server)
|
||||
.await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/v1/user-auth-credential/whoami"))
|
||||
.respond_with(ResponseTemplate::new(503))
|
||||
.with_priority(10)
|
||||
.expect(0)
|
||||
.mount(&auth_server)
|
||||
.await;
|
||||
if !matches!(
|
||||
change,
|
||||
PatCredentialChange::Logout | PatCredentialChange::Unchanged
|
||||
) {
|
||||
let account = match change {
|
||||
PatCredentialChange::Rotate
|
||||
| PatCredentialChange::UnavailableReplacement
|
||||
| PatCredentialChange::SlowReplacement => "account-pat-test",
|
||||
PatCredentialChange::SwitchAccount => "another-account",
|
||||
PatCredentialChange::Logout | PatCredentialChange::Unchanged => unreachable!(),
|
||||
};
|
||||
if matches!(change, PatCredentialChange::UnavailableReplacement) {
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/v1/user-auth-credential/whoami"))
|
||||
.and(header(
|
||||
"authorization",
|
||||
"Bearer at-synthetic-replacement-pat",
|
||||
))
|
||||
.respond_with(ResponseTemplate::new(503))
|
||||
.with_priority(1)
|
||||
.up_to_n_times(1)
|
||||
.expect(1)
|
||||
.mount(&auth_server)
|
||||
.await;
|
||||
}
|
||||
let response = ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"chatgpt_user_id": "user-pat-test",
|
||||
"chatgpt_account_id": account,
|
||||
"chatgpt_plan_type": "enterprise",
|
||||
"chatgpt_account_is_fedramp": false,
|
||||
}));
|
||||
// Exceed registration's 10-second deadline while the detached auth
|
||||
// resolution can still finish within its own 30-second budget.
|
||||
let response = if matches!(change, PatCredentialChange::SlowReplacement) {
|
||||
response.set_delay(Duration::from_secs(11))
|
||||
} else {
|
||||
response
|
||||
};
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/v1/user-auth-credential/whoami"))
|
||||
.and(header(
|
||||
"authorization",
|
||||
"Bearer at-synthetic-replacement-pat",
|
||||
))
|
||||
.respond_with(response)
|
||||
.with_priority(2)
|
||||
.expect(1)
|
||||
.mount(&auth_server)
|
||||
.await;
|
||||
}
|
||||
let expected_registry_requests = match change {
|
||||
PatCredentialChange::Rotate
|
||||
| PatCredentialChange::Unchanged
|
||||
| PatCredentialChange::UnavailableReplacement
|
||||
| PatCredentialChange::SlowReplacement => 2,
|
||||
PatCredentialChange::SwitchAccount | PatCredentialChange::Logout => 1,
|
||||
};
|
||||
let second_bearer = if matches!(change, PatCredentialChange::Unchanged) {
|
||||
"Bearer at-synthetic-executor-pat"
|
||||
} else {
|
||||
"Bearer at-synthetic-replacement-pat"
|
||||
};
|
||||
let registry = MockServer::start().await;
|
||||
let registration_path = "/cloud/environment/environment-pat-test/register";
|
||||
let (credential_change_tx, mut credential_change_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
Mock::given(method("POST"))
|
||||
.and(path(registration_path))
|
||||
.and(header("authorization", "Bearer at-synthetic-executor-pat"))
|
||||
.and(header("chatgpt-account-id", "account-pat-test"))
|
||||
.respond_with(move |_: &wiremock::Request| {
|
||||
let result = match change {
|
||||
PatCredentialChange::Rotate
|
||||
| PatCredentialChange::SwitchAccount
|
||||
| PatCredentialChange::UnavailableReplacement
|
||||
| PatCredentialChange::SlowReplacement => std::fs::write(
|
||||
&auth_path,
|
||||
r#"{"personal_access_token":"at-synthetic-replacement-pat"}"#,
|
||||
),
|
||||
PatCredentialChange::Logout => std::fs::remove_file(&auth_path),
|
||||
PatCredentialChange::Unchanged => Ok(()),
|
||||
};
|
||||
let _ = credential_change_tx.send(result);
|
||||
ResponseTemplate::new(502).set_body_json(serde_json::json!({
|
||||
"detail": {"code": "authentication_service_unavailable"},
|
||||
}))
|
||||
})
|
||||
.with_priority(1)
|
||||
.up_to_n_times(1)
|
||||
.expect(1)
|
||||
.mount(®istry)
|
||||
.await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path(registration_path))
|
||||
.and(header("authorization", second_bearer))
|
||||
.and(header("chatgpt-account-id", "account-pat-test"))
|
||||
.respond_with(ResponseTemplate::new(403))
|
||||
.with_priority(2)
|
||||
.expect(expected_registry_requests - 1)
|
||||
.mount(®istry)
|
||||
.await;
|
||||
|
||||
let mut command = tokio::process::Command::new(codex_utils_cargo_bin::cargo_bin("codex")?);
|
||||
command
|
||||
.current_dir(home.path())
|
||||
.env("CODEX_HOME", home.path())
|
||||
.env_remove("CODEX_ACCESS_TOKEN")
|
||||
.env("CODEX_AUTHAPI_BASE_URL", auth_server.uri())
|
||||
.env_remove("CODEX_API_KEY")
|
||||
.env_remove("OPENAI_API_KEY")
|
||||
.env("NO_PROXY", "127.0.0.1,localhost")
|
||||
.env("no_proxy", "127.0.0.1,localhost")
|
||||
.args([
|
||||
"exec-server",
|
||||
"--remote",
|
||||
®istry.uri(),
|
||||
"--environment-id",
|
||||
"environment-pat-test",
|
||||
])
|
||||
.kill_on_drop(true);
|
||||
// A same-owner replacement reaches the second registry request, whose denial
|
||||
// stops the executor. Logout or a different owner must fail before that request.
|
||||
let result = tokio::time::timeout(Duration::from_secs(30), command.output()).await;
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"executor timed out (AuthAPI request count: {:?})",
|
||||
auth_server
|
||||
.received_requests()
|
||||
.await
|
||||
.map(|requests| requests.len()),
|
||||
);
|
||||
let output = result??;
|
||||
let credential_update = credential_change_rx.try_recv();
|
||||
assert!(
|
||||
credential_update.is_ok(),
|
||||
"registration did not update the credential fixture ({}): {}",
|
||||
output.status,
|
||||
String::from_utf8_lossy(&output.stderr),
|
||||
);
|
||||
credential_update?.context("update the stored PAT fixture")?;
|
||||
assert!(!output.status.success());
|
||||
registry.verify().await;
|
||||
auth_server.verify().await;
|
||||
config_server.verify().await;
|
||||
assert_eq!(
|
||||
registry
|
||||
.received_requests()
|
||||
.await
|
||||
.context("registry request recording is disabled")?
|
||||
.len(),
|
||||
expected_registry_requests as usize
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_exec_server_pat_follows_stored_rotation() -> Result<()> {
|
||||
assert_pat_registry_reload(PatCredentialChange::Rotate).await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_exec_server_pat_rejects_account_switch() -> Result<()> {
|
||||
assert_pat_registry_reload(PatCredentialChange::SwitchAccount).await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_exec_server_pat_stops_using_removed_credentials() -> Result<()> {
|
||||
assert_pat_registry_reload(PatCredentialChange::Logout).await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_exec_server_pat_reuses_metadata_during_authapi_outage() -> Result<()> {
|
||||
assert_pat_registry_reload(PatCredentialChange::Unchanged).await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_exec_server_pat_recovers_after_replacement_metadata_outage() -> Result<()> {
|
||||
assert_pat_registry_reload(PatCredentialChange::UnavailableReplacement).await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_exec_server_pat_recovers_after_replacement_metadata_timeout() -> Result<()> {
|
||||
assert_pat_registry_reload(PatCredentialChange::SlowReplacement).await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_exec_server_gracefully_stops_when_parent_stdin_closes() -> Result<()> {
|
||||
const ENVIRONMENT_ID: &str = "environment-parent-lifetime";
|
||||
@@ -1121,3 +874,55 @@ async fn wait_for_response(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// API-key registration authenticates directly and never fetches account-managed
|
||||
/// cloud configuration before registering.
|
||||
#[tokio::test]
|
||||
async fn remote_exec_server_api_key_registers_without_cloud_config() -> Result<()> {
|
||||
const REGISTER: &str = "/cloud/environment/test/register";
|
||||
const REGISTRATION_REACHED: &str = "registration reached";
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path(REGISTER))
|
||||
.and(header("authorization", "Bearer test-api-key"))
|
||||
.respond_with(ResponseTemplate::new(400).set_body_string(REGISTRATION_REACHED))
|
||||
.mount(&server)
|
||||
.await;
|
||||
let home = TempDir::new()?;
|
||||
std::fs::write(
|
||||
home.path().join("config.toml"),
|
||||
"cli_auth_credentials_store = \"file\"\n",
|
||||
)?;
|
||||
let output = tokio::time::timeout(
|
||||
Duration::from_secs(30),
|
||||
tokio::process::Command::new(codex_utils_cargo_bin::cargo_bin("codex")?)
|
||||
.kill_on_drop(true)
|
||||
.current_dir(home.path())
|
||||
.env("CODEX_HOME", home.path())
|
||||
.env("NO_PROXY", "127.0.0.1,localhost")
|
||||
.env("no_proxy", "127.0.0.1,localhost")
|
||||
.env_remove("OPENAI_API_KEY")
|
||||
.env("CODEX_API_KEY", "test-api-key")
|
||||
.args([
|
||||
"exec-server",
|
||||
"--remote",
|
||||
&server.uri(),
|
||||
"--environment-id",
|
||||
"test",
|
||||
])
|
||||
.output(),
|
||||
)
|
||||
.await??;
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert!(
|
||||
!output.status.success() && stderr.contains(REGISTRATION_REACHED),
|
||||
"{stderr}"
|
||||
);
|
||||
let requests = server
|
||||
.received_requests()
|
||||
.await
|
||||
.context("mock request log")?;
|
||||
let paths: Vec<_> = requests.iter().map(|request| request.url.path()).collect();
|
||||
assert_eq!(paths, vec![REGISTER]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user