Skip to content

feat(policy): support * wildcards in permission function patterns#187

Merged
ytallo merged 2 commits into
mainfrom
feat/permissions-glob-wildcards
May 25, 2026
Merged

feat(policy): support * wildcards in permission function patterns#187
ytallo merged 2 commits into
mainfrom
feat/permissions-glob-wildcards

Conversation

@ytallo
Copy link
Copy Markdown
Contributor

@ytallo ytallo commented May 25, 2026

Summary

Permission rules in iii-permissions.yaml can now use * in the function
pattern to match any substring. Patterns without * keep matching exactly,
so every existing rule behaves identically.

This unlocks namespace-scoped rules:

rules:
  - shell::*          # allow any function under the shell namespace
  - "*::list"         # allow any worker's ::list leaf
  - "!state::*"       # deny the whole state namespace
  - "*"               # catch-all (order matters)

Globs also compose with the existing constrained form:

  - function: shell::fs::*
    action: allow
    args:
      path:
        matches: '^/tmp/'

How it works

  • compileFunctionMatcher (harness/src/harness/policy/compile.ts) turns a
    pattern containing * into an anchored regex (^...$). * becomes .*;
    every other regex metacharacter is escaped, so * is the only wildcard.
    A pattern with no * compiles to glob: null and matches by ===.
  • matchFunctionId resolves a rule against a concrete function_id via the
    glob when present, else exact equality.
  • Permissions.check routes through matchFunctionId; arg constraints still
    AND-compose with a globbed function.

The engine remains fail-closed: anything not positively matched to an
allow/deny rule resolves to needs_approval.

Tests

harness/tests/harness/policy.test.ts — 50 passing, full harness suite 902/0.
New adversarial coverage:

  • Namespace globs are anchored — Xshell::exec, shellexec, shell do not
    satisfy shell::*.
  • Only * is a wildcard — . and other metacharacters match literally
    (a.c::* does not match aXc::ping).
  • Suffix-position globs stay end-anchored — *::list rejects models::listing.
  • A deny glob covers the whole namespace regardless of args and can't be
    dodged by appending levels.
  • A newline in a function_id fails closed to needs_approval instead of
    tunneling past a deny glob into a catch-all allow.
  • A constrained allow on an exact function still works and composes with a glob.

Known limitation

A single pattern with multiple * (e.g. a*b*c*) compiles to multiple .*
groups. Patterns are author-controlled (not attacker input) and the common
forms (ns::*, *::leaf) are single-* and linear, so this is a rule-author
footgun rather than an exploitable surface.

Test plan

  • pnpm typecheck clean
  • pnpm vitest run — 902 passing, 0 failing
  • pnpm vitest run policy — 50 passing, 0 failing

Function patterns in iii-permissions.yaml may now contain `*`, which
matches any substring. A pattern with no `*` still matches exactly, so
existing rules are unchanged.

- compileFunctionMatcher turns a pattern containing `*` into an anchored
  regex (`^...$`): `*` becomes `.*` and every other regex metacharacter
  is escaped, so `*` is the only wildcard.
- matchFunctionId resolves a rule against a concrete function_id via the
  glob when present, else exact equality.
- check() routes through matchFunctionId; arg constraints still
  AND-compose with globbed functions.

Adversarial tests cover anchoring (no prefix/suffix injection),
metacharacter escaping, suffix-position globs, deny globs over hostile
args, and that a newline in a function_id fails closed to needs_approval
rather than tunneling past a deny into a catch-all.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
workers Ready Ready Preview, Comment May 25, 2026 7:13pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

Warning

Review limit reached

@ytallo, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 1 minute and 29 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, 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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 016bd59c-9086-4444-a0a6-9d32e998f34a

📥 Commits

Reviewing files that changed from the base of the PR and between b330907 and ff7a195.

📒 Files selected for processing (6)
  • harness/docs/architecture.md
  • harness/docs/workers/harness.md
  • harness/src/harness/policy/compile.ts
  • harness/src/harness/policy/permissions.ts
  • harness/tests/harness/policy.test.ts
  • iii-permissions.yaml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/permissions-glob-wildcards

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 25, 2026

skill-check — worker

0 verified, 12 skipped (no docs/).

Layer Result
structure
vale
ai

Three for three. Nicely done.

Add a Wildcards note to the architecture Kernel deny list section covering
namespace globs (shell::*, *::list, catch-all, !state::*), anchoring, and
arg-constraint composition. Update the compile.ts source-layout row to
mention matchFunctionId.
@ytallo ytallo merged commit 0929af9 into main May 25, 2026
12 checks passed
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.

2 participants