Enforce exact values from managed config requirements (#34597)

## What changed

- Apply managed values for `sqlite_home`, `log_dir`, `model_catalog_json`,
  `check_for_update_on_startup`, `allow_login_shell`, the report-submission
  opt-in, and `windows.sandbox_private_desktop` to the runtime configuration,
  with source-aware warnings when they override configured values.
- Expose these values through `configRequirements/read`, return them from
  `config/read`, include them in session config locks, and show their sources in
  the TUI config debug view.
- Reject app-server writes that overlap an exact managed requirement with
  `configRequirementReadonly` while leaving unrelated sibling keys writable.

## Testing

- Cover runtime overrides, requirement API mapping, config reads and writes,
  session lock serialization, cross-platform path URIs, and debug output.

GitOrigin-RevId: d4e23b6fd7775c1a6dfe2eab313cdcee50b07081
This commit is contained in:
Abhinav authored and copyberry committed 2026-07-21 19:08:58 +00:00
1 parent 7442f5f932
commit ee71c4a90f
34 files changed
+1566 -71

No files matched your search

+118 -1
View File
@@ -160,6 +160,64 @@ fn render_debug_config_lines(
lines.push("Requirements:".bold().into());
let mut requirement_lines = Vec::new();
if let Some(sqlite_home) = requirements.sqlite_home.as_ref() {
requirement_lines.push(requirement_line(
"sqlite_home",
sqlite_home.value.display().to_string(),
Some(&sqlite_home.source),
));
}
if let Some(log_dir) = requirements.log_dir.as_ref() {
requirement_lines.push(requirement_line(
"log_dir",
log_dir.value.display().to_string(),
Some(&log_dir.source),
));
}
if let Some(model_catalog_json) = requirements.model_catalog_json.as_ref() {
requirement_lines.push(requirement_line(
"model_catalog_json",
model_catalog_json.value.display().to_string(),
Some(&model_catalog_json.source),
));
}
if let Some(check_for_update_on_startup) = requirements.check_for_update_on_startup.as_ref() {
requirement_lines.push(requirement_line(
"check_for_update_on_startup",
check_for_update_on_startup.value.to_string(),
Some(&check_for_update_on_startup.source),
));
}
if let Some(allow_login_shell) = requirements.allow_login_shell.as_ref() {
requirement_lines.push(requirement_line(
"allow_login_shell",
allow_login_shell.value.to_string(),
Some(&allow_login_shell.source),
));
}
if let Some(feedback) = requirements.feedback.as_ref()
&& let Some(enabled) = feedback.value.enabled
{
requirement_lines.push(requirement_line(
"feedback.enabled",
enabled.to_string(),
Some(&feedback.source),
));
}
if let Some(sandbox_private_desktop) = requirements.windows_sandbox_private_desktop.as_ref() {
requirement_lines.push(requirement_line(
"windows.sandbox_private_desktop",
sandbox_private_desktop.value.to_string(),
Some(&sandbox_private_desktop.source),
));
}
if let Some(policies) = requirements_toml.allowed_approval_policies.as_ref() {
let value = join_or_empty(policies.iter().map(ToString::to_string).collect::<Vec<_>>());
requirement_lines.push(requirement_line(
@@ -626,7 +684,9 @@ mod tests {
use codex_config::SandboxModeRequirement;
use codex_config::Sourced;
use codex_config::WebSearchModeRequirement;
use codex_config::WindowsRequirementsToml;
use codex_config::sandbox_mode_requirement_for_permission_profile;
use codex_config::types::FeedbackConfigToml;
use codex_protocol::config_types::ApprovalsReviewer;
use codex_protocol::config_types::WebSearchMode;
use codex_protocol::models::PermissionProfile;
@@ -749,8 +809,53 @@ interrupt_message = false
} else {
absolute_path("/home/alice/.gitconfig")
};
let sqlite_home = if cfg!(windows) {
absolute_path("C:\\Users\\alice\\.codex\\state")
} else {
absolute_path("/home/alice/.codex/state")
};
let log_dir = if cfg!(windows) {
absolute_path("C:\\Users\\alice\\.codex\\logs")
} else {
absolute_path("/home/alice/.codex/logs")
};
let model_catalog_json = if cfg!(windows) {
absolute_path("C:\\Users\\alice\\.codex\\models.json")
} else {
absolute_path("/home/alice/.codex/models.json")
};
let requirements = ConfigRequirements {
sqlite_home: Some(Sourced::new(
sqlite_home.clone(),
RequirementSource::LegacyManagedConfigTomlFromMdm,
)),
log_dir: Some(Sourced::new(
log_dir.clone(),
RequirementSource::LegacyManagedConfigTomlFromMdm,
)),
model_catalog_json: Some(Sourced::new(
model_catalog_json.clone(),
RequirementSource::LegacyManagedConfigTomlFromMdm,
)),
check_for_update_on_startup: Some(Sourced::new(
/*value*/ false,
RequirementSource::LegacyManagedConfigTomlFromMdm,
)),
allow_login_shell: Some(Sourced::new(
/*value*/ false,
RequirementSource::LegacyManagedConfigTomlFromMdm,
)),
feedback: Some(Sourced::new(
FeedbackConfigToml {
enabled: Some(false),
},
RequirementSource::LegacyManagedConfigTomlFromMdm,
)),
windows_sandbox_private_desktop: Some(Sourced::new(
/*value*/ false,
RequirementSource::LegacyManagedConfigTomlFromMdm,
)),
approval_policy: ConstrainedWithSource::new(
Constrained::allow_any(AskForApproval::OnRequest.to_core()),
Some(RequirementSource::LegacyManagedConfigTomlFromMdm),
@@ -828,6 +933,14 @@ interrupt_message = false
};
let requirements_toml = ConfigRequirementsToml {
sqlite_home: Some(sqlite_home),
log_dir: Some(log_dir),
model_catalog_json: Some(model_catalog_json),
check_for_update_on_startup: Some(false),
allow_login_shell: Some(false),
feedback: Some(FeedbackConfigToml {
enabled: Some(false),
}),
allowed_approval_policies: Some(vec![AskForApproval::OnRequest.to_core()]),
allowed_approvals_reviewers: Some(vec![ApprovalsReviewer::AutoReview]),
allowed_sandbox_modes: Some(vec![SandboxModeRequirement::ReadOnly]),
@@ -839,7 +952,10 @@ interrupt_message = false
allow_appshots: Some(false),
allow_remote_control: Some(false),
computer_use: None,
windows: None,
windows: Some(WindowsRequirementsToml {
allowed_sandbox_implementations: None,
sandbox_private_desktop: Some(false),
}),
guardian_policy_config: Some("Use the managed guardian policy.".to_string()),
feature_requirements: Some(FeatureRequirementsToml {
entries: BTreeMap::from([("guardian_approval".to_string(), true)]),
@@ -1220,6 +1336,7 @@ approval_policy = "never"
network: None,
permissions: None,
models: None,
..ConfigRequirementsToml::default()
};
let stack = ConfigLayerStack::new(Vec::new(), requirements, requirements_toml)