mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Enable OAuth discovery by default for config servers (#62824)
## Why Config servers that publish OAuth metadata still required administrators to configure OAuth endpoints explicitly for Codex to use them. ## What changed - Discover OAuth metadata when `config_server.oauth` is omitted. Use explicit settings when provided, and fetch managed configuration anonymously when discovery finds no metadata. - Have the Git credential helper resolve the config server before fetching managed configuration. It refuses explicit or discovered OAuth so it can apply workspace policy without opening the OS keyring. - Apply local network policy to discovery during `codex logout`. ## Testing Cover app-server recovery after a discovery failure, Git credential helper rejection of explicit OAuth without a network request, and logout discovery blocked by local network policy. GitOrigin-RevId: 1ad84effef48fd9b56371ee177bd53c54f3e87b8
This commit is contained in:
@@ -6,6 +6,7 @@ use chrono::Utc;
|
||||
use clap::Args;
|
||||
use clap::ValueEnum;
|
||||
use codex_app_server::in_process::EmbeddedNetworkPolicy;
|
||||
use codex_cloud_config::anonymous_config_server_bundle_loader;
|
||||
use codex_cloud_config::managed_config_bundle_loader_for_auth;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_core::config::Config;
|
||||
@@ -133,23 +134,21 @@ async fn git_token_for_origin(
|
||||
return Ok(None);
|
||||
}
|
||||
let requirements = config.config_layer_stack.requirements_toml();
|
||||
// Config-server OAuth uses the OS keyring, which Git must never open.
|
||||
ensure!(
|
||||
requirements
|
||||
.config_server
|
||||
.as_ref()
|
||||
.is_none_or(|server| server.oauth.is_none()),
|
||||
"Git cannot verify Codex workspace policy using a protected login"
|
||||
);
|
||||
let login_changes = manager.auth_change_receiver();
|
||||
let network = EmbeddedNetworkPolicy::load(&Default::default()).await;
|
||||
let bundle = managed_config_bundle_loader_for_auth(
|
||||
network.bind_bootstrap_auth(config.auth_config()),
|
||||
&auth,
|
||||
requirements,
|
||||
)
|
||||
.await
|
||||
.map_err(config_unavailable)?;
|
||||
let bootstrap = network.bind_bootstrap_auth(config.auth_config());
|
||||
let bundle = if let Some(server) = &requirements.config_server {
|
||||
anonymous_config_server_bundle_loader(
|
||||
server,
|
||||
bootstrap.codex_home,
|
||||
&bootstrap.auth_route_config,
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
managed_config_bundle_loader_for_auth(bootstrap, &auth, requirements)
|
||||
.await
|
||||
.map_err(config_unavailable)?
|
||||
};
|
||||
let effective = builder
|
||||
.cloud_config_bundle(bundle)
|
||||
.build()
|
||||
|
||||
@@ -581,9 +581,13 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
async fn logout_config_server(config: &Config) -> std::io::Result<bool> {
|
||||
async fn logout_config_server(
|
||||
config: &Config,
|
||||
loader_overrides: &codex_config::LoaderOverrides,
|
||||
) -> std::io::Result<bool> {
|
||||
let network = codex_app_server::in_process::EmbeddedNetworkPolicy::load(loader_overrides).await;
|
||||
match codex_cloud_config::managed_config_auth_manager(
|
||||
config.auth_config(),
|
||||
network.bind_bootstrap_auth(config.auth_config()),
|
||||
config.config_layer_stack.requirements_toml(),
|
||||
)
|
||||
.await?
|
||||
@@ -601,7 +605,7 @@ pub async fn run_logout(cli_config_overrides: CliConfigOverrides) -> ! {
|
||||
.requirements_toml()
|
||||
.requires_remote_config()
|
||||
{
|
||||
logout_config_server(&config).await
|
||||
logout_config_server(&config, &Default::default()).await
|
||||
} else {
|
||||
Ok(false)
|
||||
};
|
||||
@@ -743,16 +747,21 @@ mod storage_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use codex_config::LoaderOverrides;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_core::config::ConfigBuilder;
|
||||
use codex_login::AuthKeyringBackendKind;
|
||||
use codex_login::OAuthDeviceCodePrompt;
|
||||
use codex_login::load_auth_dot_json;
|
||||
use codex_login::login_with_api_key;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::io::ErrorKind;
|
||||
use std::net::TcpListener;
|
||||
use tempfile::tempdir;
|
||||
|
||||
use super::clear_existing_auth_before_login;
|
||||
use super::config_server_device_code_message;
|
||||
use super::logout_config_server;
|
||||
use super::safe_format_key;
|
||||
|
||||
#[test]
|
||||
@@ -766,6 +775,51 @@ mod tests {
|
||||
insta::assert_snapshot!(config_server_device_code_message(&prompt), @"To sign in to the config server, open https://login.example/device and enter code ABCD-EFGH.");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn logout_config_server_respects_local_network_policy() -> anyhow::Result<()> {
|
||||
let home = tempdir()?;
|
||||
let listener = TcpListener::bind("127.0.0.1:0")?;
|
||||
listener.set_nonblocking(true)?;
|
||||
let address = listener.local_addr()?;
|
||||
let requirements_path = home.path().join("requirements.toml");
|
||||
std::fs::write(
|
||||
&requirements_path,
|
||||
format!(
|
||||
r#"
|
||||
[config_server]
|
||||
base_url = "https://{address}"
|
||||
|
||||
[application.network.domains]
|
||||
"127.0.0.1" = "deny"
|
||||
"#,
|
||||
),
|
||||
)?;
|
||||
let overrides = LoaderOverrides {
|
||||
system_requirements_path: Some(requirements_path),
|
||||
ignore_project_config: true,
|
||||
..LoaderOverrides::without_managed_config_for_tests()
|
||||
};
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(home.path().to_path_buf())
|
||||
.loader_overrides(overrides.clone())
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
let error = logout_config_server(&config, &overrides)
|
||||
.await
|
||||
.expect_err("logout discovery should fail for a denied destination");
|
||||
assert_eq!(error.to_string(), "OAuth discovery failed");
|
||||
|
||||
assert_eq!(
|
||||
listener
|
||||
.accept()
|
||||
.expect_err("logout discovery connected to a denied destination")
|
||||
.kind(),
|
||||
ErrorKind::WouldBlock
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn clears_existing_auth_before_login() {
|
||||
let codex_home = tempdir().expect("create temporary Codex home");
|
||||
|
||||
Reference in New Issue
Block a user