Add tool annotation context for Cedar/HTTP authz#4102
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4102 +/- ##
==========================================
+ Coverage 68.68% 68.69% +0.01%
==========================================
Files 453 454 +1
Lines 46011 46049 +38
==========================================
+ Hits 31604 31635 +31
- Misses 11967 11974 +7
Partials 2440 2440 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
923d27a to
cdd5c10
Compare
Cedar policies can reference entity attributes like `resource.readOnlyHint == true`, but tool annotations were never reaching the authorizers. This adds context-based annotation injection so both Cedar and HTTP PDP authorizers can use MCP tool annotations (readOnlyHint, destructiveHint, idempotentHint, openWorldHint) in authorization decisions. - Add ToolAnnotations struct and context helpers in authorizers package - Cedar authorizer merges annotations into resource entity attributes - HTTP PDP authorizer includes annotations in PORC context - Foundation for annotation cache (PR 2) and vmcp flow (PR 3) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reverse the Cedar mergeContexts order so standard resource attributes (name, operation, feature) are applied last and cannot be overwritten by annotation keys. Guard HTTP PDP annotation enrichment to tool-call operations only. Add slog.Warn when enrichPORCWithAnnotations encounters unexpected types instead of silently discarding context. Document the trust boundary (annotations must come from the server-side registry) and the asymmetric exposure paths between Cedar and HTTP authorizers. Add unit tests for enrichPORCWithAnnotations (8 cases) and Cedar attribute collision safety (5 cases). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Restore the original method ordering so the PR diff only shows the actual logic changes, not a spurious move. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dce379d to
f05b218
Compare
jhrozek
reviewed
Mar 11, 2026
jhrozek
approved these changes
Mar 11, 2026
This was referenced Mar 12, 2026
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
resource.readOnlyHint == true, but MCP tool annotations (readOnlyHint, destructiveHint, idempotentHint, openWorldHint) never reached the Cedar or HTTP PDP authorizers. This adds context-based annotation injection so authorization policies can make decisions based on tool properties.ToolAnnotationsstruct and context helpers (WithToolAnnotations/ToolAnnotationsFromContext) in theauthorizerspackage — the shared interface package that both Cedar and HTTP PDP already import, avoiding import cycles.resource.readOnlyHint == true.context.mcp.annotationsin the PORC structure.Type of change
Test plan
task test)task lint-fix)Changes
pkg/authz/authorizers/annotations.goToolAnnotationsstruct, context helpers,AnnotationsToMapconverterpkg/authz/authorizers/annotations_test.gopkg/authz/authorizers/cedar/core.goauthorizeToolCallaccepts context, reads annotations and merges into resource entity attributes; movedAuthorizeWithJWTClaimsto public methods sectionpkg/authz/authorizers/http/core.goAuthorizeWithJWTClaimsenriches PORC context with annotations; newenrichPORCWithAnnotationshelperpkg/authz/authorizers/cedar/annotations_integration_test.goresource.readOnlyHint,resource.destructiveHint, and graceful degradation without annotationsDoes this introduce a user-facing change?
No — this adds the internal plumbing. Users will benefit once annotations are populated (via annotation cache in PR 2 or vmcp discovery in PR 3), enabling Cedar policies that reference tool annotations.
Special notes for reviewers
pkg/authz/authorizers/(notpkg/authz/) because Cedar and HTTP PDP packages importauthorizersbut not the parentauthzpackage.resource.readOnlyHint) rather than context values. This is more natural since annotations are intrinsic tool properties, not request-specific data.AnnotationsToMapreturns nil, andmergeContextsskips nil maps — so existing behavior is completely unchanged.forbidtest case uses separate policy strings (onepermit, oneforbid) becauseUnmarshalCedarparses one policy per call.Generated with Claude Code