Enforce managed authentication requirements locally (#37132)

## Why

Authentication restrictions must apply before stored or environment-provided credentials can be used, including during bootstrap before cloud requirements are fetched.

## What changed

- Add local `requirements.toml` allowlists for login methods and ChatGPT workspaces. Ignore these fields in cloud-provided requirements.
- Combine managed workspace allowlists with existing workspace restrictions by intersection, and fail closed when the resulting policy permits no usable login method.
- Centralize policy checks in the authentication manager so CLI, TUI, app-server, external-auth, and credential-loading paths consistently reject disallowed authentication before token hydration or network requests.

## Testing

- Cover policy composition, workspace intersection, invalid stored and external credentials, bootstrap enforcement, and login endpoint restrictions.

GitOrigin-RevId: efef22b248f3c3333e9aa55423e539efa2d2dd48
This commit is contained in:
Abhinav authored and copyberry committed 2026-08-05 18:09:26 +00:00
1 parent 4cb8676d3a
commit 2994f545a7
36 files changed
+1121 -328

No files matched your search

+10 -19
View File
@@ -4,11 +4,9 @@ use crate::service::CloudConfigBundleService;
use codex_config::CloudConfigBundleLoadError;
use codex_config::CloudConfigBundleLoadErrorCode;
use codex_config::CloudConfigBundleLoader;
use codex_config::types::AuthCredentialsStoreMode;
use codex_http_client::HttpClientFactory;
use codex_login::AuthKeyringBackendKind;
use codex_login::AuthConfig;
use codex_login::AuthManager;
use codex_login::AuthRouteConfig;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::Mutex;
@@ -59,24 +57,17 @@ pub fn cloud_config_bundle_loader(
}
pub async fn cloud_config_bundle_loader_for_storage(
codex_home: PathBuf,
auth_config: AuthConfig,
enable_codex_api_key_env: bool,
credentials_store_mode: AuthCredentialsStoreMode,
keyring_backend_kind: AuthKeyringBackendKind,
chatgpt_base_url: String,
auth_route_config: AuthRouteConfig,
) -> CloudConfigBundleLoader {
let http_client_factory = auth_route_config.http_client_factory().clone();
let auth_manager = AuthManager::shared(
codex_home.clone(),
enable_codex_api_key_env,
credentials_store_mode,
/*forced_chatgpt_workspace_id*/ None,
Some(chatgpt_base_url.clone()),
keyring_backend_kind,
auth_route_config,
)
.await;
let codex_home = auth_config.codex_home.clone();
let chatgpt_base_url = auth_config
.chatgpt_base_url
.clone()
.unwrap_or_else(|| "https://chatgpt.com/backend-api/".to_string());
let http_client_factory = auth_config.auth_route_config.http_client_factory().clone();
let auth_manager =
AuthManager::shared_from_auth_config(auth_config, enable_codex_api_key_env).await;
cloud_config_bundle_loader(
auth_manager,
chatgpt_base_url,