Skip to content

Add name attribute alias on Resource entities#4907

Merged
jhrozek merged 1 commit intomainfrom
authz-resource-name-attr-4
Apr 17, 2026
Merged

Add name attribute alias on Resource entities#4907
jhrozek merged 1 commit intomainfrom
authz-resource-name-attr-4

Conversation

@jhrozek
Copy link
Copy Markdown
Contributor

@jhrozek jhrozek commented Apr 16, 2026

Summary

  • Resource entities in authorizeResourceRead lacked a name attribute, while Tool and Prompt entities had one populated by CreateResourceEntity. This allows the admin to declare name: String as required on all three entity kinds
  • Adds "name": resourceURI to the attributes map in authorizeResourceRead so Resource entities satisfy the schema.
  • Makes CreateResourceEntity default name to resourceID only when the caller has not already set it, so the unsanitized URI supplied by authorizeResourceRead survives and policies can match on the real URI rather than the Cedar-sanitized entity ID.

Fixes #4766

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • Manual testing (describe below)

Manual E2E in a Kind cluster with real Entra ID tokens, using this policy:

permit(principal in THVGroup::"mcp-admin",
       action == Action::"call_tool",
       resource in MCP::"entra-role-test")
  when { resource.name == "echo" };

With an Entra JWT carrying "roles": ["mcp-admin", "developer"]:

  • call_tool "echo" → 200 (resource.name matches)
  • call_tool "nonexistent_tool" → 403 (name mismatch)

Two regression unit tests were added:

  • TestCreateResourceEntity_NamePreservation — guards against reintroducing the unconditional attributes["name"] = resourceID overwrite.
  • A new test in core_test.go exercising the authorizeResourceRead path to confirm the name attribute is emitted.

The enterprise Cedar schema (platform-authz branch, 02-cedar-compilation.md
§ entity types) declares "name" as a required String attribute on all three
entity kinds — Tool, Prompt, and Resource. Tool and Prompt entities already
had "name" populated by CreateResourceEntity, but authorizeResourceRead
built its own attributes map with only "uri", so Resource entities lacked
the attribute and would fail schema validation when the enterprise
controller compiles policies.

Add "name": resourceURI alongside the existing "uri": resourceURI in
authorizeResourceRead so Resource entities satisfy the schema.

In CreateResourceEntity, default "name" to resourceID only when the
caller has not already provided one — authorizeResourceRead sets name
to the original unsanitized URI before passing the sanitized form as
resourceID, and the caller's value must survive.

Preserving the caller-provided name also exposes the original URI to
policies, so authors can match on the form they actually know (e.g.
resource.name == "file:///...") rather than the Cedar-sanitized entity
ID.

E2E tested in a Kind cluster with real Entra ID tokens:

  permit(principal in THVGroup::"mcp-admin",
         action == Action::"call_tool",
         resource in MCP::"entra-role-test")
    when { resource.name == "echo" };

  Entra JWT: { "roles": ["mcp-admin", "developer"] }

  call_tool "echo" -> 200 (resource.name matches)
  call_tool "nonexistent_tool" -> 403 (name mismatch)

Fixes #4766

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels Apr 16, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.23%. Comparing base (0e5e576) to head (b0ad3bf).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4907      +/-   ##
==========================================
- Coverage   69.26%   69.23%   -0.04%     
==========================================
  Files         535      535              
  Lines       55354    55356       +2     
==========================================
- Hits        38343    38325      -18     
- Misses      14068    14087      +19     
- Partials     2943     2944       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jhrozek jhrozek merged commit cfd835c into main Apr 17, 2026
44 of 45 checks passed
@jhrozek jhrozek deleted the authz-resource-name-attr-4 branch April 17, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add name attribute alias on Resource entities

2 participants