feat(builder): add cedar builder in js#137
Conversation
5a52d2a to
a50f346
Compare
Adds js/cedar-agent-policy-builder/ — a TypeScript library that generates Cedar policies, entities, and schemas for agent authorization from declarative configuration. Features: - Fluent builder API: .role(), .restrict(), .rateLimit(), .timeWindow(), .denyToolsInEnv(), .consent(), .resource(), .namespace() - fromConfig() for JSON/object-based configuration - Schema generation via @cedar-policy/mcp-schema-generator-wasm integration - McpServer resource entity generation (aligns with MCP schema generator) - Consent-gated policies (permit when context.session.user_consent == true) - Build-time warnings for undeclared tool references - Edge case handling: empty allowedValues = deny, denyToolsInEnv() without tools = deny all, rateLimit(0) = always deny, timeWindow(n,n) = deny all Tests: 64 tests including adversarial injection tests and real Cedar evaluation via @cedar-policy/cedar-wasm. Signed-off-by: Liz <91279165+lizradway@users.noreply.github.com>
victornicolet
left a comment
There was a problem hiding this comment.
Looks good, I have some comments.
We should also have a README.md with documentation and some CI on this package.
| if (tools.includes('*')) { | ||
| // Deny all tools in this environment | ||
| policies.push( | ||
| `forbid(\n principal,\n action,\n resource\n) when { context.session.environment == "${escapeCedarString(env)}" };` |
There was a problem hiding this comment.
Should the policy checkcontext.session has environment here just to be safe? Same on other uses of context.sessions.<field name>.
| if (forRole) { | ||
| this._config.consent[tool].push(forRole) | ||
| } else { | ||
| this._config.consent[tool] = ['*'] |
There was a problem hiding this comment.
This means that .consent([tool_foo], 'admin').consent(['tool_foo', 'tool_bar']) for example results in having consent for tool_foo for all roles. I think it's worth documenting (for this API and others) how permissions / deny get added/transformed when builder methods are chained (i.e. in this case, ommitting the role results in overwriting all previous consent instructions for a tool).
| } | ||
| if (this._config.consent) { | ||
| for (const tool of Object.keys(this._config.consent)) referenced.add(tool) | ||
| } |
There was a problem hiding this comment.
Should this also add tool references in this._config.rateLimits?
|
cc: @victornicolet
Sounds good! can add README.md, is it alright to add CI in a follow up PR on Monday to get an MVP through? |
Coverage ReportHead Commit: Base Commit: Download the full coverage report. Coverage of Added or Modified Lines of Rust CodeRequired coverage: 80.00% Actual coverage: 100.00% Status: PASSED ✅ Details
Coverage of All Lines of Rust CodeRequired coverage: 80.00% Actual coverage: 90.91% Status: PASSED ✅ Details
|
Description of changes
Adds
js/cedar-agent-policy-builder/— a TypeScript library that generates Cedar policies, entities, and schemas for agent authorization from declarative configuration. Integrates with@cedar-policy/mcp-schema-generator-wasmfor schema generation and@cedar-policy/cedar-wasmfor policy validation.Usage
Builder API:
From config (JSON/object):
.tools()accepts MCP tool definitions (framework-agnostic):Full Strands integration (with
CedarAuthorizationintervention handler):How it integrates with the MCP schema generator:
Issue #, if available
N/A — supporting the Cedar authorization and Intervention Primitive design proposals:
Checklist for requesting a review
The change in this PR is:
cedar-agent-policy-builder(new package)I confirm that this PR:
Additional Context
cedar-policy-mcp-schema-generatorsemantics: actions named directly after tools,context.input.*for tool arguments,context.session.*for runtime state@cedar-policy/mcp-schema-generator-wasmfor schema generation from MCP tool definitions.tools()accepts the standard MCP tool definition format ({ name, inputSchema }) — works with any framework (Strands, OpenAI Agents, raw MCP servers)@cedar-policy/cedar-wasm