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:
viyatb-oai
2026-11-13 22:31:23 +00:00
committed by copyberry
parent 347143f140
commit f5fb19fc4a
15 changed files with 529 additions and 76 deletions
@@ -172,6 +172,13 @@ async fn managed_network_requirements_control_broker_project_discovery() -> anyh
format!("[{table}]\nenabled = {enabled}\n"),
)?;
let (canonical, local) = fixture.load().await?;
let policy_only = crate::loader::load_managed_requirements_state(
&TestFileSystem,
&fixture.home,
fixture.overrides.clone(),
)
.await?;
assert_eq!(&policy_only, canonical.requirements_toml());
let mut local_effective = TomlValue::Table(toml::map::Map::new());
for layer in local.config.layers {
merge_toml_values(&mut local_effective, &layer.toml);
@@ -203,8 +210,9 @@ async fn project_discovery_rejects_invalid_network_requirements() -> anyhow::Res
fixture.overrides.system_requirements_path = Some(path.clone());
for table in ["network_proxy", "experimental_network"] {
for (nested, message) in [
("http_port = 8090", "exactly one surface"),
("enabled = false", "exactly one surface"),
("http_port = 8090", "same network policy"),
("enabled = false", "same network policy"),
("review_domains = []", "same network policy"),
("", "rename the managed profile"),
(
"extends = ':workspace'\nenabled = true",