You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add auditable logging with user_id/org_id correlation
Implement structured audit logging that correlates Gemini user sessions
with Red Hat API requests. Every JSON log record now includes user_id,
org_id, order_id, and a per-request UUID4 request_id, providing a full
audit trail of data lineage independent of ephemeral session storage.
- Add _request_user_id, _request_org_id, _request_id contextvars to auth
middleware with getter functions
- Create AuditContextFilter logging filter that injects audit fields into
every log record from contextvars
- Update JSON log format to include user_id, org_id, order_id, request_id
- Enhance AgentLoggingPlugin with event_type classification and
data_source tracking for MCP tool calls
- Add mcp_jwt_forwarded audit event to MCP header provider
- Document audit logging in .env.example, docs/configuration.md,
deploy/cloudrun/README.md, service.yaml, and podman configmap
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The agent automatically produces structured audit logs that correlate each user session with Red Hat API requests. When `LOG_FORMAT=json` (the default in Cloud Run), every log record includes:
1315
+
1316
+
-**`user_id`** — authenticated user (JWT `sub` claim)
1317
+
-**`org_id`** — Red Hat organization (JWT `org_id` claim)
1318
+
-**`order_id`** — Google Cloud Marketplace order
1319
+
-**`request_id`** — UUID4 correlation ID (unique per request)
1320
+
1321
+
Each agent lifecycle event carries an `event_type` tag (`request_authenticated`, `agent_run_started`, `tool_call_completed`, `mcp_jwt_forwarded`, etc.) and tool calls include a `data_source` field identifying which Red Hat Insights MCP tool retrieved the data.
1322
+
1323
+
This provides a full data lineage audit trail: every piece of information disclosed by the agent can be traced back to a specific authenticated user prompt and a verified Red Hat Insights data source. These persistent logs are independent of the ephemeral ADK session storage.
1324
+
1325
+
### Querying Audit Logs
1326
+
1327
+
Cloud Logging automatically parses JSON log fields. Example queries:
Copy file name to clipboardExpand all lines: docs/configuration.md
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -249,6 +249,55 @@ LOG_FORMAT=text # Human-readable for development
249
249
AGENT_LOGGING_DETAIL=detailed # Include tool args/results in logs
250
250
```
251
251
252
+
#### Audit Logging
253
+
254
+
When `LOG_FORMAT=json` (the default), every log record automatically includes audit context fields:
255
+
256
+
| Field | Source | Description |
257
+
|-------|--------|-------------|
258
+
|`user_id`| JWT `sub` claim | Authenticated user identifier |
259
+
|`org_id`| JWT `org_id` claim | Red Hat organization identifier |
260
+
|`order_id`| DCR client lookup | Google Cloud Marketplace order |
261
+
|`request_id`| Generated UUID4 | Per-request correlation ID |
262
+
263
+
These fields enable:
264
+
-**Request correlation** — all events in a single request share the same `request_id`
265
+
-**User audit** — filter by `user_id` to trace all actions by a specific user
266
+
-**Organization audit** — filter by `org_id` for organization-level auditing
267
+
-**Data lineage** — `tool_call_completed` events include `data_source=<mcp_tool>`, and `mcp_jwt_forwarded` events prove data was retrieved using the user's authorized JWT
268
+
269
+
Each agent lifecycle event is tagged with an `event_type` in the log message:
270
+
271
+
| Event Type | Description |
272
+
|------------|-------------|
273
+
|`request_authenticated`| User JWT validated, user_id and org_id extracted |
274
+
|`agent_run_started`| ADK agent invocation started |
0 commit comments