feat: add allowEnv policy option for shell commands#24782
feat: add allowEnv policy option for shell commands#24782rmedranollamas wants to merge 3 commits intogoogle-gemini:mainfrom
Conversation
This adds `allowEnv` to the policy engine, mirroring the behavior of `allowRedirection`. It allows shell commands prefixed with environment variable assignments (e.g. `VAR=value cmd`) to execute without prompting the user if they match a rule with `allowEnv = true`. Also includes tests to verify parsing and enforcement logic. Co-authored-by: rmedranollamas <45878745+rmedranollamas@users.noreply.github.com>
This adds `allowEnv` to the policy engine, mirroring the behavior of `allowRedirection`. It allows shell commands prefixed with environment variable assignments (e.g. `VAR=value cmd`) to execute without prompting the user if they match a rule with `allowEnv = true`. Also includes tests to verify parsing and enforcement logic. Co-authored-by: rmedranollamas <45878745+rmedranollamas@users.noreply.github.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the policy engine by adding support for 'allowEnv', a configuration option that allows the AI to execute shell commands containing environment variable assignments without manual intervention. By leveraging the existing tree-sitter-bash parser for precise detection, this change improves agent autonomy while maintaining security, ensuring that commands requiring environment variables are only executed automatically when explicitly permitted by the user's policy. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to detect environment variable prefixes in shell commands and downgrade the policy decision from ALLOW to ASK_USER unless explicitly permitted by a new allowEnv rule property. This change includes updates to the policy engine, type definitions, and shell utility functions, along with corresponding tests. A security concern was identified regarding the hasEnvPrefix implementation, which currently only detects bash-native assignments and misses other methods like the env utility, potentially allowing for policy bypasses.
|
@jules ptal |
This adds `allowEnv` to the policy engine, mirroring the behavior of `allowRedirection`. It allows shell commands prefixed with environment variable assignments (e.g. `VAR=value cmd`) to execute without prompting the user if they match a rule with `allowEnv = true`. Also includes tests to verify parsing and enforcement logic. Address Code Review Feedback: - Updated `hasEnvPrefix` to detect the use of the `env` command (e.g., `env VAR=val cmd`) - Added tests to verify `env` command detection Co-authored-by: rmedranollamas <45878745+rmedranollamas@users.noreply.github.com>
|
I think this should not work still, but it would be beneficial to carry inspection for injection in the environment prefix. For example |
kschaab
left a comment
There was a problem hiding this comment.
This seems to ignore FOO=bar cmd && cmd2 case where FOO now applies to cmd2.
|
|
||
| expect(result.decision).toBe(PolicyDecision.ASK_USER); | ||
| }); | ||
|
|
There was a problem hiding this comment.
You can use tests for escapes like PAGER="less -X" or PAGER=less\ -X.
| @@ -0,0 +1,28 @@ | |||
| import { initializeShellParsers } from './packages/core/dist/src/utils/shell-utils.js'; | |||
| @@ -0,0 +1,28 @@ | |||
| import { initializeShellParsers } from './packages/core/dist/src/utils/shell-utils.js'; | |||
There was a problem hiding this comment.
Looks like leftovers from the agent.
Summary
This PR introduces the allowEnv (and allow_env) configuration option to the policy engine. This allows users to configure rules that permit the AI model to execute shell commands prefixed with environment variables (e.g., PAGER=cat git commit) without requiring user confirmation. Currently, any command with an environment variable assignment is downgraded to ASK_USER. This change brings environment variable assignments to parity with the existing allowRedirection feature, improving the agent's autonomy while maintaining security.
Details
Related Issues
Closes #24779
How to Validate
Pre-Merge Checklist