mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Normalize managed network requirements before merging (#61391)
## Why Managed network requirements support both legacy tables and `permissions.network`. Equivalent declarations in one source should be accepted, while older runtime clients still need the top-level network field. ## What changed - Normalize `network_proxy` and `experimental_network` into `permissions.network` before merging requirements, preserving source attribution and explicit empty allowlist replacements. - Accept legacy and nested declarations in one source when they describe the same policy, comparing domain and review selectors by their canonical identities. Continue rejecting mixed surfaces across sources. - Populate the legacy output field for compatibility and preserve legacy selector text when both forms are supplied. - Include contributing requirement sources in cloud bundle errors without exposing submitted TOML. ## Testing Add coverage for equivalent and conflicting declarations, empty allowlist overrides, loader compatibility, and debug output. Add a proxy regression test verifying that a saved grant cannot bypass managed loopback restrictions. GitOrigin-RevId: e0d2a600f5c7c6c07a665ccc0e18a72ff172fd6d
This commit is contained in:
@@ -23,13 +23,7 @@ pub(crate) fn validate_bundle(
|
||||
enterprise_managed_requirements,
|
||||
} = bundle_layers;
|
||||
|
||||
let requirements = compose_requirements(enterprise_managed_requirements).map_err(|_| {
|
||||
CloudConfigBundleLoadError::new(
|
||||
CloudConfigBundleLoadErrorCode::InvalidBundle,
|
||||
/*status_code*/ None,
|
||||
"invalid cloud config bundle: invalid requirements",
|
||||
)
|
||||
})?;
|
||||
let requirements = compose_requirements(enterprise_managed_requirements)?;
|
||||
if let Some(providers) = requirements.and_then(|requirements| requirements.model_providers) {
|
||||
validate_model_providers(&providers).map_err(|_| {
|
||||
CloudConfigBundleLoadError::new(
|
||||
|
||||
@@ -4,28 +4,56 @@ use pretty_assertions::assert_eq;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[test]
|
||||
fn cloud_validation_rejects_mixed_network_requirements() {
|
||||
fn cloud_validation_checks_network_spellings_per_fragment() {
|
||||
let home = tempdir().expect("tempdir");
|
||||
let base_dir = AbsolutePathBuf::from_absolute_path(home.path()).expect("absolute path");
|
||||
let mut bundle = CloudConfigBundle::default();
|
||||
for alias in ["experimental_network", "network_proxy"] {
|
||||
let nested = "[permissions.network]\nenabled = false";
|
||||
let top_level = format!("[{alias}]\nenabled = false");
|
||||
for contents in [
|
||||
vec![format!("{nested}\n{top_level}")],
|
||||
vec![nested.to_owned(), top_level],
|
||||
let conflicting = format!("[{alias}]\nenabled = true");
|
||||
for (contents, expected) in [
|
||||
(vec![format!("{nested}\n{top_level}")], Ok(())),
|
||||
(
|
||||
vec![nested.to_owned(), conflicting.clone()],
|
||||
Err(CloudConfigBundleLoadErrorCode::InvalidBundle),
|
||||
),
|
||||
(
|
||||
vec![conflicting.clone(), nested.to_owned()],
|
||||
Err(CloudConfigBundleLoadErrorCode::InvalidBundle),
|
||||
),
|
||||
(
|
||||
vec![
|
||||
"[permissions.network]\ndenied_domains = ['shared.test']".to_string(),
|
||||
format!("[{alias}]\nallowed_domains = ['shared.test']"),
|
||||
],
|
||||
Err(CloudConfigBundleLoadErrorCode::InvalidBundle),
|
||||
),
|
||||
(
|
||||
vec![format!(
|
||||
"{nested}\n{conflicting}\nreview_domains = ['private-policy.example']"
|
||||
)],
|
||||
Err(CloudConfigBundleLoadErrorCode::InvalidBundle),
|
||||
),
|
||||
] {
|
||||
bundle.requirements_toml.enterprise_managed = contents
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(index, contents)| CloudRequirementsFragment {
|
||||
id: index.to_string(),
|
||||
id: format!("fragment-{index}"),
|
||||
name: index.to_string(),
|
||||
contents,
|
||||
})
|
||||
.collect();
|
||||
let err = validate_bundle(&bundle, &base_dir).expect_err("mixed policy spellings");
|
||||
assert_eq!(err.code(), CloudConfigBundleLoadErrorCode::InvalidBundle);
|
||||
let result = validate_bundle(&bundle, &base_dir);
|
||||
if let Err(error) = &result {
|
||||
let message = error.to_string();
|
||||
for fragment in &bundle.requirements_toml.enterprise_managed {
|
||||
assert!(message.contains(&fragment.id), "{message}");
|
||||
}
|
||||
assert!(!message.contains("private-policy.example"), "{message}");
|
||||
}
|
||||
assert_eq!(result.map_err(|error| error.code()), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user