agentic-community / agentic-community/mcp-gateway-registry

Audit Log displays Entra `sub` instead of identifiable user for OBO-authenticated MCP calls

オープン
#1,642 コメント 0 件 リアクション 0 件 担当者 1 名 @omrishiv が担当を希望しています GitHub で見る
主要言語
Python
スター
912
フォーク
234
平均マージ
1日 11時間
マージ済み PR(30日)
62

説明

## Summary

When an Entra-authenticated client accesses an OBO-capable MCP server through AI Gateway, the Gateway Audit Log displays the JWT `sub` claim in the **USER** field rather than a human-readable or stable Entra user identity.

For example, an audit entry for a request made by `user@example.com` is displayed as:

```text
USER:
```

I confirmed that this value is exactly the `sub` claim from the Entra access token.

The same token contains both the user's UPN and Entra Object ID, so Gateway has sufficient information to record an identifiable user.

## Environment

* AI Gateway: QA
* Gateway version: `1.29.0`
* Authentication: Microsoft Entra ID
* Flow: delegated user authentication / OBO
* Target: MCP server supporting OBO
* MCP operation observed: `tools/call`

## Steps to reproduce

1. Configure an MCP server behind AI Gateway with Entra OBO authentication.
2. Authenticate to Gateway using an Entra delegated user token.
3. Invoke an MCP operation, e.g. `tools/call`.
4. Open **AI Gateway → Audit**.
5. Locate the corresponding request.
6. Inspect the value shown in the **USER** column.
7. Decode the Entra access token used for the request and compare its identity claims.

## Actual behavior

Gateway displays an opaque value in the Audit Log **USER** field:

```text

```

Decoded token claims confirm that this is the JWT `sub`:

```text
sub =
oid =
upn = user@example.com
name = Example User
scp = access_as_user
```

Therefore, the value shown as **USER** is currently sourced from `sub`.

## Expected behavior

The Audit Log should identify the originating Entra user in a way that is meaningful to an administrator.

For example:

```text
USER: user@example.com
```

For durable identity and audit correlation, Gateway should also retain the Entra identity using:

```text
oid + tid
```

The `sub` claim may still be useful for protocol-level correlation and could remain available in the event details, but it should not be the only identity exposed as the human-facing **USER** value.

Suggested mapping:

```text
Audit USER -> upn / preferred_username
Canonical user ID -> oid + tid
Event details -> sub, oid, tid, appid/azp, upn, name
```

## Why this is a problem

`sub` is an opaque, pairwise subject identifier. An administrator reviewing the Audit Log cannot reasonably determine which Entra user performed an action from this value alone.

This makes OBO-originated audit events substantially less useful for:

* security investigations
* user activity tracing
* operational troubleshooting
* audit/compliance review
* correlating Gateway activity with Entra users

This is particularly confusing because other audit entries may appear with human-readable identities such as `user@example.com`, while OBO requests appear under an opaque identifier.

## Evidence

For the reproduced request:

```text
Gateway Audit USER
=

JWT sub
=
```

The values are an exact match.

The same JWT simultaneously contains:

```text
upn = user@example.com
oid =
tid =
```

so the Gateway has access to a recognizable user identity at the point the audit record is created.

Additional token context, sanitized:

```text
iss = https://sts.windows.net//
aud = api://
tid =
appid =
scp = access_as_user
```

## Suggested fix

When generating an audit event for an Entra delegated/OBO request:

1. Use `upn` or `preferred_username` as the human-readable **USER** value when available.
2. Persist `oid` and `tid` as the stable Entra identity.
3. Preserve `sub` separately for token-level correlation.
4. Fall back to `sub` only when no more appropriate user identity claims are available.

If the current use of `sub` is intentional, the Audit UI should at minimum expose the associated `upn`/`oid` and avoid presenting `sub` alone under a field labelled **USER**.

## Severity / impact

Suggested severity: **Medium**

Authentication and authorization appear to function correctly; the issue is specifically with audit identity attribution/presentation. However, it materially reduces the usefulness of the Gateway Audit Log for OBO-authenticated traffic.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Find the MCP request-to-audit pipeline for delegated/OBO flows (notably `tools/call`) and trace how JWT claims are mapped into audit fields. Start by reading the auth/audit handlers and any tests around event emission, then locate where the `USER` field is currently sourced from `sub`. Update the mapping to prefer `upn`/`preferred_username` for USER, and preserve `oid` and `tid` (plus `sub`) in event details. Verify by running relevant audit/auth tests and checking AI Gateway Audit shows readable user plus retained stable Entra identity fields.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
azure, python
領域
backend, observability
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
58/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。