WIP fase 2b-2: rimosso login ChatGPT/OAuth/device code, agent/workload identity, backend-client; resta solo chiave API (test non tutti verdi)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -35,9 +35,9 @@ pub(crate) async fn program_for_turn(
|
||||
anyhow::ensure!(
|
||||
matches!(
|
||||
read_account(client, request_ids).await?,
|
||||
Some(Account::Chatgpt { .. } | Account::ApiKey { .. })
|
||||
Some(Account::ApiKey { .. })
|
||||
),
|
||||
"Daybreak requires a signed-in ChatGPT account or an OpenAI API key"
|
||||
"Daybreak requires an OpenAI API key"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,6 @@ pub(crate) async fn program_for_turn(
|
||||
return Ok(None);
|
||||
};
|
||||
let eligible = match read_account(client, request_ids).await.unwrap_or(None) {
|
||||
Some(Account::Chatgpt { .. }) => true,
|
||||
Some(Account::ApiKey { .. }) => {
|
||||
features.enabled(Feature::ApiKeyCyberAccessPrograms)
|
||||
}
|
||||
@@ -100,9 +99,7 @@ async fn read_account(
|
||||
let account = client
|
||||
.request_typed::<GetAccountResponse>(ClientRequest::GetAccount {
|
||||
request_id: request_ids.next(),
|
||||
params: GetAccountParams {
|
||||
refresh_token: false,
|
||||
},
|
||||
params: GetAccountParams {},
|
||||
})
|
||||
.await
|
||||
.map_err(|error| {
|
||||
|
||||
@@ -90,7 +90,6 @@ use codex_history::RolloutLine;
|
||||
use codex_login::default_client::set_default_client_residency_requirement;
|
||||
use codex_login::default_client::set_default_originator;
|
||||
use codex_login::enforce_login_restrictions;
|
||||
use codex_login::is_workload_identity_selected;
|
||||
use codex_model_provider_info::LMSTUDIO_OSS_PROVIDER_ID;
|
||||
use codex_model_provider_info::OLLAMA_OSS_PROVIDER_ID;
|
||||
use codex_otel::set_parent_from_context;
|
||||
@@ -680,9 +679,7 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
|
||||
set_default_client_residency_requirement(config.enforce_residency.value());
|
||||
|
||||
if !is_workload_identity_selected()
|
||||
&& let Err(err) = enforce_login_restrictions(&config.auth_config()).await
|
||||
{
|
||||
if let Err(err) = enforce_login_restrictions(&config.auth_config()).await {
|
||||
eprintln!("{err}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
@@ -2240,15 +2237,6 @@ async fn handle_server_request(
|
||||
)
|
||||
.await
|
||||
}
|
||||
ServerRequest::ChatgptAuthTokensRefresh { request_id, .. } => {
|
||||
reject_server_request(
|
||||
client,
|
||||
request_id,
|
||||
&method,
|
||||
"chatgpt auth token refresh is not supported in exec mode".to_string(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
ServerRequest::AttestationGenerate { request_id, .. } => {
|
||||
reject_server_request(
|
||||
client,
|
||||
|
||||
@@ -4,12 +4,7 @@ use core_test_support::responses::mount_sse_once_match;
|
||||
use core_test_support::responses::sse;
|
||||
use core_test_support::responses::start_mock_server;
|
||||
use core_test_support::test_codex_exec::test_codex_exec;
|
||||
use serde_json::json;
|
||||
use wiremock::Mock;
|
||||
use wiremock::ResponseTemplate;
|
||||
use wiremock::matchers::header;
|
||||
use wiremock::matchers::method;
|
||||
use wiremock::matchers::path;
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_uses_codex_api_key_env_var() -> anyhow::Result<()> {
|
||||
@@ -34,162 +29,3 @@ async fn exec_uses_codex_api_key_env_var() -> anyhow::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_api_key_cannot_discard_stored_workspace_network_policy() -> anyhow::Result<()> {
|
||||
let test = test_codex_exec();
|
||||
let policy_server = start_mock_server().await;
|
||||
let inference_server = start_mock_server().await;
|
||||
let token = concat!(
|
||||
"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.",
|
||||
"eyJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsiY2hhdGdwdF9wbGFuX3R5cGUiOiJlbnRlcnByaXNlIiwiY2hhdGdwdF9hY2NvdW50X2lkIjoid29ya3NwYWNlIn19.",
|
||||
"c2lnbmF0dXJl",
|
||||
);
|
||||
std::fs::write(
|
||||
test.home_path().join("auth.json"),
|
||||
serde_json::to_vec(&json!({
|
||||
"auth_mode": "chatgpt",
|
||||
"tokens": {"id_token": token, "access_token": "workspace-token",
|
||||
"refresh_token": "refresh-token", "account_id": "workspace"},
|
||||
"last_refresh": "2099-01-01T00:00:00Z",
|
||||
}))?,
|
||||
)?;
|
||||
std::fs::write(
|
||||
test.home_path().join("config.toml"),
|
||||
format!(
|
||||
"chatgpt_base_url = '{}/backend-api/'\ncli_auth_credentials_store = 'file'\n",
|
||||
policy_server.uri()
|
||||
),
|
||||
)?;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/backend-api/wham/config/bundle"))
|
||||
.and(header("authorization", "Bearer workspace-token"))
|
||||
.and(header("chatgpt-account-id", "workspace"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"requirements_toml": {"enterprise_managed": [{
|
||||
"id": "workspace-network", "name": "Workspace network",
|
||||
"contents": "[application.network]\nenabled = true",
|
||||
}]},
|
||||
})))
|
||||
.expect(1..)
|
||||
.mount(&policy_server)
|
||||
.await;
|
||||
let inference = mount_sse_once_match(
|
||||
&inference_server,
|
||||
header("Authorization", "Bearer dummy"),
|
||||
sse(vec![ev_completed("unexpected-request")]),
|
||||
)
|
||||
.await;
|
||||
|
||||
test.cmd_with_server(&inference_server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("echo testing workspace network policy")
|
||||
.assert()
|
||||
.failure();
|
||||
|
||||
assert!(
|
||||
inference.requests().is_empty(),
|
||||
"an environment API key sent model traffic despite workspace policy"
|
||||
);
|
||||
policy_server.verify().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_bootstrap_rejects_redirected_oauth_and_cloud_policy() -> anyhow::Result<()> {
|
||||
for redirect_oauth in [true, false] {
|
||||
let test = test_codex_exec();
|
||||
let origin = start_mock_server().await;
|
||||
let destination = start_mock_server().await;
|
||||
let inference = start_mock_server().await;
|
||||
let token = concat!(
|
||||
"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.",
|
||||
"eyJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsiY2hhdGdwdF9wbGFuX3R5cGUiOiJlbnRlcnByaXNlIiwiY2hhdGdwdF9hY2NvdW50X2lkIjoid29ya3NwYWNlIn19.",
|
||||
"c2lnbmF0dXJl",
|
||||
);
|
||||
let last_refresh = if redirect_oauth {
|
||||
"2000-01-01T00:00:00Z"
|
||||
} else {
|
||||
"2099-01-01T00:00:00Z"
|
||||
};
|
||||
std::fs::write(
|
||||
test.home_path().join("auth.json"),
|
||||
serde_json::to_vec(&json!({
|
||||
"auth_mode": "chatgpt",
|
||||
"tokens": {"id_token": token, "access_token": "workspace-token",
|
||||
"refresh_token": "refresh-token", "account_id": "workspace"},
|
||||
"last_refresh": last_refresh,
|
||||
}))?,
|
||||
)?;
|
||||
std::fs::write(
|
||||
test.home_path().join("config.toml"),
|
||||
format!(
|
||||
"chatgpt_base_url = '{}/backend-api/'\ncli_auth_credentials_store = 'file'\n",
|
||||
origin.uri()
|
||||
),
|
||||
)?;
|
||||
let cloud_response = if redirect_oauth {
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/oauth/token"))
|
||||
.and(wiremock::matchers::body_string_contains("refresh-token"))
|
||||
.respond_with(
|
||||
ResponseTemplate::new(307)
|
||||
.insert_header("location", format!("{}/stolen", destination.uri())),
|
||||
)
|
||||
.expect(1..)
|
||||
.mount(&origin)
|
||||
.await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/stolen"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"id_token": token, "access_token": "replacement", "refresh_token": "replacement",
|
||||
})))
|
||||
.mount(&destination)
|
||||
.await;
|
||||
ResponseTemplate::new(200).set_body_json(json!({}))
|
||||
} else {
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/policy"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"requirements_toml": {"enterprise_managed": [{
|
||||
"id": "redirected", "name": "Redirected policy",
|
||||
"contents": "[application.network.domains]\n'foreign.example' = 'allow'",
|
||||
}]},
|
||||
})))
|
||||
.mount(&destination)
|
||||
.await;
|
||||
ResponseTemplate::new(308)
|
||||
.insert_header("location", format!("{}/policy", destination.uri()))
|
||||
};
|
||||
let cloud = Mock::given(method("GET"))
|
||||
.and(path("/backend-api/wham/config/bundle"))
|
||||
.respond_with(cloud_response);
|
||||
if redirect_oauth {
|
||||
cloud.mount(&origin).await;
|
||||
} else {
|
||||
cloud.expect(1..).mount(&origin).await;
|
||||
}
|
||||
mount_sse_once_match(
|
||||
&inference,
|
||||
header("Authorization", "Bearer dummy"),
|
||||
sse(vec![ev_completed("request")]),
|
||||
)
|
||||
.await;
|
||||
|
||||
let output = test
|
||||
.cmd_with_server(&inference)
|
||||
.env(
|
||||
codex_login::REFRESH_TOKEN_URL_OVERRIDE_ENV_VAR,
|
||||
format!("{}/oauth/token", origin.uri()),
|
||||
)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("exercise embedded discovery")
|
||||
.output()?;
|
||||
if !redirect_oauth {
|
||||
assert!(!output.status.success());
|
||||
}
|
||||
origin.verify().await;
|
||||
assert!(destination.received_requests().await.unwrap().is_empty());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -163,18 +163,11 @@ async fn configured_daybreak_exec() -> anyhow::Result<(TestCodexExecBuilder, wir
|
||||
{
|
||||
let test = test_codex_exec();
|
||||
let server = responses::start_mock_server().await;
|
||||
let token = concat!(
|
||||
"eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.",
|
||||
"eyJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsiY2hhdGdwdF9wbGFuX3R5cGUiOiJlbnRlcnByaXNlIiwiY2hhdGdwdF9hY2NvdW50X2lkIjoid29ya3NwYWNlIn19.",
|
||||
"c2lnbmF0dXJl",
|
||||
);
|
||||
std::fs::write(
|
||||
test.home_path().join("auth.json"),
|
||||
serde_json::to_vec(&json!({
|
||||
"auth_mode": "chatgpt",
|
||||
"tokens": {"id_token": token, "access_token": "test-token",
|
||||
"refresh_token": "refresh-token", "account_id": "workspace"},
|
||||
"last_refresh": "2099-01-01T00:00:00Z"
|
||||
"auth_mode": "apikey",
|
||||
"OPENAI_API_KEY": "test-token",
|
||||
}))?,
|
||||
)?;
|
||||
let catalog = test.home_path().join("catalog.json");
|
||||
@@ -197,21 +190,6 @@ async fn configured_daybreak_exec() -> anyhow::Result<(TestCodexExecBuilder, wir
|
||||
catalog.display()
|
||||
),
|
||||
)?;
|
||||
wiremock::Mock::given(wiremock::matchers::method("GET"))
|
||||
.and(wiremock::matchers::path("/backend-api/wham/config/bundle"))
|
||||
.respond_with(wiremock::ResponseTemplate::new(200).set_body_json(json!({
|
||||
"config_toml": {"enterprise_managed": []}
|
||||
})))
|
||||
.mount(&server)
|
||||
.await;
|
||||
wiremock::Mock::given(wiremock::matchers::method("GET"))
|
||||
.and(wiremock::matchers::path("/backend-api/wham/accounts/check"))
|
||||
.respond_with(wiremock::ResponseTemplate::new(200).set_body_json(json!({
|
||||
"accounts": [{"id": "workspace", "workspace_backend_origin": "https://chatgpt.com",
|
||||
"account_routing_override": "NO_CONSTRAINT"}]
|
||||
})))
|
||||
.mount(&server)
|
||||
.await;
|
||||
Ok((test, server))
|
||||
}
|
||||
|
||||
|
||||
@@ -255,127 +255,6 @@ async fn worktree_start_and_fork_use_host_pool_and_preserve_legacy_resume() -> a
|
||||
}
|
||||
assert!(!home.join("worktrees").exists());
|
||||
|
||||
// Synthetic enterprise claims let the cloud bundle, not a local project entry,
|
||||
// supply the source's distrust decision.
|
||||
fs::write(
|
||||
home.join("auth.json"),
|
||||
serde_json::to_vec(&serde_json::json!({
|
||||
"auth_mode": "chatgpt",
|
||||
"tokens": {
|
||||
"id_token": "e30.eyJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsiY2hhdGdwdF9wbGFuX3R5cGUiOiJlbnRlcnByaXNlIiwiY2hhdGdwdF9hY2NvdW50X2lkIjoid29ya3NwYWNlLTEyMyIsImNoYXRncHRfdXNlcl9pZCI6InVzZXItMTIzIn19.signature",
|
||||
"access_token": "test-access-token",
|
||||
"refresh_token": "test-refresh-token",
|
||||
"account_id": "workspace-123"
|
||||
}
|
||||
}))?,
|
||||
)?;
|
||||
fs::write(
|
||||
home.join("config.toml"),
|
||||
format!(
|
||||
"features.worktrees=true\ncli_auth_credentials_store=\"file\"\nchatgpt_base_url=\"{}/backend-api\"\n",
|
||||
server.uri(),
|
||||
),
|
||||
)?;
|
||||
wiremock::Mock::given(wiremock::matchers::method("GET"))
|
||||
.and(wiremock::matchers::path("/backend-api/wham/config/bundle"))
|
||||
.respond_with(
|
||||
wiremock::ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"config_toml": { "enterprise_managed": [{
|
||||
"id": "source-trust", "name": "Source trust",
|
||||
"contents": format!(
|
||||
"[projects.{}]\ntrust_level=\"untrusted\"\n[projects.{}]\ntrust_level=\"untrusted\"\n",
|
||||
serde_json::to_string(&source)?,
|
||||
serde_json::to_string(&legacy.cwd.join("extra"))?,
|
||||
)
|
||||
}] }
|
||||
})),
|
||||
)
|
||||
.mount(&server)
|
||||
.await;
|
||||
for args in [vec!["prompt"], vec!["fork", legacy_id.as_str(), "prompt"]] {
|
||||
let request_count = if args.first() == Some(&"fork") {
|
||||
// The saved checkout can choose file auth even when the launcher does not.
|
||||
fs::remove_file(source.join(".codex/config.toml"))?;
|
||||
fs::create_dir_all(legacy.cwd.join(".codex"))?;
|
||||
fs::write(
|
||||
legacy.cwd.join(".codex/config.toml"),
|
||||
"cli_auth_credentials_store=\"file\"\n",
|
||||
)?;
|
||||
git(&legacy.cwd, &["add", ".codex/config.toml"])?;
|
||||
git(
|
||||
&legacy.cwd,
|
||||
&["commit", "--quiet", "--no-gpg-sign", "-m", "file auth"],
|
||||
)?;
|
||||
fs::write(
|
||||
home.join("config.toml"),
|
||||
format!(
|
||||
"features.worktrees=true\ncli_auth_credentials_store=\"ephemeral\"\nchatgpt_base_url=\"{}/backend-api\"\n[projects.{}]\ntrust_level=\"trusted\"\n",
|
||||
server.uri(),
|
||||
serde_json::to_string(&source)?,
|
||||
),
|
||||
)?;
|
||||
let cache = home.join("cloud-config-bundle-cache.json");
|
||||
if cache.exists() {
|
||||
fs::remove_file(&cache)?;
|
||||
}
|
||||
Some(server.received_requests().await.context("requests")?.len())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let output = test
|
||||
.cmd()
|
||||
.current_dir(if request_count.is_some() {
|
||||
launcher.path()
|
||||
} else {
|
||||
&source
|
||||
})
|
||||
.env_remove("CODEX_API_KEY")
|
||||
.env_remove("OPENAI_API_KEY")
|
||||
.env_remove("CODEX_ACCESS_TOKEN")
|
||||
.args(["--json", "--worktree", "--strict-config"])
|
||||
.args(args)
|
||||
.output()?;
|
||||
assert!(
|
||||
!output.status.success()
|
||||
&& String::from_utf8_lossy(&output.stderr).contains("explicitly untrusted"),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
if let Some(request_count) = request_count {
|
||||
assert!(!String::from_utf8_lossy(&output.stdout).contains("thread.started"));
|
||||
let denied_manager =
|
||||
WorktreeManager::new(WorktreeSettings::for_cli(&home, /*desktop*/ None)?);
|
||||
let checkout = denied_manager
|
||||
.list(&legacy.cwd)?
|
||||
.into_iter()
|
||||
.next()
|
||||
.context("denied checkout remains for manual removal")?;
|
||||
assert_eq!(denied_manager.owner(&checkout.root)?, None);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert!(
|
||||
stderr.contains(
|
||||
checkout
|
||||
.root
|
||||
.file_name()
|
||||
.context("checkout name")?
|
||||
.to_string_lossy()
|
||||
.as_ref()
|
||||
)
|
||||
);
|
||||
assert!(stderr.contains("Remove it manually with `git worktree remove`"));
|
||||
assert!(
|
||||
server
|
||||
.received_requests()
|
||||
.await
|
||||
.context("requests")?
|
||||
.iter()
|
||||
.skip(request_count)
|
||||
.any(|request| request.url.path() == "/backend-api/wham/config/bundle")
|
||||
);
|
||||
} else {
|
||||
assert!(!home.join("worktrees").exists());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user