Lightweight coding agent that runs in your terminal
Rust
Redact Bedrock API keys from debug output (#40706)
alexsong-oai13fe2bcb7a3b
diff --git a/codex-rs/login/src/auth/bedrock_api_key.rs b/codex-rs/login/src/auth/bedrock_api_key.rsindex cae6ddf548..a101aa74fe 100644--- a/codex-rs/login/src/auth/bedrock_api_key.rs+++ b/codex-rs/login/src/auth/bedrock_api_key.rs@@ -1,3 +1,4 @@+use std::fmt;use std::path::Path;use codex_config::types::AuthCredentialsStoreMode;@@ -10,12 +11,21 @@ use super::storage::AuthKeyringBackendKind;use codex_protocol::auth::AuthMode;/// Managed Amazon Bedrock API key persisted in `auth.json`.-#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]+#[derive(Deserialize, Serialize, Clone, PartialEq, Eq)]pub struct BedrockApiKeyAuth {pub api_key: String,pub region: String,}+impl fmt::Debug for BedrockApiKeyAuth {+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {+ f.debug_struct("BedrockApiKeyAuth")+ .field("api_key", &"<redacted>")+ .field("region", &self.region)+ .finish()+ }+}+/// Writes an `auth.json` that contains only the Amazon Bedrock API key auth.pub fn login_with_bedrock_api_key(codex_home: &Path,diff --git a/codex-rs/login/src/auth/bedrock_api_key_tests.rs b/codex-rs/login/src/auth/bedrock_api_key_tests.rsindex 70764abff8..cdb3273213 100644--- a/codex-rs/login/src/auth/bedrock_api_key_tests.rs+++ b/codex-rs/login/src/auth/bedrock_api_key_tests.rs@@ -44,6 +44,20 @@ fn bedrock_auth() -> BedrockApiKeyAuth {}}+#[test]+fn bedrock_api_key_debug_redacts_secret() {+ let auth = bedrock_auth();++ assert_eq!(+ format!("{auth:?}"),+ r#"BedrockApiKeyAuth { api_key: "<redacted>", region: "us-east-1" }"#+ );+ assert_eq!(+ format!("{:?}", CodexAuth::BedrockApiKey(auth)),+ r#"BedrockApiKey(BedrockApiKeyAuth { api_key: "<redacted>", region: "us-east-1" })"#+ );+}+#[tokio::test]#[serial(codex_auth_env)]async fn login_with_bedrock_api_key_replaces_openai_auth() -> anyhow::Result<()> {