feat(rules): support compound command evaluation with result aggregation#49
feat(rules): support compound command evaluation with result aggregation#49
Conversation
evaluate_command() only handled single commands and wrapper recursion. Compound commands (pipelines, &&, ||, ;) need each sub-command evaluated independently with results aggregated to enforce security policies across the full command line. Add evaluate_compound() that splits compound commands via extract_commands(), evaluates each with evaluate_command(), and aggregates results: - Action: Explicit Deny Wins (deny > ask > allow > default) - Sandbox policy: Strictest Wins via SandboxPreset::merge_strictest() (writable roots intersection, deny paths union, network intersection) - Writable roots contradiction (empty intersection) escalates to Ask Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary of ChangesHello @fohte, 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 significantly enhances the rule engine's capability to handle complex shell commands by introducing a robust mechanism for evaluating compound commands. It ensures that security policies, including actions and sandbox restrictions, are applied consistently and securely across all components of a multi-part command, preventing unintended bypasses and providing clearer enforcement outcomes. Highlights
Changelog
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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for evaluating compound commands by splitting them into sub-commands and aggregating the results, which is a great feature for improving security rule granularity. The implementation for merging sandbox policies and aggregating actions seems robust. My review focuses on improving the test suite's structure to align with the repository's style guide by parameterizing similar test cases, and a small efficiency improvement in the new evaluate_compound logic.
Gemini Code Assist review pointed out redundant iteration in has_writable_contradiction and test cases that should be parameterized per the repository style guide. Pass deduplicated unique_names to has_writable_contradiction instead of the raw preset_names list. Parameterize similar test cases using rstest in both model.rs (merge_strictest writable/network) and rule_engine.rs (compound all_allow/deny_wins across operators). Co-Authored-By: Claude Opus 4.6 <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #49 +/- ##
==========================================
+ Coverage 89.32% 89.78% +0.45%
==========================================
Files 18 18
Lines 3803 4002 +199
==========================================
+ Hits 3397 3593 +196
- Misses 406 409 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Why
|,&&,||,;) passed toevaluate_command()are evaluated as a single command, so individual sub-commands are not checked against permission rulesls -la | rm -rf /does not trigger the deny rule forrm -rf /What
evaluate_compound()that splits compound commands into individual sub-commands, evaluates each, and aggregates resultswritableintersection,denyunion,network.allowintersection)writableintersection becomes empty (contradiction)SandboxPreset::merge_strictest()to aggregate multiple sandbox presets