mirror of
https://github.com/openai/codex.git
synced 2026-11-22 15:15:18 +00:00
Enforce managed authentication backend settings (#39043)
## What changed - Add `cli_auth_credentials_store` and `chatgpt_base_url` as exact managed requirements loaded from local requirements configuration. - Apply these requirements to runtime and bootstrap authentication configuration, overriding user-configured values. - Expose the managed values through `configRequirements/read` and reject attempts to change them through config write APIs. - Ignore these local-only authentication requirements in cloud-managed requirement layers. ## Testing - Cover requirement loading and composition, runtime and bootstrap overrides, app-server responses, and read-only config writes. GitOrigin-RevId: 8ea9c096386072036ca5441f3d48af8707988a65
This commit is contained in:
1 parent
d0fd4e830a
commit
0f21cb3413
24 files changed
+458
-22
No files matched your search
@@ -41,6 +41,7 @@ pub fn bootstrap_auth_config(
|
||||
bootstrap_config: &ConfigTomlLoadResult,
|
||||
) -> std::io::Result<AuthConfig> {
|
||||
let config = &bootstrap_config.config_toml;
|
||||
let requirements = bootstrap_config.config_layer_stack.requirements();
|
||||
// Empty legacy workspace settings mean unrestricted, not an empty allowlist.
|
||||
let forced_chatgpt_workspace_id = config
|
||||
.forced_chatgpt_workspace_id
|
||||
@@ -54,26 +55,25 @@ pub fn bootstrap_auth_config(
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.filter(|workspaces| !workspaces.is_empty());
|
||||
let auth_config = AuthConfig {
|
||||
let mut auth_config = AuthConfig {
|
||||
codex_home: codex_home.to_path_buf(),
|
||||
auth_credentials_store_mode: config.cli_auth_credentials_store.unwrap_or_default(),
|
||||
keyring_backend_kind: resolve_bootstrap_auth_keyring_backend_kind(bootstrap_config)?,
|
||||
forced_login_method: config.forced_login_method,
|
||||
chatgpt_base_url: config.chatgpt_base_url.clone(),
|
||||
forced_chatgpt_workspace_id,
|
||||
managed_auth_policy: bootstrap_config
|
||||
.config_layer_stack
|
||||
.requirements()
|
||||
.managed_auth_policy(),
|
||||
managed_auth_policy: requirements.managed_auth_policy(),
|
||||
auth_route_config: resolve_bootstrap_auth_route_config(
|
||||
config,
|
||||
bootstrap_config
|
||||
.config_layer_stack
|
||||
.requirements()
|
||||
.feature_requirements
|
||||
.as_ref(),
|
||||
requirements.feature_requirements.as_ref(),
|
||||
)?,
|
||||
};
|
||||
if let Some(required) = requirements.cli_auth_credentials_store.as_ref() {
|
||||
auth_config.auth_credentials_store_mode = required.value;
|
||||
}
|
||||
if let Some(required) = requirements.chatgpt_base_url.as_ref() {
|
||||
auth_config.chatgpt_base_url = Some(required.value.clone());
|
||||
}
|
||||
auth_config.validate()?;
|
||||
Ok(auth_config)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use codex_config::RequirementSource;
|
||||
use codex_config::Sourced;
|
||||
use codex_config::config_toml::ConfigToml;
|
||||
use codex_config::config_toml::ForcedChatgptWorkspaceIds;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_features::FeaturesToml;
|
||||
use codex_protocol::config_types::ForcedLoginMethod;
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -126,6 +127,42 @@ fn managed_auth_restrictions_intersect_workspaces_and_fail_closed() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bootstrap_auth_config_applies_managed_store_and_chatgpt_base_url() {
|
||||
let configured_store = AuthCredentialsStoreMode::File;
|
||||
let configured_url = "https://user.example/backend-api/";
|
||||
let managed_store = AuthCredentialsStoreMode::Keyring;
|
||||
let managed_url = "https://managed.example/backend-api/";
|
||||
let config_toml = ConfigToml {
|
||||
cli_auth_credentials_store: Some(configured_store),
|
||||
chatgpt_base_url: Some(configured_url.to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
let requirements = ConfigRequirements {
|
||||
cli_auth_credentials_store: Some(Sourced::new(managed_store, RequirementSource::Unknown)),
|
||||
chatgpt_base_url: Some(Sourced::new(
|
||||
managed_url.to_string(),
|
||||
RequirementSource::Unknown,
|
||||
)),
|
||||
..Default::default()
|
||||
};
|
||||
let bootstrap_config = ConfigTomlLoadResult {
|
||||
config_toml,
|
||||
config_layer_stack: ConfigLayerStack::new(
|
||||
Vec::new(),
|
||||
requirements,
|
||||
ConfigRequirementsToml::default(),
|
||||
)
|
||||
.expect("requirements should stack"),
|
||||
};
|
||||
|
||||
let auth_config = bootstrap_auth_config(Path::new("codex-home"), &bootstrap_config)
|
||||
.expect("managed authentication settings should resolve");
|
||||
|
||||
assert_eq!(auth_config.auth_credentials_store_mode, managed_store);
|
||||
assert_eq!(auth_config.chatgpt_base_url.as_deref(), Some(managed_url));
|
||||
}
|
||||
|
||||
fn config_toml_load_result(
|
||||
config_toml: ConfigToml,
|
||||
feature_requirements: Option<Sourced<FeatureRequirementsToml>>,
|
||||
|
||||
@@ -5735,6 +5735,53 @@ async fn config_resolves_explicit_keyring_auth_store_mode() -> std::io::Result<(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn config_applies_managed_auth_store_and_chatgpt_base_url() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let managed_store = AuthCredentialsStoreMode::Keyring;
|
||||
let managed_url = "https://managed.example/backend-api/";
|
||||
let requirements = codex_config::ConfigRequirements {
|
||||
cli_auth_credentials_store: Some(Sourced::new(managed_store, RequirementSource::Unknown)),
|
||||
chatgpt_base_url: Some(Sourced::new(
|
||||
managed_url.to_string(),
|
||||
RequirementSource::Unknown,
|
||||
)),
|
||||
..Default::default()
|
||||
};
|
||||
let config_layer_stack = ConfigLayerStack::new(
|
||||
Vec::new(),
|
||||
requirements,
|
||||
codex_config::ConfigRequirementsToml::default(),
|
||||
)?;
|
||||
|
||||
let config = Config::load_config_with_layer_stack(
|
||||
LOCAL_FS.as_ref(),
|
||||
ConfigToml {
|
||||
cli_auth_credentials_store: Some(AuthCredentialsStoreMode::File),
|
||||
chatgpt_base_url: Some("https://user.example/backend-api/".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
ConfigOverrides {
|
||||
cwd: Some(codex_home.path().to_path_buf()),
|
||||
..Default::default()
|
||||
},
|
||||
codex_home.abs(),
|
||||
config_layer_stack,
|
||||
)
|
||||
.await?;
|
||||
|
||||
assert_eq!(config.cli_auth_credentials_store_mode, managed_store);
|
||||
assert_eq!(config.chatgpt_base_url, managed_url);
|
||||
assert!(config.startup_warnings.iter().any(|warning| {
|
||||
warning.contains("Configured value for `cli_auth_credentials_store` is overridden")
|
||||
}));
|
||||
assert!(config.startup_warnings.iter().any(|warning| {
|
||||
warning.contains("Configured value for `chatgpt_base_url` is overridden")
|
||||
}));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn config_resolves_default_oauth_store_mode() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
@@ -9487,6 +9534,8 @@ async fn test_requirements_web_search_mode_allowlist_does_not_warn_when_unset()
|
||||
let requirements_toml = codex_config::ConfigRequirementsToml {
|
||||
allowed_login_methods: None,
|
||||
allowed_chatgpt_workspaces: None,
|
||||
cli_auth_credentials_store: None,
|
||||
chatgpt_base_url: None,
|
||||
sqlite_home: None,
|
||||
log_dir: None,
|
||||
model_catalog_json: None,
|
||||
|
||||
@@ -3116,6 +3116,8 @@ impl Config {
|
||||
let ConfigRequirements {
|
||||
allowed_login_methods: _,
|
||||
allowed_chatgpt_workspaces: _,
|
||||
cli_auth_credentials_store,
|
||||
chatgpt_base_url: _,
|
||||
sqlite_home: _,
|
||||
log_dir: _,
|
||||
model_catalog_json: _,
|
||||
@@ -4015,10 +4017,13 @@ impl Config {
|
||||
include_environment_context,
|
||||
// The config.toml omits "_mode" because it's a config file. However, "_mode"
|
||||
// is important in code to differentiate the mode from the store implementation.
|
||||
cli_auth_credentials_store_mode: resolve_cli_auth_credentials_store_mode(
|
||||
cfg.cli_auth_credentials_store.unwrap_or_default(),
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
),
|
||||
cli_auth_credentials_store_mode: match cli_auth_credentials_store {
|
||||
Some(required) => required.value,
|
||||
None => resolve_cli_auth_credentials_store_mode(
|
||||
cfg.cli_auth_credentials_store.unwrap_or_default(),
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
),
|
||||
},
|
||||
mcp_servers,
|
||||
non_prefixed_mcp_tool_servers,
|
||||
// The config.toml omits "_mode" because it's a config file. However, "_mode"
|
||||
|
||||
@@ -28,6 +28,8 @@ pub(super) fn apply_to_config(
|
||||
};
|
||||
}
|
||||
|
||||
apply_exact!(cli_auth_credentials_store);
|
||||
apply_exact!(chatgpt_base_url);
|
||||
apply_exact!(sqlite_home);
|
||||
apply_exact!(log_dir);
|
||||
apply_exact!(model_catalog_json);
|
||||
|
||||
Reference in new issue
Block a user