mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Protect managed config through the app-server API
This commit is contained in:
+14
-20
@@ -8372,7 +8372,7 @@
|
||||
]
|
||||
},
|
||||
"otel": {
|
||||
"description": "Lossless config-native OTEL requirements, including exporter headers."
|
||||
"description": "Config-native OTEL requirements. Exporter header names are preserved, while their values are redacted."
|
||||
},
|
||||
"shellEnvironmentPolicy": {
|
||||
"anyOf": [
|
||||
@@ -15994,6 +15994,14 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ShellEnvironmentPolicyFilter": {
|
||||
"description": "Assigns a shell environment variable pattern to the include-only or exclude set. Includes do not re-add variables removed by another exclude pattern.",
|
||||
"enum": [
|
||||
"include",
|
||||
"exclude"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ShellEnvironmentPolicyInherit": {
|
||||
"oneOf": [
|
||||
{
|
||||
@@ -16021,9 +16029,12 @@
|
||||
},
|
||||
"ShellEnvironmentPolicyRequirements": {
|
||||
"properties": {
|
||||
"experimental_use_profile": {
|
||||
"filters": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/v2/ShellEnvironmentPolicyFilter"
|
||||
},
|
||||
"type": [
|
||||
"boolean",
|
||||
"object",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
@@ -16043,15 +16054,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"rules": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/v2/ShellEnvironmentPolicyRule"
|
||||
},
|
||||
"type": [
|
||||
"object",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"set": {
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
@@ -16064,14 +16066,6 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"ShellEnvironmentPolicyRule": {
|
||||
"description": "Assigns a shell environment variable pattern to the include-only or exclude set. Includes do not re-add variables removed by another exclude pattern.",
|
||||
"enum": [
|
||||
"include",
|
||||
"exclude"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"SkillDependencies": {
|
||||
"properties": {
|
||||
"tools": {
|
||||
|
||||
+14
-20
@@ -4685,7 +4685,7 @@
|
||||
]
|
||||
},
|
||||
"otel": {
|
||||
"description": "Lossless config-native OTEL requirements, including exporter headers."
|
||||
"description": "Config-native OTEL requirements. Exporter header names are preserved, while their values are redacted."
|
||||
},
|
||||
"shellEnvironmentPolicy": {
|
||||
"anyOf": [
|
||||
@@ -13802,6 +13802,14 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ShellEnvironmentPolicyFilter": {
|
||||
"description": "Assigns a shell environment variable pattern to the include-only or exclude set. Includes do not re-add variables removed by another exclude pattern.",
|
||||
"enum": [
|
||||
"include",
|
||||
"exclude"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ShellEnvironmentPolicyInherit": {
|
||||
"oneOf": [
|
||||
{
|
||||
@@ -13829,9 +13837,12 @@
|
||||
},
|
||||
"ShellEnvironmentPolicyRequirements": {
|
||||
"properties": {
|
||||
"experimental_use_profile": {
|
||||
"filters": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/ShellEnvironmentPolicyFilter"
|
||||
},
|
||||
"type": [
|
||||
"boolean",
|
||||
"object",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
@@ -13851,15 +13862,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"rules": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/ShellEnvironmentPolicyRule"
|
||||
},
|
||||
"type": [
|
||||
"object",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"set": {
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
@@ -13872,14 +13874,6 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"ShellEnvironmentPolicyRule": {
|
||||
"description": "Assigns a shell environment variable pattern to the include-only or exclude set. Includes do not re-add variables removed by another exclude pattern.",
|
||||
"enum": [
|
||||
"include",
|
||||
"exclude"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"SkillDependencies": {
|
||||
"properties": {
|
||||
"tools": {
|
||||
|
||||
+14
-20
@@ -285,7 +285,7 @@
|
||||
]
|
||||
},
|
||||
"otel": {
|
||||
"description": "Lossless config-native OTEL requirements, including exporter headers."
|
||||
"description": "Config-native OTEL requirements. Exporter header names are preserved, while their values are redacted."
|
||||
},
|
||||
"shellEnvironmentPolicy": {
|
||||
"anyOf": [
|
||||
@@ -653,6 +653,14 @@
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ShellEnvironmentPolicyFilter": {
|
||||
"description": "Assigns a shell environment variable pattern to the include-only or exclude set. Includes do not re-add variables removed by another exclude pattern.",
|
||||
"enum": [
|
||||
"include",
|
||||
"exclude"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ShellEnvironmentPolicyInherit": {
|
||||
"oneOf": [
|
||||
{
|
||||
@@ -680,9 +688,12 @@
|
||||
},
|
||||
"ShellEnvironmentPolicyRequirements": {
|
||||
"properties": {
|
||||
"experimental_use_profile": {
|
||||
"filters": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/ShellEnvironmentPolicyFilter"
|
||||
},
|
||||
"type": [
|
||||
"boolean",
|
||||
"object",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
@@ -702,15 +713,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"rules": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/ShellEnvironmentPolicyRule"
|
||||
},
|
||||
"type": [
|
||||
"object",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"set": {
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
@@ -723,14 +725,6 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"ShellEnvironmentPolicyRule": {
|
||||
"description": "Assigns a shell environment variable pattern to the include-only or exclude set. Includes do not re-add variables removed by another exclude pattern.",
|
||||
"enum": [
|
||||
"include",
|
||||
"exclude"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"WebSearchMode": {
|
||||
"enum": [
|
||||
"disabled",
|
||||
|
||||
@@ -14,7 +14,8 @@ import type { ShellEnvironmentPolicyRequirements } from "./ShellEnvironmentPolic
|
||||
import type { WindowsSandboxSetupMode } from "./WindowsSandboxSetupMode";
|
||||
|
||||
export type ConfigRequirements = {allowedApprovalPolicies: Array<AskForApproval> | null, allowedSandboxModes: Array<SandboxMode> | null, allowedWindowsSandboxImplementations: Array<WindowsSandboxSetupMode> | null, allowedPermissionProfiles: { [key in string]?: boolean } | null, defaultPermissions: string | null, allowedWebSearchModes: Array<WebSearchMode> | null, allowManagedHooksOnly: boolean | null, allowAppshots: boolean | null, allowRemoteControl: boolean | null, computerUse: ComputerUseRequirements | null, featureRequirements: { [key in string]?: boolean } | null, enforceResidency: ResidencyRequirement | null, allowedLoginMethods: { [key in string]?: boolean } | null, allowedChatgptWorkspaces: { [key in string]?: boolean } | null, cliAuthCredentialsStore: AuthCredentialsStoreMode | null, chatgptBaseUrl: string | null, sqliteHome: AbsolutePathBuf | null, logDir: AbsolutePathBuf | null, modelCatalogJson: AbsolutePathBuf | null, checkForUpdateOnStartup: boolean | null, /**
|
||||
* Lossless config-native OTEL requirements, including exporter headers.
|
||||
* Config-native OTEL requirements. Exporter header names are preserved,
|
||||
* while their values are redacted.
|
||||
*/
|
||||
otel: JsonValue | null, allowLoginShell: boolean | null, /**
|
||||
* Lossless config-native shell environment policy requirements.
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@
|
||||
* Assigns a shell environment variable pattern to the include-only or exclude
|
||||
* set. Includes do not re-add variables removed by another exclude pattern.
|
||||
*/
|
||||
export type ShellEnvironmentPolicyRule = "include" | "exclude";
|
||||
export type ShellEnvironmentPolicyFilter = "include" | "exclude";
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ShellEnvironmentPolicyFilter } from "./ShellEnvironmentPolicyFilter";
|
||||
import type { ShellEnvironmentPolicyInherit } from "./ShellEnvironmentPolicyInherit";
|
||||
import type { ShellEnvironmentPolicyRule } from "./ShellEnvironmentPolicyRule";
|
||||
|
||||
export type ShellEnvironmentPolicyRequirements = { inherit: ShellEnvironmentPolicyInherit | null, ignore_default_excludes: boolean | null, set: { [key in string]?: string } | null, rules: { [key in string]?: ShellEnvironmentPolicyRule } | null, experimental_use_profile: boolean | null, };
|
||||
export type ShellEnvironmentPolicyRequirements = { inherit: ShellEnvironmentPolicyInherit | null, ignore_default_excludes: boolean | null, set: { [key in string]?: string } | null, filters: { [key in string]?: ShellEnvironmentPolicyFilter } | null, };
|
||||
|
||||
+1
-1
@@ -355,9 +355,9 @@ export type { SendAddCreditsNudgeEmailResponse } from "./SendAddCreditsNudgeEmai
|
||||
export type { ServerRequestResolvedNotification } from "./ServerRequestResolvedNotification";
|
||||
export type { SessionMigration } from "./SessionMigration";
|
||||
export type { SessionSource } from "./SessionSource";
|
||||
export type { ShellEnvironmentPolicyFilter } from "./ShellEnvironmentPolicyFilter";
|
||||
export type { ShellEnvironmentPolicyInherit } from "./ShellEnvironmentPolicyInherit";
|
||||
export type { ShellEnvironmentPolicyRequirements } from "./ShellEnvironmentPolicyRequirements";
|
||||
export type { ShellEnvironmentPolicyRule } from "./ShellEnvironmentPolicyRule";
|
||||
export type { SkillDependencies } from "./SkillDependencies";
|
||||
export type { SkillErrorInfo } from "./SkillErrorInfo";
|
||||
export type { SkillInterface } from "./SkillInterface";
|
||||
|
||||
@@ -8,8 +8,8 @@ pub use codex_protocol::config_types::AuthCredentialsStoreMode;
|
||||
use codex_protocol::config_types::AutoCompactTokenLimitScope;
|
||||
use codex_protocol::config_types::ForcedLoginMethod;
|
||||
use codex_protocol::config_types::ReasoningSummary;
|
||||
use codex_protocol::config_types::ShellEnvironmentPolicyFilter;
|
||||
use codex_protocol::config_types::ShellEnvironmentPolicyInherit;
|
||||
use codex_protocol::config_types::ShellEnvironmentPolicyRule;
|
||||
use codex_protocol::config_types::Verbosity;
|
||||
use codex_protocol::config_types::WebSearchMode;
|
||||
use codex_protocol::config_types::WebSearchToolConfig;
|
||||
@@ -339,6 +339,7 @@ pub struct ConfigWriteResponse {
|
||||
#[ts(export_to = "v2/")]
|
||||
pub enum ConfigWriteErrorCode {
|
||||
ConfigLayerReadonly,
|
||||
ConfigRequirementReadonly,
|
||||
ConfigVersionConflict,
|
||||
ConfigValidationError,
|
||||
ConfigPathNotFound,
|
||||
@@ -403,7 +404,8 @@ pub struct ConfigRequirements {
|
||||
pub log_dir: Option<AbsolutePathBuf>,
|
||||
pub model_catalog_json: Option<AbsolutePathBuf>,
|
||||
pub check_for_update_on_startup: Option<bool>,
|
||||
/// Lossless config-native OTEL requirements, including exporter headers.
|
||||
/// Config-native OTEL requirements. Exporter header names are preserved,
|
||||
/// while their values are redacted.
|
||||
pub otel: Option<JsonValue>,
|
||||
pub allow_login_shell: Option<bool>,
|
||||
/// Lossless config-native shell environment policy requirements.
|
||||
@@ -426,8 +428,7 @@ pub struct ShellEnvironmentPolicyRequirements {
|
||||
pub inherit: Option<ShellEnvironmentPolicyInherit>,
|
||||
pub ignore_default_excludes: Option<bool>,
|
||||
pub r#set: Option<HashMap<String, String>>,
|
||||
pub rules: Option<BTreeMap<String, ShellEnvironmentPolicyRule>>,
|
||||
pub experimental_use_profile: Option<bool>,
|
||||
pub filters: Option<BTreeMap<String, ShellEnvironmentPolicyFilter>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
|
||||
@@ -235,7 +235,7 @@ Example with notification opt-out:
|
||||
- `externalAgentConfig/import` — apply selected external-agent migration items by passing explicit `migrationItems` with `cwd` (`null` for home) and any plugin/session `details` returned by detect. Returns an `importId` used to correlate the completion notification. When a request includes migration items, the server emits `externalAgentConfig/import/completed` once after the full import finishes with type-level `itemResults` containing each migrated type's success count, error count, successes, and raw errors (immediately after the response when everything completed synchronously, or after background imports finish).
|
||||
- `config/value/write` — write a single config key/value to the user's config.toml on disk; dotted paths such as `desktop.someKey` use the same generic write surface.
|
||||
- `config/batchWrite` — apply multiple config edits atomically to the user's config.toml on disk, with optional `reloadUserConfig: true` to hot-reload loaded threads, including multiple `desktop.*` edits.
|
||||
- `configRequirements/read` — fetch loaded requirements constraints from `requirements.toml` and/or MDM (or `null` if none are configured), including allow-lists (`allowedApprovalPolicies`, `allowedSandboxModes`, `allowedWebSearchModes`, `allowedLoginMethods`, `allowedChatgptWorkspaces`), the layered permission-profile allow map (`allowedPermissionProfiles`), the managed permission-profile default (`defaultPermissions`), lifecycle hook lockdown (`allowManagedHooksOnly`), remote-control policy (`allowRemoteControl`; `false` force-disables remote control while `true` or `null` preserves existing behavior), computer use policy (`computerUse`), pinned feature values (`featureRequirements`), managed lifecycle hooks (`hooks`), `enforceResidency`, `network` constraints such as canonical domain/socket permissions plus `managedAllowedDomainsOnly` and `dangerFullAccessDenylistOnly`, and pinned runtime settings such as credential storage, ChatGPT base URL, state/log/model-catalog paths, update checks, login-shell and environment policy, feedback, Windows private-desktop use, and OTEL configuration. Shell environment requirements expose pattern-to-action `rules` whose values are `include` or `exclude`; OTEL exporter responses include their complete headers map.
|
||||
- `configRequirements/read` — fetch loaded requirements constraints from `requirements.toml` and/or MDM (or `null` if none are configured), including allow-lists (`allowedApprovalPolicies`, `allowedSandboxModes`, `allowedWebSearchModes`, `allowedLoginMethods`, `allowedChatgptWorkspaces`), the layered permission-profile allow map (`allowedPermissionProfiles`), the managed permission-profile default (`defaultPermissions`), lifecycle hook lockdown (`allowManagedHooksOnly`), remote-control policy (`allowRemoteControl`; `false` force-disables remote control while `true` or `null` preserves existing behavior), computer use policy (`computerUse`), pinned feature values (`featureRequirements`), managed lifecycle hooks (`hooks`), `enforceResidency`, `network` constraints such as canonical domain/socket permissions plus `managedAllowedDomainsOnly` and `dangerFullAccessDenylistOnly`, and pinned runtime settings such as credential storage, ChatGPT base URL, state/log/model-catalog paths, update checks, login-shell and environment policy, feedback, Windows private-desktop use, and OTEL configuration. Shell environment requirements expose pattern-to-action `filters` whose values are `include` or `exclude`; OTEL exporter responses preserve header names but redact their values.
|
||||
|
||||
### Example: Start or resume a thread
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use codex_config::ConfigLayerStack;
|
||||
use codex_config::ConfigLayerStackOrdering;
|
||||
use codex_config::ConfigRequirementsToml;
|
||||
use codex_config::config_toml::ConfigToml;
|
||||
use codex_config::merge_toml_values;
|
||||
use codex_config::merge_toml_values_at_path;
|
||||
use codex_core::config::deserialize_config_toml_with_base;
|
||||
use codex_core::config::edit::ConfigEdit;
|
||||
use codex_core::config::edit::ConfigEditsBuilder;
|
||||
@@ -237,6 +237,16 @@ impl ConfigManager {
|
||||
let segments = parse_key_path(&key_path).map_err(|message| {
|
||||
ConfigManagerError::write(ConfigWriteErrorCode::ConfigValidationError, message)
|
||||
})?;
|
||||
if let Some(requirement) =
|
||||
managed_requirement_for_path(layers.requirements_toml(), &segments)
|
||||
{
|
||||
return Err(ConfigManagerError::write(
|
||||
ConfigWriteErrorCode::ConfigRequirementReadonly,
|
||||
format!(
|
||||
"Configuration path `{key_path}` is read-only because it is managed by `{requirement}`"
|
||||
),
|
||||
));
|
||||
}
|
||||
if !value.is_null() {
|
||||
match segments.as_slice() {
|
||||
[segment] if segment == "profile" => {
|
||||
@@ -360,6 +370,132 @@ impl ConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn managed_requirement_for_path(
|
||||
requirements: &ConfigRequirementsToml,
|
||||
segments: &[String],
|
||||
) -> Option<&'static str> {
|
||||
let root = segments.first()?.as_str();
|
||||
let ConfigRequirementsToml {
|
||||
allowed_login_methods,
|
||||
allowed_chatgpt_workspaces,
|
||||
cli_auth_credentials_store,
|
||||
chatgpt_base_url,
|
||||
sqlite_home,
|
||||
log_dir,
|
||||
model_catalog_json,
|
||||
check_for_update_on_startup,
|
||||
otel,
|
||||
allow_login_shell,
|
||||
shell_environment_policy,
|
||||
feedback,
|
||||
allowed_approval_policies,
|
||||
allowed_approvals_reviewers,
|
||||
allowed_sandbox_modes,
|
||||
allowed_permission_profiles,
|
||||
default_permissions,
|
||||
remote_sandbox_config,
|
||||
allowed_web_search_modes,
|
||||
allow_managed_hooks_only,
|
||||
allow_appshots: _,
|
||||
allow_remote_control,
|
||||
computer_use,
|
||||
windows,
|
||||
feature_requirements,
|
||||
hooks,
|
||||
mcp_servers,
|
||||
plugins,
|
||||
apps,
|
||||
rules,
|
||||
enforce_residency,
|
||||
network,
|
||||
permissions,
|
||||
guardian_policy_config,
|
||||
} = requirements;
|
||||
|
||||
macro_rules! managed_root {
|
||||
($requirement:ident, $($root:literal),+ $(,)?) => {
|
||||
if $requirement.is_some() && matches!(root, $($root)|+) {
|
||||
return Some(stringify!($requirement));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
managed_root!(allowed_login_methods, "forced_login_method");
|
||||
managed_root!(allowed_chatgpt_workspaces, "forced_chatgpt_workspace_id");
|
||||
managed_root!(cli_auth_credentials_store, "cli_auth_credentials_store");
|
||||
managed_root!(chatgpt_base_url, "chatgpt_base_url");
|
||||
managed_root!(sqlite_home, "sqlite_home");
|
||||
managed_root!(log_dir, "log_dir");
|
||||
managed_root!(model_catalog_json, "model_catalog_json");
|
||||
managed_root!(check_for_update_on_startup, "check_for_update_on_startup");
|
||||
managed_root!(otel, "otel");
|
||||
managed_root!(allow_login_shell, "allow_login_shell");
|
||||
managed_root!(shell_environment_policy, "shell_environment_policy");
|
||||
managed_root!(feedback, "feedback");
|
||||
managed_root!(allowed_approval_policies, "approval_policy");
|
||||
managed_root!(allowed_approvals_reviewers, "approvals_reviewer");
|
||||
managed_root!(
|
||||
allowed_sandbox_modes,
|
||||
"sandbox_mode",
|
||||
"sandbox_workspace_write",
|
||||
"permissions"
|
||||
);
|
||||
managed_root!(allowed_permission_profiles, "sandbox_mode", "permissions");
|
||||
managed_root!(default_permissions, "sandbox_mode", "permissions");
|
||||
managed_root!(remote_sandbox_config, "remote_sandbox_config");
|
||||
managed_root!(allowed_web_search_modes, "web_search");
|
||||
managed_root!(allow_managed_hooks_only, "hooks");
|
||||
if allow_remote_control.is_some() && is_feature_path(segments, "remote_control") {
|
||||
return Some("allow_remote_control");
|
||||
}
|
||||
if computer_use.is_some() && is_feature_path(segments, "computer_use") {
|
||||
return Some("computer_use");
|
||||
}
|
||||
managed_root!(windows, "windows");
|
||||
if let Some(requirements) = feature_requirements {
|
||||
if matches!(segments, [root] if root == "features") {
|
||||
return Some("feature_requirements");
|
||||
}
|
||||
let key = match segments {
|
||||
[root, key, ..] if root == "features" => key.as_str(),
|
||||
[key, ..] => key.as_str(),
|
||||
[] => return None,
|
||||
};
|
||||
if let Some(feature) = codex_features::feature_for_key(key)
|
||||
&& requirements.entries.keys().any(|required| {
|
||||
codex_features::feature_for_key(required).is_some_and(|value| value == feature)
|
||||
})
|
||||
{
|
||||
return Some("feature_requirements");
|
||||
}
|
||||
}
|
||||
managed_root!(hooks, "hooks");
|
||||
managed_root!(mcp_servers, "mcp_servers");
|
||||
managed_root!(plugins, "plugins");
|
||||
managed_root!(apps, "apps");
|
||||
managed_root!(rules, "rules");
|
||||
managed_root!(enforce_residency, "enforce_residency");
|
||||
managed_root!(network, "experimental_network", "network", "permissions");
|
||||
managed_root!(permissions, "permissions", "sandbox_mode");
|
||||
managed_root!(guardian_policy_config, "guardian_policy_config");
|
||||
None
|
||||
}
|
||||
|
||||
fn is_feature_path(segments: &[String], required_key: &str) -> bool {
|
||||
match segments {
|
||||
[root] if root == "features" => true,
|
||||
[root, key, ..] if root == "features" => {
|
||||
codex_features::feature_for_key(key)
|
||||
== codex_features::canonical_feature_for_key(required_key)
|
||||
}
|
||||
[key, ..] => {
|
||||
codex_features::feature_for_key(key)
|
||||
== codex_features::canonical_feature_for_key(required_key)
|
||||
}
|
||||
[] => false,
|
||||
}
|
||||
}
|
||||
|
||||
async fn create_empty_user_layer(
|
||||
config_toml: &AbsolutePathBuf,
|
||||
) -> Result<ConfigLayerEntry, ConfigManagerError> {
|
||||
@@ -512,7 +648,7 @@ fn apply_merge(
|
||||
&& matches!(existing, TomlValue::Table(_))
|
||||
&& matches!(value, TomlValue::Table(_))
|
||||
{
|
||||
merge_toml_values(existing, value);
|
||||
merge_toml_values_at_path(existing, value, segments);
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -458,7 +458,7 @@ writable_roots = ["~/code"]
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn write_value_reports_override() {
|
||||
async fn write_value_rejects_managed_path_even_when_value_matches() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
std::fs::write(
|
||||
tmp.path().join(CONFIG_TOML_FILE),
|
||||
@@ -477,7 +477,7 @@ async fn write_value_reports_override() {
|
||||
CloudConfigBundleLoader::default(),
|
||||
);
|
||||
|
||||
let result = service
|
||||
let error = service
|
||||
.write_value(ConfigValueWriteParams {
|
||||
file_path: Some(tmp.path().join(CONFIG_TOML_FILE).display().to_string()),
|
||||
key_path: "approval_policy".to_string(),
|
||||
@@ -486,7 +486,12 @@ async fn write_value_reports_override() {
|
||||
expected_version: None,
|
||||
})
|
||||
.await
|
||||
.expect("result");
|
||||
.expect_err("managed path should be read-only");
|
||||
|
||||
assert_eq!(
|
||||
error.write_error_code(),
|
||||
Some(ConfigWriteErrorCode::ConfigRequirementReadonly)
|
||||
);
|
||||
|
||||
let read_after = service
|
||||
.read(ConfigReadParams {
|
||||
@@ -509,8 +514,10 @@ async fn write_value_reports_override() {
|
||||
file: managed_file.clone()
|
||||
}
|
||||
);
|
||||
assert_eq!(result.status, WriteStatus::Ok);
|
||||
assert!(result.overridden_metadata.is_none());
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(tmp.path().join(CONFIG_TOML_FILE)).unwrap(),
|
||||
"approval_policy = \"on-request\""
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -636,7 +643,7 @@ async fn load_default_config_preserves_selected_user_config_path_after_load_erro
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn invalid_user_value_rejected_even_if_overridden_by_managed() {
|
||||
async fn managed_write_is_rejected_before_value_validation() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
std::fs::write(tmp.path().join(CONFIG_TOML_FILE), "model = \"user\"").unwrap();
|
||||
|
||||
@@ -663,7 +670,7 @@ async fn invalid_user_value_rejected_even_if_overridden_by_managed() {
|
||||
|
||||
assert_eq!(
|
||||
error.write_error_code(),
|
||||
Some(ConfigWriteErrorCode::ConfigValidationError)
|
||||
Some(ConfigWriteErrorCode::ConfigRequirementReadonly)
|
||||
);
|
||||
|
||||
let contents = std::fs::read_to_string(tmp.path().join(CONFIG_TOML_FILE)).expect("read config");
|
||||
@@ -728,12 +735,10 @@ personality = true
|
||||
|
||||
assert_eq!(
|
||||
error.write_error_code(),
|
||||
Some(ConfigWriteErrorCode::ConfigValidationError)
|
||||
Some(ConfigWriteErrorCode::ConfigRequirementReadonly)
|
||||
);
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("invalid value for `features`: `features.personality=false`"),
|
||||
error.to_string().contains("feature_requirements"),
|
||||
"{error}"
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -742,6 +747,75 @@ personality = true
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn write_value_allows_unmanaged_feature_next_to_requirement() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
std::fs::write(tmp.path().join(CONFIG_TOML_FILE), "").unwrap();
|
||||
let service = ConfigManager::new_for_tests(
|
||||
tmp.path().to_path_buf(),
|
||||
vec![],
|
||||
LoaderOverrides::without_managed_config_for_tests(),
|
||||
CloudConfigBundleFixture::loader_with_enterprise_requirement(
|
||||
r#"
|
||||
[features]
|
||||
personality = true
|
||||
"#,
|
||||
),
|
||||
);
|
||||
|
||||
service
|
||||
.write_value(ConfigValueWriteParams {
|
||||
file_path: None,
|
||||
key_path: "features.mentions_v2".to_string(),
|
||||
value: serde_json::json!(true),
|
||||
merge_strategy: MergeStrategy::Replace,
|
||||
expected_version: None,
|
||||
})
|
||||
.await
|
||||
.expect("unmanaged feature should remain writable");
|
||||
|
||||
assert!(
|
||||
std::fs::read_to_string(tmp.path().join(CONFIG_TOML_FILE))
|
||||
.unwrap()
|
||||
.contains("mentions_v2 = true")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn write_value_rejects_managed_exact_requirement_path() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
std::fs::write(tmp.path().join(CONFIG_TOML_FILE), "").unwrap();
|
||||
let service = ConfigManager::new_for_tests(
|
||||
tmp.path().to_path_buf(),
|
||||
vec![],
|
||||
LoaderOverrides::without_managed_config_for_tests(),
|
||||
CloudConfigBundleFixture::loader_with_enterprise_requirement(
|
||||
r#"chatgpt_base_url = "https://managed.example""#,
|
||||
),
|
||||
);
|
||||
|
||||
let error = service
|
||||
.write_value(ConfigValueWriteParams {
|
||||
file_path: None,
|
||||
key_path: "chatgpt_base_url".to_string(),
|
||||
value: serde_json::json!("https://user.example"),
|
||||
merge_strategy: MergeStrategy::Replace,
|
||||
expected_version: None,
|
||||
})
|
||||
.await
|
||||
.expect_err("managed config path should be read-only");
|
||||
|
||||
assert_eq!(
|
||||
error.write_error_code(),
|
||||
Some(ConfigWriteErrorCode::ConfigRequirementReadonly)
|
||||
);
|
||||
assert!(error.to_string().contains("chatgpt_base_url"));
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(tmp.path().join(CONFIG_TOML_FILE)).unwrap(),
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_reports_managed_overrides_user_and_session_flags() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
@@ -805,42 +879,6 @@ async fn read_reports_managed_overrides_user_and_session_flags() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn write_value_reports_managed_override() {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
std::fs::write(tmp.path().join(CONFIG_TOML_FILE), "").unwrap();
|
||||
|
||||
let managed_path = tmp.path().join("managed_config.toml");
|
||||
std::fs::write(&managed_path, "approval_policy = \"never\"").unwrap();
|
||||
let managed_file = AbsolutePathBuf::try_from(managed_path.clone()).expect("managed file");
|
||||
|
||||
let service = ConfigManager::new_for_tests(
|
||||
tmp.path().to_path_buf(),
|
||||
vec![],
|
||||
LoaderOverrides::with_managed_config_path_for_tests(managed_path.clone()),
|
||||
CloudConfigBundleLoader::default(),
|
||||
);
|
||||
|
||||
let result = service
|
||||
.write_value(ConfigValueWriteParams {
|
||||
file_path: Some(tmp.path().join(CONFIG_TOML_FILE).display().to_string()),
|
||||
key_path: "approval_policy".to_string(),
|
||||
value: serde_json::json!("on-request"),
|
||||
merge_strategy: MergeStrategy::Replace,
|
||||
expected_version: None,
|
||||
})
|
||||
.await
|
||||
.expect("result");
|
||||
|
||||
assert_eq!(result.status, WriteStatus::OkOverridden);
|
||||
let overridden = result.overridden_metadata.expect("overridden metadata");
|
||||
assert_eq!(
|
||||
overridden.overriding_layer.name,
|
||||
ConfigLayerSource::LegacyManagedConfigTomlFromFile { file: managed_file }
|
||||
);
|
||||
assert_eq!(overridden.effective_value, serde_json::json!("never"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn upsert_merges_tables_replace_overwrites() -> Result<()> {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
@@ -927,3 +965,44 @@ beta = "b"
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn upsert_shell_environment_policy_uses_its_full_key_path() -> Result<()> {
|
||||
let tmp = tempdir()?;
|
||||
let path = tmp.path().join(CONFIG_TOML_FILE);
|
||||
std::fs::write(
|
||||
&path,
|
||||
r#"
|
||||
[shell_environment_policy]
|
||||
exclude = ["FLIP_*", "KEEP_*"]
|
||||
"#,
|
||||
)?;
|
||||
let service = ConfigManager::without_managed_config_for_tests(tmp.path().to_path_buf());
|
||||
|
||||
service
|
||||
.write_value(ConfigValueWriteParams {
|
||||
file_path: Some(path.display().to_string()),
|
||||
key_path: "shell_environment_policy".to_string(),
|
||||
value: serde_json::json!({
|
||||
"filters": {
|
||||
"FLIP_*": "include",
|
||||
},
|
||||
}),
|
||||
merge_strategy: MergeStrategy::Upsert,
|
||||
expected_version: None,
|
||||
})
|
||||
.await?;
|
||||
|
||||
let config: TomlValue = toml::from_str(&std::fs::read_to_string(path)?)?;
|
||||
assert_eq!(
|
||||
config,
|
||||
toml::from_str(
|
||||
r#"
|
||||
[shell_environment_policy.filters]
|
||||
"flip_*" = "include"
|
||||
"keep_*" = "exclude"
|
||||
"#,
|
||||
)?
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ use codex_config::MatcherGroup as CoreMatcherGroup;
|
||||
use codex_config::ResidencyRequirement as CoreResidencyRequirement;
|
||||
use codex_config::SandboxModeRequirement as CoreSandboxModeRequirement;
|
||||
use codex_config::ShellEnvironmentPolicyRequirementsToml;
|
||||
use codex_config::types::OtelConfigToml;
|
||||
use codex_config::types::OtelExporterKind;
|
||||
use codex_core::ThreadManager;
|
||||
use codex_features::canonical_feature_for_key;
|
||||
use codex_features::feature_for_key;
|
||||
@@ -403,7 +405,7 @@ fn map_requirements_toml_to_api(requirements: ConfigRequirementsToml) -> ConfigR
|
||||
log_dir: requirements.log_dir,
|
||||
model_catalog_json: requirements.model_catalog_json,
|
||||
check_for_update_on_startup: requirements.check_for_update_on_startup,
|
||||
otel: requirements.otel.map(|otel| json!(otel)),
|
||||
otel: requirements.otel.map(redact_otel_requirements),
|
||||
allow_login_shell: requirements.allow_login_shell,
|
||||
shell_environment_policy: requirements
|
||||
.shell_environment_policy
|
||||
@@ -422,18 +424,34 @@ fn map_shell_environment_policy_requirements_to_api(
|
||||
inherit,
|
||||
ignore_default_excludes,
|
||||
r#set,
|
||||
rules,
|
||||
experimental_use_profile,
|
||||
filters,
|
||||
} = policy;
|
||||
ShellEnvironmentPolicyRequirements {
|
||||
inherit,
|
||||
ignore_default_excludes,
|
||||
r#set,
|
||||
rules,
|
||||
experimental_use_profile,
|
||||
filters,
|
||||
}
|
||||
}
|
||||
|
||||
fn redact_otel_requirements(mut otel: OtelConfigToml) -> serde_json::Value {
|
||||
for exporter in [
|
||||
&mut otel.exporter,
|
||||
&mut otel.trace_exporter,
|
||||
&mut otel.metrics_exporter,
|
||||
] {
|
||||
let headers = match exporter {
|
||||
Some(OtelExporterKind::OtlpHttp { headers, .. })
|
||||
| Some(OtelExporterKind::OtlpGrpc { headers, .. }) => headers,
|
||||
Some(OtelExporterKind::None | OtelExporterKind::Statsig) | None => continue,
|
||||
};
|
||||
headers
|
||||
.values_mut()
|
||||
.for_each(|value| *value = "<redacted>".to_string());
|
||||
}
|
||||
json!(otel)
|
||||
}
|
||||
|
||||
fn map_computer_use_requirements_to_api(
|
||||
computer_use: codex_config::ComputerUseRequirementsToml,
|
||||
) -> ComputerUseRequirements {
|
||||
@@ -626,8 +644,8 @@ mod tests {
|
||||
use codex_config::ComputerUseRequirementsToml;
|
||||
use codex_config::ConfigRequirementsToml;
|
||||
use codex_config::WindowsRequirementsToml;
|
||||
use codex_protocol::config_types::ShellEnvironmentPolicyFilter;
|
||||
use codex_protocol::config_types::ShellEnvironmentPolicyInherit;
|
||||
use codex_protocol::config_types::ShellEnvironmentPolicyRule;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use std::collections::BTreeMap;
|
||||
@@ -730,7 +748,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requirements_api_preserves_otel_headers_and_shell_environment_policy() {
|
||||
fn requirements_api_redacts_otel_headers_and_preserves_shell_environment_policy() {
|
||||
let requirements = toml::from_str(
|
||||
r#"
|
||||
[otel]
|
||||
@@ -744,9 +762,7 @@ team = "codex"
|
||||
[shell_environment_policy]
|
||||
inherit = "core"
|
||||
ignore_default_excludes = false
|
||||
experimental_use_profile = false
|
||||
|
||||
[shell_environment_policy.rules]
|
||||
[shell_environment_policy.filters]
|
||||
"*SECRET*" = "exclude"
|
||||
"HOME" = "include"
|
||||
"PATH" = "exclude"
|
||||
@@ -763,7 +779,7 @@ MANAGED = "true"
|
||||
.otel
|
||||
.as_ref()
|
||||
.and_then(|otel| otel.pointer("/exporter/otlp-http/headers")),
|
||||
Some(&json!({"Authorization": "Bearer secret"}))
|
||||
Some(&json!({"Authorization": "<redacted>"}))
|
||||
);
|
||||
assert_eq!(
|
||||
mapped.shell_environment_policy,
|
||||
@@ -773,13 +789,16 @@ MANAGED = "true"
|
||||
r#set: Some(HashMap::from([
|
||||
("MANAGED".to_string(), "true".to_string(),)
|
||||
])),
|
||||
rules: Some(BTreeMap::from([
|
||||
("*SECRET*".to_string(), ShellEnvironmentPolicyRule::Exclude,),
|
||||
("HOME".to_string(), ShellEnvironmentPolicyRule::Include,),
|
||||
("PATH".to_string(), ShellEnvironmentPolicyRule::Exclude,),
|
||||
filters: Some(BTreeMap::from([
|
||||
(
|
||||
"*SECRET*".to_string(),
|
||||
ShellEnvironmentPolicyFilter::Exclude,
|
||||
),
|
||||
("HOME".to_string(), ShellEnvironmentPolicyFilter::Include,),
|
||||
("PATH".to_string(), ShellEnvironmentPolicyFilter::Exclude,),
|
||||
])),
|
||||
experimental_use_profile: Some(false),
|
||||
})
|
||||
);
|
||||
assert!(!mapped.otel.unwrap().to_string().contains("Bearer secret"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,48 @@ async fn config_requirements_read_includes_allow_remote_control() -> Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn config_write_reports_managed_requirement_as_read_only() -> Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
write_config(&codex_home, "")?;
|
||||
std::fs::write(
|
||||
codex_home.path().join("requirements.toml"),
|
||||
r#"chatgpt_base_url = "https://managed.example""#,
|
||||
)?;
|
||||
let mut mcp = TestAppServer::new(codex_home.path()).await?;
|
||||
timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;
|
||||
|
||||
let request_id = mcp
|
||||
.send_config_value_write_request(ConfigValueWriteParams {
|
||||
file_path: None,
|
||||
key_path: "chatgpt_base_url".to_string(),
|
||||
value: json!("https://user.example"),
|
||||
merge_strategy: MergeStrategy::Replace,
|
||||
expected_version: None,
|
||||
})
|
||||
.await?;
|
||||
let error: JSONRPCError = timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
mcp.read_stream_until_error_message(RequestId::Integer(request_id)),
|
||||
)
|
||||
.await??;
|
||||
|
||||
assert_eq!(
|
||||
error
|
||||
.error
|
||||
.data
|
||||
.as_ref()
|
||||
.and_then(|data| data.get("config_write_error_code"))
|
||||
.and_then(serde_json::Value::as_str),
|
||||
Some("configRequirementReadonly")
|
||||
);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(codex_home.path().join("config.toml"))?,
|
||||
""
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn config_read_returns_effective_and_layers() -> Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
|
||||
@@ -119,6 +119,7 @@ pub use mcp_types::McpServerToolConfig;
|
||||
pub use mcp_types::McpServerTransportConfig;
|
||||
pub use mcp_types::RawMcpServerConfig;
|
||||
pub use merge::merge_toml_values;
|
||||
pub use merge::merge_toml_values_at_path;
|
||||
pub use overrides::build_cli_overrides_layer;
|
||||
pub use plugin_edit::PluginConfigEdit;
|
||||
pub use plugin_edit::apply_user_plugin_config_edits;
|
||||
|
||||
@@ -5,10 +5,14 @@ use toml::Value as TomlValue;
|
||||
|
||||
/// Merge config `overlay` into `base`, giving `overlay` precedence.
|
||||
pub fn merge_toml_values(base: &mut TomlValue, overlay: &TomlValue) {
|
||||
merge_toml_values_at_path(base, overlay, &mut Vec::new());
|
||||
merge_toml_values_at_path(base, overlay, &[]);
|
||||
}
|
||||
|
||||
fn merge_toml_values_at_path(base: &mut TomlValue, overlay: &TomlValue, path: &mut Vec<String>) {
|
||||
pub fn merge_toml_values_at_path(base: &mut TomlValue, overlay: &TomlValue, path: &[String]) {
|
||||
merge_toml_values_recursive(base, overlay, &mut path.to_vec());
|
||||
}
|
||||
|
||||
fn merge_toml_values_recursive(base: &mut TomlValue, overlay: &TomlValue, path: &mut Vec<String>) {
|
||||
prepare_shell_environment_policy_merge(base, overlay, path);
|
||||
|
||||
if let TomlValue::Table(overlay_table) = overlay
|
||||
@@ -31,7 +35,7 @@ fn merge_toml_values_at_path(base: &mut TomlValue, overlay: &TomlValue, path: &m
|
||||
for (key, value) in overlay_table {
|
||||
path.push(key.clone());
|
||||
if let Some(existing) = base_table.get_mut(&key) {
|
||||
merge_toml_values_at_path(existing, &value, path);
|
||||
merge_toml_values_recursive(existing, &value, path);
|
||||
} else {
|
||||
base_table.insert(key, normalized_for_merge(&value, path));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user