mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Honor per-environment shell variable policies (#38902)
## What changed - Carry `ShellEnvironmentPolicy` in each resolved `EnvironmentConfig` and use the selected turn environment's policy for shell commands, user shell tasks, and unified exec. - Infer the policy from the thread configuration when an environment does not provide its own resolved configuration. - Redact the policy from `EnvironmentConfig` debug output because it can contain explicit environment variable values. ## Testing - Verify shell handlers and unified exec filter inherited variables according to the selected environment while preserving its explicit overrides. GitOrigin-RevId: 9f6a52aa4af60e5f17251a0e1b11e1926b779055
This commit is contained in:
1 parent
f85e81d30b
commit
6c108912ee
22 files changed
+219
-52
No files matched your search
@@ -81,12 +81,7 @@ async fn run_exec_like(args: RunExecLikeArgs) -> Result<FunctionToolOutput, Func
|
||||
|
||||
let fs = turn_environment.environment.get_filesystem();
|
||||
|
||||
let mut explicit_env_overrides = turn
|
||||
.config
|
||||
.permissions
|
||||
.shell_environment_policy
|
||||
.r#set
|
||||
.clone();
|
||||
let mut explicit_env_overrides = turn_environment.shell_environment_policy().r#set.clone();
|
||||
let mut env = exec_params.env.clone();
|
||||
strip_output_env(&mut env);
|
||||
strip_output_env(&mut explicit_env_overrides);
|
||||
|
||||
@@ -108,7 +108,7 @@ impl ShellCommandHandler {
|
||||
let command = Self::base_command(shell, ¶ms.command, use_login_shell);
|
||||
|
||||
let mut env = create_env(
|
||||
&turn_context.config.permissions.shell_environment_policy,
|
||||
turn_environment.shell_environment_policy(),
|
||||
Some(session.thread_id),
|
||||
);
|
||||
inject_session_id_env(&mut env, session.session_id());
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use codex_protocol::config_types::EnvironmentVariablePattern;
|
||||
use codex_protocol::config_types::ShellEnvironmentPolicy;
|
||||
use codex_protocol::config_types::ShellEnvironmentPolicyInherit;
|
||||
use codex_protocol::models::ActivePermissionProfile;
|
||||
use codex_protocol::models::ShellCommandToolCallParams;
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -82,7 +86,14 @@ fn assert_safe(shell: &Shell, command: &str) {
|
||||
async fn shell_command_handler_to_exec_params_uses_selected_environment() {
|
||||
let (session, mut turn_context) = make_session_and_context().await;
|
||||
let permission_profile = turn_context.config.permissions.permission_profile().clone();
|
||||
Arc::make_mut(&mut turn_context.config)
|
||||
let config = Arc::make_mut(&mut turn_context.config);
|
||||
config.permissions.shell_environment_policy.r#set = HashMap::from([
|
||||
("KEEP".to_string(), "from-thread".to_string()),
|
||||
("DROP".to_string(), "from-thread".to_string()),
|
||||
]);
|
||||
config.permissions.shell_environment_policy.include_only =
|
||||
vec![EnvironmentVariablePattern::new_case_insensitive("DROP")];
|
||||
config
|
||||
.permissions
|
||||
.set_permission_profile_from_session_snapshot(PermissionProfileSnapshot::active(
|
||||
permission_profile.clone(),
|
||||
@@ -105,6 +116,17 @@ async fn shell_command_handler_to_exec_params_uses_selected_environment() {
|
||||
let selected_cwd = turn_context.config.cwd.join("selected-environment");
|
||||
let expected_cwd = selected_cwd.join("subdir");
|
||||
let active_permission_profile = ActivePermissionProfile::new("selected-profile");
|
||||
let selected_shell_environment_policy = ShellEnvironmentPolicy {
|
||||
inherit: ShellEnvironmentPolicyInherit::None,
|
||||
include_only: vec![EnvironmentVariablePattern::new_case_insensitive("KEEP")],
|
||||
r#set: turn_context
|
||||
.config
|
||||
.permissions
|
||||
.shell_environment_policy
|
||||
.r#set
|
||||
.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
let selected_environment = TurnEnvironment::new(
|
||||
TurnEnvironmentSelection {
|
||||
environment_id: "selected-environment".to_string(),
|
||||
@@ -116,6 +138,7 @@ async fn shell_command_handler_to_exec_params_uses_selected_environment() {
|
||||
permission_profile,
|
||||
active_permission_profile.clone(),
|
||||
),
|
||||
shell_environment_policy: selected_shell_environment_policy.clone(),
|
||||
selected_capability_roots: Vec::new(),
|
||||
}),
|
||||
},
|
||||
@@ -129,10 +152,7 @@ async fn shell_command_handler_to_exec_params_uses_selected_environment() {
|
||||
),
|
||||
Some(selected_shell),
|
||||
);
|
||||
let mut expected_env = create_env(
|
||||
&turn_context.config.permissions.shell_environment_policy,
|
||||
Some(session.thread_id),
|
||||
);
|
||||
let mut expected_env = create_env(&selected_shell_environment_policy, Some(session.thread_id));
|
||||
inject_session_id_env(&mut expected_env, session.session_id());
|
||||
inject_permission_profile_env(&mut expected_env, Some(&active_permission_profile));
|
||||
|
||||
|
||||
Reference in new issue
Block a user