Design and implement a governance-rule sandboxing/resource-limiting execution model - #317
Open
nurudeenheroic wants to merge 1 commit into
Conversation
…mits and timeout - Add AST complexity scoring (computeComplexity) with MAX_COMPLEXITY=64 - Add pre-pass complexity guard (estimateComplexity) to protect recursive validator from pathologically wide×deep ASTs (50¹⁰ worst case) - Export RESOURCE_LIMITS for consumers to surface in docs/UI - Add evaluateRuleWithBudget() with wall-clock timeout (default 5ms) - Thread deadline through all combinator functions as yield point - Wire timeout into GovernanceRuleProvider → returns GOVERNANCE_TIMEOUT code - Add 9 new tests for complexity scoring and budget-aware evaluation - Add load test with max-complexity AST (1000 evaluations bounded) - Document resource-limiting model in GOVERNANCE_ENGINE_IMPLEMENTATION.md Closes Adamantine-guild#155
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.
Summary
Implements a three-layer resource-limiting execution model for governance rule evaluation, preventing maliciously or accidentally crafted rule ASTs from degrading checkAccess() latency.
Layers of Defence
Changes
packages/governance-engine/src/validator.ts
computeComplexity()— weighted AST complexity scoringestimateComplexity()— pre-pass guard protecting recursive validator from pathologically wide×deep ASTs (e.g., 50¹⁰ worst case)RESOURCE_LIMITSexportvalidateRuleAST()to use the pre-pass guardpackages/governance-engine/src/evaluator.ts
EvaluationOptionsinterface withtimeoutMsevaluateRuleWithBudget()— budget-aware entry point with wall-clock deadlineevaluateNode()at each AST node entrydeadlinethrough all combinator functions (AND, OR, NOT, N_OF_M)evaluateRule()kept for backward compatibilityapps/access-api/src/policy/governanceRuleProvider.ts
evaluateRule()toevaluateRuleWithBudget()with 5ms timeoutGOVERNANCE_TIMEOUTDENY code on timeouttests
docs
Acceptance Criteria
Fixes #155