Azure / Azure/data-api-builder
centralize role resolution across all MCP tools
- 主要语言
- C#
- 星标
- 1.5k
- 派生
- 370
- 平均合并
- 3 天 22 小时
- 30 天内合并 PR
- 9
描述
**Related PR:** [#3737 — MSRC 31000000666371: MCP `describe_entities` info-disclosure fix + single-role alignment](https://github.com/Azure/data-api-builder/pull/3737)
## Proposed fix
Add a single choke point on `McpAuthorizationHelper` that every MCP tool calls to obtain the caller's role:
```csharp
public static bool TryResolveValidatedRole(
HttpContext httpContext,
IAuthorizationResolver authResolver,
out string? role);
```
Behavior:
- Delegates validation to `IAuthorizationResolver.IsValidRoleContext` (exactly-one non-empty header value + `HttpContext.User.IsInRole(header)`).
- Returns the validated `X-MS-API-ROLE` header value verbatim as the single role for the request.
- Is the only place any MCP code reads `AuthorizationResolver.CLIENT_ROLE_HEADER`.
Then refactor every MCP tool to call it: `DescribeEntitiesTool`, `AggregateRecordsTool`, `CreateRecordTool`, `DeleteRecordTool`, `ExecuteEntityTool`, `ReadRecordsTool`, `UpdateRecordTool`, `DynamicCustomTool`.
## Design
- **Single-role model.** `X-MS-API-ROLE` is one atomic role. No splitting, no unioning. Matches REST, GraphQL, and DAB's existing `ClientRoleHeaderAuthorizationMiddleware`.
- **Resolver-owned inheritance.** Per-entity authorization goes through `IAuthorizationResolver.AreRoleAndOperationDefinedForEntity` / `GetAllowedExposedColumns`, so `anonymous → authenticated → named` inheritance and wildcard `All` expansion are consistent with REST/GraphQL.
- **One header read.** `AuthorizationResolver.CLIENT_ROLE_HEADER` appears in exactly one MCP file after this change.
## Acceptance
- `grep AuthorizationResolver.CLIENT_ROLE_HEADER src/Azure.DataApiBuilder.Mcp/**` returns one match, in `McpAuthorizationHelper`.
- No `.Split(',')` on the role header anywhere in the MCP project.
- All MCP tools use `TryResolveValidatedRole`; existing tests still pass.
## Non-goals
- No resolver behavior changes.
- No config schema changes.
- No new live-database tests.
## Reference
See [PR #3737](https://github.com/Azure/data-api-builder/pull/3737) for the single-role model, the MSRC fix in `DescribeEntitiesTool`, and the `McpAuthorizationHelper.TryResolveAuthorizedRole` alignment this issue builds on.
贡献指南
调研方向
阅读 McpAuthorizationHelper 和八个已命名的 MCP 工具入口点,然后对比 PR #3737 中现有的 alignment 和 security 更改。确认 role header 仅在 McpAuthorizationHelper 中读取,没有任何 MCP 代码对其进行拆分,每个工具都使用 TryResolveValidatedRole,并且现有测试通过。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp
- 领域
- backend-api-design, security
- Issue 类型
- 重构
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 55/100