mirror of
https://github.com/openai/codex.git
synced 2026-11-08 20:40:33 +00:00
Propagate authentication header failures before sending requests (#55607)
## Why Synchronous auth header construction could silently return no credentials when managed authentication became unavailable. Callers need an error to avoid sending requests with missing or partial authentication. ## What changed - Make `AuthProvider::add_auth_headers`, `to_auth_headers`, and auth header telemetry fallible, and propagate failures through request and WebSocket setup. - Return a transient error when managed authentication is unavailable, and preserve network policy denials through auth error conversion. - Retry transient MCP authentication errors while treating build errors and policy denials as terminal. - Cancel local MCP event streams before resolving authentication so cleanup still works when credentials become unavailable. ## Testing Add regression coverage for rejected partial authentication, async header resolution, terminal auth errors without sending requests, managed account changes, MCP retry classification, and local stream cancellation after authentication becomes unavailable. GitOrigin-RevId: 39d981e232cba1e302de502a2fa6239101114ed1
This commit is contained in:
@@ -563,7 +563,7 @@ impl std::fmt::Debug for StaticBearerAuthProvider {
|
||||
}
|
||||
|
||||
impl AuthProvider for StaticBearerAuthProvider {
|
||||
fn add_auth_headers(&self, headers: &mut HeaderMap) {
|
||||
fn add_auth_headers(&self, headers: &mut HeaderMap) -> Result<(), codex_api::AuthError> {
|
||||
headers.insert(http::header::AUTHORIZATION, self.authorization.clone());
|
||||
if let Some(chatgpt_account_id) = &self.chatgpt_account_id {
|
||||
headers.insert(
|
||||
@@ -571,6 +571,7 @@ impl AuthProvider for StaticBearerAuthProvider {
|
||||
chatgpt_account_id.clone(),
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1133,7 +1134,9 @@ mod tests {
|
||||
struct StaticRegistryAuthProvider;
|
||||
|
||||
impl AuthProvider for StaticRegistryAuthProvider {
|
||||
fn add_auth_headers(&self, _headers: &mut HeaderMap) {}
|
||||
fn add_auth_headers(&self, _headers: &mut HeaderMap) -> Result<(), codex_api::AuthError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn resolve_auth_headers(&self) -> codex_api::AuthHeadersFuture<'_> {
|
||||
Box::pin(async {
|
||||
@@ -1158,11 +1161,12 @@ mod tests {
|
||||
struct ScopedExecutorAuth;
|
||||
|
||||
impl AuthProvider for ScopedExecutorAuth {
|
||||
fn add_auth_headers(&self, headers: &mut HeaderMap) {
|
||||
fn add_auth_headers(&self, headers: &mut HeaderMap) -> Result<(), codex_api::AuthError> {
|
||||
headers.insert(
|
||||
AUTHORIZATION,
|
||||
HeaderValue::from_static("Bearer synthetic-scoped-token"),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1171,8 +1175,12 @@ mod tests {
|
||||
struct InvalidExecutorAuth(HeaderMap);
|
||||
|
||||
impl AuthProvider for InvalidExecutorAuth {
|
||||
fn add_auth_headers(&self, headers: &mut HeaderMap) {
|
||||
fn add_auth_headers(
|
||||
&self,
|
||||
headers: &mut HeaderMap,
|
||||
) -> Result<(), codex_api::AuthError> {
|
||||
headers.extend(self.0.clone());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1433,11 +1441,15 @@ mod tests {
|
||||
const TOKEN: &str = "synthetic-scoped-registry-secret";
|
||||
struct ExecutorAuth;
|
||||
impl AuthProvider for ExecutorAuth {
|
||||
fn add_auth_headers(&self, headers: &mut HeaderMap) {
|
||||
fn add_auth_headers(
|
||||
&self,
|
||||
headers: &mut HeaderMap,
|
||||
) -> Result<(), codex_api::AuthError> {
|
||||
let mut credential =
|
||||
HeaderValue::from_str(&format!("Bearer {TOKEN}")).expect("bearer");
|
||||
credential.set_sensitive(true);
|
||||
headers.insert(AUTHORIZATION, credential);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
let encoded_echo = serde_json::json!({
|
||||
|
||||
Reference in New Issue
Block a user