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,8 +2,6 @@
|
||||
//! Discovery and inference must preserve primary auth and reject requests when gateway auth fails.
|
||||
|
||||
use super::*;
|
||||
use crate::AgentIdentitySessionFallback;
|
||||
use crate::ProviderAuthScope;
|
||||
use crate::create_model_provider;
|
||||
use crate::test_support::seed_gateway_auth;
|
||||
use codex_api::Compression;
|
||||
@@ -12,10 +10,8 @@ use codex_http_client::ClientRouteClass;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
use codex_http_client::ReqwestTransport;
|
||||
use codex_login::AuthHeaders;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_login::auth::AgentIdentityAuthPolicy;
|
||||
use codex_login::default_client::ClientRedirectPolicy;
|
||||
use codex_login::default_client::create_client_for_route;
|
||||
use codex_model_provider_info::GatewayOAuthConfig;
|
||||
@@ -26,7 +22,6 @@ use codex_model_provider_info::OAuthCredentialsStore;
|
||||
use codex_models_manager::manager::RefreshStrategy;
|
||||
use codex_protocol::error::CodexErrorDetails;
|
||||
use codex_protocol::protocol::CodexErrorInfo;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use http::HeaderMap;
|
||||
use http::HeaderName;
|
||||
use http::HeaderValue;
|
||||
@@ -84,16 +79,11 @@ async fn gateway_credentials_accompany_primary_auth_in_models_and_responses() {
|
||||
};
|
||||
let info = ModelProviderInfo {
|
||||
gateway_oauth: Some(GatewayOAuthConfig::OAuth(config)),
|
||||
model_catalog_url: Some(format!("{}/models", server.uri()).into()),
|
||||
..ModelProviderInfo::create_openai_provider(Some(server.uri()))
|
||||
};
|
||||
let mut primary_headers = HeaderMap::new();
|
||||
primary_headers.insert(
|
||||
"authorization",
|
||||
HeaderValue::from_static("Bearer primary-token"),
|
||||
);
|
||||
primary_headers.insert("chatgpt-account-id", HeaderValue::from_static("account"));
|
||||
let primary = AuthManager::from_auth_for_testing_with_home(
|
||||
CodexAuth::Headers(AuthHeaders::new(primary_headers)),
|
||||
CodexAuth::from_api_key("primary-token"),
|
||||
home.path().to_path_buf(),
|
||||
);
|
||||
let manager = seed_gateway_auth(
|
||||
@@ -116,29 +106,13 @@ async fn gateway_credentials_accompany_primary_auth_in_models_and_responses() {
|
||||
models
|
||||
.raw_model_catalog(RefreshStrategy::Online, factory.clone())
|
||||
.await;
|
||||
let (api, resolved) = provider
|
||||
.request_provider_and_auth(/*scope*/ None)
|
||||
.await
|
||||
.unwrap();
|
||||
let (api, resolved) = provider.request_provider_and_auth().await.unwrap();
|
||||
let auth = resolved.auth;
|
||||
let scoped = provider
|
||||
.api_auth_for_scope(ProviderAuthScope {
|
||||
agent_identity_policy: AgentIdentityAuthPolicy::JwtOnly,
|
||||
session_source: SessionSource::Cli,
|
||||
agent_identity_session_fallback: AgentIdentitySessionFallback::default(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let mut expected = HeaderMap::from_iter([
|
||||
(
|
||||
http::header::AUTHORIZATION,
|
||||
HeaderValue::from_static("Bearer primary-token"),
|
||||
),
|
||||
(
|
||||
HeaderName::from_static("chatgpt-account-id"),
|
||||
HeaderValue::from_static("account"),
|
||||
),
|
||||
]);
|
||||
let scoped = provider.request_auth().await.unwrap();
|
||||
let mut expected = HeaderMap::from_iter([(
|
||||
http::header::AUTHORIZATION,
|
||||
HeaderValue::from_static("Bearer primary-token"),
|
||||
)]);
|
||||
let (name, value) = match delivery {
|
||||
GatewayOAuthDelivery::Header { .. } => ("x-gateway-auth", "Bearer gateway-token"),
|
||||
GatewayOAuthDelivery::Cookie { .. } => ("cookie", "gateway_session=gateway-token"),
|
||||
@@ -193,122 +167,66 @@ async fn gateway_credentials_accompany_primary_auth_in_models_and_responses() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn gateway_preserves_runtime_auth_and_rejects_header_collisions() {
|
||||
use codex_features::RuntimeAuthMode;
|
||||
use codex_runtime_agent_instance::AgentHostAuthorization;
|
||||
use codex_runtime_agent_instance::RuntimeAuthManager;
|
||||
use codex_runtime_agent_instance::RuntimeRegistrationMetadata;
|
||||
use codex_runtime_agent_instance::RuntimeRole;
|
||||
|
||||
for mode in [RuntimeAuthMode::DualHeader, RuntimeAuthMode::AssertionOnly] {
|
||||
let server = MockServer::start().await;
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/register"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"runtime_agent_instance_id": "runtime-a",
|
||||
"agent_host_id": "host-a",
|
||||
"actor": {"kind":"platform", "user_id":"user-a", "organization_id":"org-a", "project_id":null},
|
||||
})))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
let primary = AuthManager::from_auth_for_testing_with_home(
|
||||
CodexAuth::from_api_key("primary-token"),
|
||||
home.path().to_path_buf(),
|
||||
);
|
||||
let info = ModelProviderInfo {
|
||||
gateway_oauth: Some(GatewayOAuthConfig::OAuth(GatewayOAuthSettings {
|
||||
authorization_url: format!("{}/authorize", server.uri()),
|
||||
device_authorization_url: None,
|
||||
token_url: format!("{}/token", server.uri()),
|
||||
client_id: "client".into(),
|
||||
resource: None,
|
||||
scopes: vec![],
|
||||
redirect_port: None,
|
||||
credentials_store: Default::default(),
|
||||
delivery: GatewayOAuthDelivery::Header {
|
||||
name: "x-gateway-auth".into(),
|
||||
scheme: "Bearer".into(),
|
||||
},
|
||||
})),
|
||||
..ModelProviderInfo::create_openai_provider(Some(server.uri()))
|
||||
};
|
||||
let _gateway = seed_gateway_auth(
|
||||
&info,
|
||||
&primary,
|
||||
json!({"access_token": "gateway-token", "expires_at": i64::MAX}),
|
||||
);
|
||||
let runtime = Arc::new(RuntimeAuthManager::new(
|
||||
Arc::clone(&primary),
|
||||
AgentHostAuthorization::InstallationId {
|
||||
installation_id: "00000000-0000-0000-0000-000000000000".parse().unwrap(),
|
||||
async fn gateway_preserves_primary_auth_and_rejects_header_collisions() {
|
||||
let server = MockServer::start().await;
|
||||
let home = tempfile::tempdir().unwrap();
|
||||
let primary = AuthManager::from_auth_for_testing_with_home(
|
||||
CodexAuth::from_api_key("primary-token"),
|
||||
home.path().to_path_buf(),
|
||||
);
|
||||
let info = ModelProviderInfo {
|
||||
gateway_oauth: Some(GatewayOAuthConfig::OAuth(GatewayOAuthSettings {
|
||||
authorization_url: format!("{}/authorize", server.uri()),
|
||||
device_authorization_url: None,
|
||||
token_url: format!("{}/token", server.uri()),
|
||||
client_id: "client".into(),
|
||||
resource: None,
|
||||
scopes: vec![],
|
||||
redirect_port: None,
|
||||
credentials_store: Default::default(),
|
||||
delivery: GatewayOAuthDelivery::Header {
|
||||
name: "x-gateway-auth".into(),
|
||||
scheme: "Bearer".into(),
|
||||
},
|
||||
RuntimeRegistrationMetadata {
|
||||
harness: None,
|
||||
harness_version: None,
|
||||
role: RuntimeRole::Orchestrator,
|
||||
},
|
||||
format!("{}/register", server.uri()).parse().unwrap(),
|
||||
));
|
||||
let provider = crate::test_support::runtime_model_provider(info, primary, (runtime, mode));
|
||||
let auth = provider.api_auth().await.unwrap();
|
||||
let stale_headers = HeaderMap::from_iter([
|
||||
(
|
||||
http::header::AUTHORIZATION,
|
||||
HeaderValue::from_static("Bearer stale"),
|
||||
),
|
||||
(
|
||||
HeaderName::from_static("x-openai-agent-assertion"),
|
||||
HeaderValue::from_static("stale"),
|
||||
),
|
||||
(
|
||||
HeaderName::from_static("chatgpt-account-id"),
|
||||
HeaderValue::from_static("stale"),
|
||||
),
|
||||
(
|
||||
HeaderName::from_static("x-caller"),
|
||||
HeaderValue::from_static("retained"),
|
||||
),
|
||||
]);
|
||||
let headers = auth
|
||||
.apply_auth_headers(stale_headers.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(headers["x-gateway-auth"], "Bearer gateway-token");
|
||||
assert_eq!(headers["x-caller"], "retained");
|
||||
assert!(!headers.contains_key("chatgpt-account-id"));
|
||||
let proof_header = match mode {
|
||||
RuntimeAuthMode::DualHeader => {
|
||||
assert_eq!(headers["authorization"], "Bearer primary-token");
|
||||
"x-openai-agent-assertion"
|
||||
}
|
||||
RuntimeAuthMode::AssertionOnly => {
|
||||
assert!(!headers.contains_key("x-openai-agent-assertion"));
|
||||
assert!(
|
||||
headers["authorization"]
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.starts_with("AgentAssertion 1.")
|
||||
);
|
||||
"authorization"
|
||||
}
|
||||
};
|
||||
let mut request = codex_http_client::Request::new(http::Method::POST, server.uri());
|
||||
request.headers = stale_headers.clone();
|
||||
let signed = auth.apply_auth(request).await.unwrap();
|
||||
assert_eq!(signed.headers["x-gateway-auth"], "Bearer gateway-token");
|
||||
assert_ne!(headers[proof_header], signed.headers[proof_header]);
|
||||
})),
|
||||
..ModelProviderInfo::create_openai_provider(Some(server.uri()))
|
||||
};
|
||||
let _gateway = seed_gateway_auth(
|
||||
&info,
|
||||
&primary,
|
||||
json!({"access_token": "gateway-token", "expires_at": i64::MAX}),
|
||||
);
|
||||
let provider = create_model_provider(info, Some(primary));
|
||||
let auth = provider.api_auth().await.unwrap();
|
||||
let caller_headers = HeaderMap::from_iter([
|
||||
(
|
||||
http::header::AUTHORIZATION,
|
||||
HeaderValue::from_static("Bearer stale"),
|
||||
),
|
||||
(
|
||||
HeaderName::from_static("x-caller"),
|
||||
HeaderValue::from_static("retained"),
|
||||
),
|
||||
]);
|
||||
let headers = auth
|
||||
.apply_auth_headers(caller_headers.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(headers["x-gateway-auth"], "Bearer gateway-token");
|
||||
assert_eq!(headers["x-caller"], "retained");
|
||||
assert_eq!(headers["authorization"], "Bearer primary-token");
|
||||
let mut request = codex_http_client::Request::new(http::Method::POST, server.uri());
|
||||
request.headers = caller_headers.clone();
|
||||
let signed = auth.apply_auth(request).await.unwrap();
|
||||
assert_eq!(signed.headers["x-gateway-auth"], "Bearer gateway-token");
|
||||
assert_eq!(signed.headers["authorization"], "Bearer primary-token");
|
||||
|
||||
let mut collision = stale_headers;
|
||||
collision.insert("x-gateway-auth", HeaderValue::from_static("caller-token"));
|
||||
assert!(auth.apply_auth_headers(collision.clone()).await.is_err());
|
||||
let mut request = codex_http_client::Request::new(http::Method::POST, server.uri());
|
||||
request.headers = collision;
|
||||
assert!(auth.apply_auth(request).await.is_err());
|
||||
assert_eq!(server.received_requests().await.unwrap().len(), 1);
|
||||
server.verify().await;
|
||||
}
|
||||
let mut collision = caller_headers;
|
||||
collision.insert("x-gateway-auth", HeaderValue::from_static("caller-token"));
|
||||
assert!(auth.apply_auth_headers(collision.clone()).await.is_err());
|
||||
let mut request = codex_http_client::Request::new(http::Method::POST, server.uri());
|
||||
request.headers = collision;
|
||||
assert!(auth.apply_auth(request).await.is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in New Issue
Block a user