From b6743d7ea8e952e675c847fd29326e06e33a4855 Mon Sep 17 00:00:00 2001 From: Alvin Date: Tue, 1 Dec 2026 23:36:32 +0000 Subject: [PATCH] Report workload identity authentication in `codex doctor` (#65142) ## Why `codex doctor` could report missing credentials when workload identity was selected and no local credentials were stored. ## What changed Use the auth manager's workload identity selection to report authentication as successful and show how to check it with `codex login status`. ## Testing Add a regression test that checks the terminal and redacted JSON reports for workload identity with no stored credentials. GitOrigin-RevId: cf385cf2cb71cc8aed95427ef83524bab4582702 --- codex-rs/cli/src/doctor.rs | 18 +++++++- codex-rs/cli/src/doctor/auth_tests.rs | 66 +++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 codex-rs/cli/src/doctor/auth_tests.rs diff --git a/codex-rs/cli/src/doctor.rs b/codex-rs/cli/src/doctor.rs index 16b1e1fa9f..1fecf682ca 100644 --- a/codex-rs/cli/src/doctor.rs +++ b/codex-rs/cli/src/doctor.rs @@ -92,6 +92,9 @@ mod updates; #[cfg(target_os = "windows")] mod windows_dev_drive; +#[cfg(test)] +#[path = "doctor/auth_tests.rs"] +mod auth_tests; #[cfg(test)] #[path = "doctor/desktop_tests.rs"] mod desktop_tests; @@ -445,7 +448,7 @@ async fn build_report( }, async { run_sync_check("auth", progress.clone(), || match &auth_manager_result { - Ok(_) => auth_check(config), + Ok(manager) => auth_check(config, manager.is_workload_identity_selected()), Err(error) => DoctorCheck::new( "auth.load", "auth", @@ -1227,7 +1230,7 @@ fn config_toml_details(config: &Config, details: &mut Vec) { } } -fn auth_check(config: &Config) -> DoctorCheck { +fn auth_check(config: &Config, workload_identity_authenticated: bool) -> DoctorCheck { let mut details = Vec::new(); let auth_path = config.codex_home.join("auth.json"); details.push(format!( @@ -1260,6 +1263,17 @@ fn auth_check(config: &Config) -> DoctorCheck { return check; } + if workload_identity_authenticated { + return DoctorCheck::new( + "auth.credentials", + "auth", + CheckStatus::Ok, + "authenticated using workload identity", + ) + .details(details) + .detail("Run codex login status to check the current login."); + } + match load_auth_dot_json( &config.codex_home, config.cli_auth_credentials_store_mode, diff --git a/codex-rs/cli/src/doctor/auth_tests.rs b/codex-rs/cli/src/doctor/auth_tests.rs new file mode 100644 index 0000000000..ca81339148 --- /dev/null +++ b/codex-rs/cli/src/doctor/auth_tests.rs @@ -0,0 +1,66 @@ +#![cfg(test)] + +use codex_core::config::ConfigBuilder; +use pretty_assertions::assert_eq; + +use super::HumanOutputOptions; +use super::auth_check; +use super::redacted_json_report; +use super::render_human_report; +use super::report_from_checks; + +#[tokio::test] +async fn auth_check_reports_authenticated_workload_identity_without_stored_credentials() { + let home = tempfile::tempdir().expect("create Codex home"); + let config = ConfigBuilder::default() + .codex_home(home.path().to_path_buf()) + .build() + .await + .expect("load doctor config"); + + let mut check = auth_check(&config, /*workload_identity_authenticated*/ true); + // Stabilize the host-specific details for the terminal snapshot. + check + .details + .retain(|detail| !detail.starts_with("auth env vars present: ")); + if let Some(auth_file) = check + .details + .iter_mut() + .find(|detail| detail.starts_with("auth file: ")) + { + *auth_file = "auth file: /codex-home/auth.json".to_string(); + } + + let mut report = report_from_checks(vec![check]); + report.codex_version = "1.2.3".to_string(); + let rendered = render_human_report( + &report, + HumanOutputOptions { + show_details: true, + show_all: false, + ascii: false, + color_enabled: false, + }, + ); + insta::assert_snapshot!(rendered, @r" + Codex Doctor v1.2.3 + + Configuration + ✓ auth authenticated using workload identity + auth storage mode File + auth.json path (file backend/fallback) /codex-home/auth.json + · Run codex login status to check the current login. + + ───────────────────────────────────────────────────────────── + 1 ok · 0 warn · 0 fail ok + + --summary compact output --all expand truncated lists + --json redacted report + "); + + let report = serde_json::to_value(redacted_json_report(&report)).expect("serialize report"); + let check = &report["checks"]["auth.credentials"]; + + assert_eq!(check["status"], "ok"); + assert_eq!(check["summary"], "authenticated using workload identity"); +}