Skip to content

proposal: multiple policies per VM#12

Merged
kanywst merged 2 commits into
mainfrom
feat/multiple-policies
May 9, 2026
Merged

proposal: multiple policies per VM#12
kanywst merged 2 commits into
mainfrom
feat/multiple-policies

Conversation

@kanywst

@kanywst kanywst commented May 9, 2026

Copy link
Copy Markdown
Member

Design doc only. Tracks the multiple-policies item from ROADMAP medium term.

See docs/proposals/multiple-policies.md.

Summary:

  • Plugin config accepts modules[] + targets[]. Each module can carry an optional package. Targets address rules as package.rule.
  • Evaluator gains evalModules(target_pkg, target_rule, input). Existing single-module configs keep working via a synthetic wrapper.
  • Per-target on_deny lets one decision block (403) while another logs only, supporting the "authz enforces, audit observes" pattern in one VM.

Status: design only, no implementation.

@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@kanywst has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 33 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e00f2afe-7dc7-461e-af6e-a27466d331c5

📥 Commits

Reviewing files that changed from the base of the PR and between d119f94 and da3e557.

📒 Files selected for processing (5)
  • docs/proposals/multiple-policies.md
  • src/ast.zig
  • src/eval.zig
  • test/run.mjs
  • test/run_wasmtime.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/multiple-policies

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request proposes a design for supporting multiple policies per VM, allowing for separate authentication, authorization, and audit modules with configurable evaluation targets. Feedback highlights inconsistencies in the proposed function signatures and naming conventions, and suggests refining the evaluation order to ensure that short-circuiting on denial does not bypass audit logging.

Comment on lines +49 to +51
1. Evaluator gains a fully qualified rule lookup: `evalModule(modules,
"authz.allow", input)` instead of just rule-by-name within a single
module.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

There is a naming and signature inconsistency between this section and the Design sketch (line 72). This section uses evalModule(modules, "authz.allow", input), while the sketch uses evalModules(target_pkg, target_rule, input). It would be better to align the function name and the argument structure (including the modules container) across the document.

Comment on lines +85 to +86
- If decision is deny and `on_deny` is `send_local_response_403`,
short-circuit immediately.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The proposed short-circuiting logic for send_local_response_403 may interfere with the 'audit observes' pattern. If an enforcing target is placed before an audit target in the targets[] list, a denial will prevent the audit target from being evaluated. Consider specifying that all non-enforcing targets should be evaluated before any short-circuiting occurs, or clarifying the expected ordering in the documentation.


A bare module (current shape, no `modules` wrapper) is wrapped into a
synthetic single-element list with `package: ""` and a synthetic
`targets[]` of `[{ package: "", rule: "allow", on_deny: send_403 }]`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For consistency, use send_local_response_403 instead of send_403, matching the example provided in the Goals section (line 43).

@kanywst kanywst marked this pull request as ready for review May 9, 2026 13:58
kanywst added 2 commits May 9, 2026 23:22
ast.zig:
- Module gains optional package field (default "").
- New Modules struct wrapping a slice of Module.
- New buildModulesBundle handles {"type":"modules","modules":[...]}
  plus the legacy single-module / bare-expression forms (wrapped as
  a 1-element bundle with package="" for backwards compat).

eval.zig:
- New evaluateAddressed(arena, input, ast, target_pkg, target_rule)
  parses the AST as a bundle and dispatches to package.rule.
- Existing evaluate() delegates to evaluateAddressed with
  ("", "allow"), so all existing call sites are untouched.
- New evalBundle OR-combines evalModule across every module whose
  package matches; missing package -> deny by default.

Tests:
- src/eval.zig: 4 unit tests (cross-package addressing, missing
  package, backwards compat, OR within a package).
- test/run.mjs and test/run_wasmtime.py: 4 cases each verifying
  the wire format works through the wasm boundary.

Release build grows from 50K to 54K. ci.yml gains the test-unit job
in line with the other implementation branches.
@kanywst kanywst force-pushed the feat/multiple-policies branch from 0e18049 to da3e557 Compare May 9, 2026 14:25
@kanywst kanywst merged commit 956cf1c into main May 9, 2026
10 checks passed
@kanywst kanywst deleted the feat/multiple-policies branch May 9, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant