Skip to content

execpolicycheck command in codex cli#7012

Merged
zhao-oai merged 13 commits intomainfrom
dev/zhao/execpolicycheck-cli-2
Nov 20, 2025
Merged

execpolicycheck command in codex cli#7012
zhao-oai merged 13 commits intomainfrom
dev/zhao/execpolicycheck-cli-2

Conversation

@zhao-oai
Copy link
Copy Markdown
Contributor

@zhao-oai zhao-oai commented Nov 20, 2025

adding execpolicycheck tool onto codex cli

this is useful for validating policies (can be multiple) against commands.

it will also surface errors in policy syntax:
Screenshot 2025-11-19 at 12 46 21 PM

this PR also changes output format when there's no match in the CLI. instead of returning the raw string noMatch, we return {"noMatch":{}}

this PR is a rewrite of: #6932 (due to the numerous merge conflicts present in the original PR)

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +35 to +37
pub fn run(&self) -> Result<String> {
let policy = load_policies(&self.policies)?;
let evaluation = policy.check(&self.command);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Execpolicycheck skips shell command expansion

The new execpolicycheck subcommand evaluates policies by calling policy.check(&self.command) on the raw argv, so it only considers the literal leading tokens. Runtime enforcement (core/src/exec_policy.rs lines 87‑94) first expands bash -lc/sh -lc and other shell commands via parse_shell_lc_plain_commands and then checks every resulting command, which is how approval decisions are actually made. With the current CLI implementation, commands wrapped in bash -lc "..." (or multiple commands separated by ;) will report noMatch in the checker even though the real runtime would inspect and potentially forbid or prompt for the inner command, making the validation tool misleading for the common shell-wrapped cases it’s meant to preview.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

@zhao-oai zhao-oai Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for a cli tool -- we are assuming the user passes in unwrapped commands

@zhao-oai zhao-oai requested a review from bolinfest November 20, 2025 18:03
Copy link
Copy Markdown
Collaborator

@bolinfest bolinfest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have an integration test for the CLI if you don't already. Take a look at assert_cmd::Command::cargo_bin (or alternatively, escargot::CargoBuild) for how to run a bin target from an integration test.

Comment thread codex-rs/bad.codexpolicy Outdated
Comment thread codex-rs/cli/src/main.rs Outdated
Comment thread codex-rs/cli/src/main.rs Outdated
Comment thread codex-rs/execpolicy/src/execpolicycheck.rs Outdated
@zhao-oai zhao-oai requested a review from bolinfest November 20, 2025 19:49
use tempfile::TempDir;

#[test]
fn execpolicy_check_matches_expected_json() -> Result<(), Box<dyn std::error::Error>> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bolinfest added integration test here!

Comment thread codex-rs/cli/src/main.rs Outdated
@zhao-oai zhao-oai merged commit fe7a3f0 into main Nov 20, 2025
44 of 46 checks passed
@zhao-oai zhao-oai deleted the dev/zhao/execpolicycheck-cli-2 branch November 20, 2025 21:44
@github-actions github-actions bot locked and limited conversation to collaborators Nov 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants