Repository navigation
Within a policy document, the most cautious matching rule wins - #113
Open
samuelcole wants to merge 4 commits into
Open
samuelcole wants to merge 4 commits into
samuelcole wants to merge 4 commits into
Conversation
Today compileDocument orders a document's rules deny -> ask -> preview -> allow -> typed `rules`, and the engine's Tier 6/7 lookup takes the first match across that whole ordering. That lets a short-form allow array entry beat a typed deny rule, and an earlier typed allow beat a later typed deny, instead of the more cautious rule winning. Pins the cross-source precedence (managed decides before user, when it has a matching rule) and the tie-break order (first rule wins on an effect tie) that the implementation must preserve. Co-Authored-By: Claude Sonnet 5 (Claude Code) <noreply@anthropic.com>
Tier 6/7 used to take the first matching rule across a document's compiled rules — short-form deny/ask/preview/allow arrays, then typed `rules`, in that written order — so a short-form allow could beat a typed deny, and an earlier typed allow could beat a later typed deny. The engine now looks at every rule that matches, per source (managed, then user), and takes the most cautious effect: deny > preview > ask > allow. The first source with any matching rule still decides, exactly as before; only the within-document lookup changed. Ties between rules of equal effect keep the first in the existing compiled order, so a rule's id stays deterministic. Tiers 0-4, origin-grant semantics (Tier 8), and the forced-minimum logic (Tier 2) are untouched; the winning rule's own (pre-forced-minimum) effect is still what `decision.rule.effect` reports, so upstream-consent's `decision.rule.effect === 'allow'` check still sees an allow rule that Tier 2 raised to a preview. Updates docs/PERMISSIONS.md's precedence paragraph and the tier-ladder description, and corrects two stale comments in store.ts about an `appendOriginGrantRules` helper that was never implemented — origin grants are resolved separately, at Tier 8, not compiled into Policy.rules(). Co-Authored-By: Claude Sonnet 5 (Claude Code) <noreply@anthropic.com>
…ule source findFirstMatchingRule described the old first-match order and only its own tests called it. No rule is ever compiled with source 'originGrant' (origin grants are resolved live at Tier 8), so the rule and compiler types no longer offer it. Co-Authored-By: Claude Opus 5.5 (Claude Code) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (Claude Code) <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes HBR-161
Problem
Within one policy document, Harbor's policy engine took the first rule that matched. The store tried the short-form arrays first (deny, ask, preview, allow), then the typed
rulesin the order written, so:allow: ["Tool(*)"]beat atool.calldeny written inrules;allowbeat a later typeddeny.Only an organization's managed deny (Tier 1) was guaranteed to win. The permissions guide used to promise that a deny always wins; the maintainer decided that's the rule Harbor should follow.
Change
extension/src/policy/engine.ts. Tiers 6 and 7 now consider every rule in a source that matches the request, and take the most cautious effect: deny > preview > ask > allow. Ties keep the first rule in compiled order, so a decision's rule id is stable. Across sources nothing changes: the managed policy decides if any of its rules match, otherwise the user's, and origin grants stay at Tier 8. The decision still records the winning rule's own effect, so a page's origin grant still answers an allow rule that Tier 2 raised to a preview.docs/PERMISSIONS.md's ladder, Tier 6/7 text and precedence paragraph say so. A narrowallowcan no longer carve an exception out of a broaddeny; that's the accepted trade.findFirstMatchingRuleinrules.ts, which described the old order and was used only by its own tests, and'originGrant'as a rule source, which no rule was ever compiled with. Origin grants are resolved live at Tier 8.Testing
npx vitest runinextension/: 144 files, 1611 tests pass.npm run buildandnpm run build:chromesucceed.tsc --noEmithas the same errors as the base.tests/e2e): 21/21 pass.Also fixed
policy/store.ts's header said origin grants were compiled into rules by anappendOriginGrantRulesfunction that doesn't exist. It now describes what the code does.What's left
This PR was opened by an AI agent (Claude Code) working for the maintainer.
🤖 Generated with Claude Code