mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Handle credential provider source remapping across config layers (#44241)
## What changed - Let higher-priority providers in `features.network_proxy.credentials` displace lower-priority providers with overlapping `env` sources, including in profiles. Preserve inherited settings when providers swap sources, and compare environment names case-insensitively on Windows. - Preserve provider definitions across ordered batch remaps and persist displaced-provider removals without overwriting unrelated sibling updates. - Validate remapped providers using the credential broker's compilation rules before persisting writes, while allowing incomplete drafts and explicit deletions. - Omit displaced providers from config origins and report writes overridden by another provider's source ownership. - Build trusted credential-broker configuration before merging managed layers for project discovery, preserving remapped providers' environment protections. ## Testing Add unit and config RPC regression tests for source precedence, source swaps, ordered edits, concurrent sibling updates, atomic rejection of invalid remaps, persistence, and override reporting. Add a macOS managed-config regression test for remapped provider bindings during project discovery. GitOrigin-RevId: b7d402727acf4e5b0f25946db1cf18811f5e2679
This commit is contained in:
1 parent
3436cad5ab
commit
ed4ca07ba6
14 files changed
+1690
-45
No files matched your search
@@ -24,7 +24,6 @@ use codex_config::merge_toml_values;
|
||||
use codex_config::shell_environment_filter_entry;
|
||||
use codex_config::validate_shell_environment_policy_filter_config;
|
||||
use codex_core::config::deserialize_config_toml_with_base;
|
||||
use codex_core::config::edit::ConfigEdit;
|
||||
use codex_core::config::edit::ConfigEditsBuilder;
|
||||
use codex_core::config::validate_feature_requirements_for_config_toml;
|
||||
use codex_core::path_utils;
|
||||
@@ -42,6 +41,11 @@ use tokio::task;
|
||||
use toml::Value as TomlValue;
|
||||
use toml_edit::Item as TomlItem;
|
||||
|
||||
#[path = "config_manager_service_credential_edits.rs"]
|
||||
mod credential_edits;
|
||||
|
||||
use credential_edits::CredentialProviderEdits;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub(crate) enum ConfigManagerError {
|
||||
#[error("{message}")]
|
||||
@@ -254,6 +258,7 @@ impl ConfigManager {
|
||||
}
|
||||
|
||||
let mut user_config = user_layer.config.clone();
|
||||
let mut credential_provider_edits = CredentialProviderEdits::new(&user_config);
|
||||
let mut parsed_segments = Vec::new();
|
||||
let mut config_edits = Vec::new();
|
||||
|
||||
@@ -331,15 +336,6 @@ impl ConfigManager {
|
||||
})?;
|
||||
}
|
||||
|
||||
let persist_segments = if matches!(strategy, MergeStrategy::Upsert)
|
||||
&& parsed_value.as_ref().is_some_and(|value| {
|
||||
shell_environment_policy_representation_switch(&user_config, &segments, value)
|
||||
}) {
|
||||
vec!["shell_environment_policy".to_string()]
|
||||
} else {
|
||||
segments.clone()
|
||||
};
|
||||
let original_value = value_at_path(&user_config, &persist_segments).cloned();
|
||||
let structured_feature_toggle = preserves_network_proxy_settings
|
||||
|| is_structured_feature_path(&segments)
|
||||
&& parsed_value.as_ref().is_some_and(|value| {
|
||||
@@ -350,28 +346,13 @@ impl ConfigManager {
|
||||
})
|
||||
});
|
||||
|
||||
apply_merge(&mut user_config, &segments, parsed_value.as_ref(), strategy).map_err(
|
||||
|err| match err {
|
||||
MergeError::Validation(message) => ConfigManagerError::write(
|
||||
ConfigWriteErrorCode::ConfigValidationError,
|
||||
message,
|
||||
),
|
||||
},
|
||||
)?;
|
||||
|
||||
let updated_value = value_at_path(&user_config, &persist_segments).cloned();
|
||||
if original_value != updated_value {
|
||||
config_edits.push(match updated_value {
|
||||
Some(value) => ConfigEdit::SetPath {
|
||||
segments: persist_segments,
|
||||
value: toml_value_to_item(&value).map_err(|err| {
|
||||
ConfigManagerError::anyhow("failed to build config edits", err)
|
||||
})?,
|
||||
},
|
||||
None => ConfigEdit::ClearPath {
|
||||
segments: persist_segments,
|
||||
},
|
||||
});
|
||||
if let Some(edit) = credential_provider_edits.apply(
|
||||
&mut user_config,
|
||||
&segments,
|
||||
parsed_value.as_ref(),
|
||||
strategy,
|
||||
)? {
|
||||
config_edits.push(edit);
|
||||
}
|
||||
|
||||
if structured_feature_toggle {
|
||||
@@ -379,6 +360,7 @@ impl ConfigManager {
|
||||
}
|
||||
parsed_segments.push(segments);
|
||||
}
|
||||
config_edits.extend(credential_provider_edits.remapping_edits(&user_config)?);
|
||||
|
||||
validate_config(&user_config).map_err(|err| {
|
||||
ConfigManagerError::write(
|
||||
@@ -414,12 +396,20 @@ impl ConfigManager {
|
||||
)
|
||||
})?;
|
||||
let effective = updated_layers.effective_config();
|
||||
validate_config(&effective).map_err(|err| {
|
||||
ConfigManagerError::write(
|
||||
ConfigWriteErrorCode::ConfigValidationError,
|
||||
format!("Invalid configuration: {err}"),
|
||||
)
|
||||
})?;
|
||||
validate_config(&effective)
|
||||
.and_then(|()| {
|
||||
credential_provider_edits.validate_remapping(
|
||||
&user_layer.config,
|
||||
&user_config,
|
||||
&updated_layers,
|
||||
)
|
||||
})
|
||||
.map_err(|err| {
|
||||
ConfigManagerError::write(
|
||||
ConfigWriteErrorCode::ConfigValidationError,
|
||||
format!("Invalid configuration: {err}"),
|
||||
)
|
||||
})?;
|
||||
|
||||
if !config_edits.is_empty() {
|
||||
ConfigEditsBuilder::for_config_path(provided_path.as_path())
|
||||
@@ -577,6 +567,19 @@ fn structured_feature_depth(segments: &[String]) -> Option<usize> {
|
||||
is_structured_feature_path(&segments[..depth]).then_some(depth)
|
||||
}
|
||||
|
||||
fn credential_providers_path(segments: &[String]) -> Option<&[String]> {
|
||||
match segments {
|
||||
[features, proxy, credentials, ..]
|
||||
if features == "features"
|
||||
&& proxy == "network_proxy"
|
||||
&& credentials == "credentials" =>
|
||||
{
|
||||
Some(&segments[..3])
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_merge(
|
||||
root: &mut TomlValue,
|
||||
segments: &[String],
|
||||
@@ -608,7 +611,8 @@ fn apply_merge(
|
||||
|
||||
if preserves_structured_feature_config
|
||||
|| matches!(strategy, MergeStrategy::Upsert)
|
||||
&& (shell_environment_policy_representation_switch(root, segments, value)
|
||||
&& (credential_providers_path(segments).is_some()
|
||||
|| shell_environment_policy_representation_switch(root, segments, value)
|
||||
|| (matches!(value_at_path(root, segments), Some(TomlValue::Table(_)))
|
||||
&& matches!(value, TomlValue::Table(_))))
|
||||
{
|
||||
@@ -866,6 +870,23 @@ fn find_effective_layer(
|
||||
layers: &ConfigLayerStack,
|
||||
segments: &[String],
|
||||
) -> Option<ConfigLayerMetadata> {
|
||||
if credential_providers_path(segments).is_some() {
|
||||
// A provider can be displaced by another provider's environment sources,
|
||||
// even when that layer never writes the edited path itself.
|
||||
let mut merged = TomlValue::Table(Default::default());
|
||||
let mut origin = None;
|
||||
for layer in layers.layers_low_to_high() {
|
||||
let previous = value_at_path(&merged, segments).cloned();
|
||||
merge_toml_values(&mut merged, &layer.config);
|
||||
if value_at_path(&layer.config, segments).is_some()
|
||||
|| previous.as_ref() != value_at_path(&merged, segments)
|
||||
{
|
||||
origin = Some(layer.metadata());
|
||||
}
|
||||
}
|
||||
return origin;
|
||||
}
|
||||
|
||||
for layer in layers.layers_high_to_low() {
|
||||
if value_at_semantic_path(&layer.config, segments).is_some() {
|
||||
return Some(layer.metadata());
|
||||
|
||||
Reference in new issue
Block a user