Enforce environment-specific command policies (#38942)

## What changed

- Add an optional restrictive execution policy to `EnvironmentConfig` and merge it over the active command policy for shell execution and approval decisions.
- Reject environment policies that contain allow rules, so environment configuration can only tighten command access.
- Include the environment policy fingerprint in cached approval keys so policy changes require fresh session approvals.

## Testing

- Cover restrictions overriding saved prefix approvals, policy changes invalidating session approvals, and environment overlays remaining effective when model-specific prefix filtering is active.

GitOrigin-RevId: e94f877549ed5e0f577b8cb52f3c1872c58f029d
This commit is contained in:
sayan-oai authored and copyberry committed 2026-08-17 04:37:50 +00:00
1 parent 89e297729e
commit e38290846c
27 files changed
+364 -17

No files matched your search

@@ -31,6 +31,7 @@ fn test_turn_environment(environment_id: &str) -> crate::session::turn_context::
PermissionProfile::read_only(),
),
shell_environment_policy: Default::default(),
exec_policy: None,
selected_capability_roots: Vec::new(),
}),
},
@@ -183,7 +183,10 @@ pub(super) async fn try_run_zsh_fork(
ctx.session
.services
.exec_policy
.current_for_prefix_rules(ctx.step_context.turn.allow_prefix_rules())
.current_for_environment(
req.turn_environment.config().exec_policy.as_ref(),
ctx.step_context.turn.allow_prefix_rules(),
)
.as_ref()
.clone(),
));
@@ -297,7 +300,10 @@ pub(crate) async fn prepare_unified_exec_zsh_fork(
ctx.session
.services
.exec_policy
.current_for_prefix_rules(ctx.step_context.turn.allow_prefix_rules())
.current_for_environment(
req.turn_environment.config().exec_policy.as_ref(),
ctx.step_context.turn.allow_prefix_rules(),
)
.as_ref()
.clone(),
));
@@ -28,6 +28,7 @@ async fn approval_key_uses_path_uri_and_includes_environment_id() {
PermissionProfile::read_only(),
),
shell_environment_policy: Default::default(),
exec_policy: None,
selected_capability_roots: Vec::new(),
}),
},
@@ -543,6 +543,7 @@ mod tests {
PermissionProfile::read_only(),
),
shell_environment_policy: Default::default(),
exec_policy: None,
selected_capability_roots: Vec::new(),
}),
},