Repository navigation
feat(broker): per-user credential-brokering audit records (spec 074 T10) - #694
Conversation
Emit a secret-free activity-log record on every per-user credential operation — acquisition, refresh, injection, and connect — carrying attribution (user id, server, request id), the acquisition method, and the outcome (success/failure + coarse reason). No token/refresh/secret value is ever recorded (FR-028, FR-029, SC-006; User Story 4 payoff). - broker.AuditEvent/AuditSink: a structurally secret-free audit port (no field can hold a credential) with a default no-op sink. - CredentialResolver.Resolve emits one classified event per resolution (acquire / refresh / inject / connect), threading the action out of the single-flight acquire so success and failure are attributed correctly. - OAuthConnector.Complete/Deny emit the connect-flow event; failure reasons are fixed coarse labels, never the raw upstream token-endpoint body. - storage.ActivityTypeCredentialBroker + an activity-log-backed AuditSink adapter (SaveActivityAsync, non-blocking) that reuses the existing activity log; wired into the live connect flow via NewCredentialHandlers. TDD: resolver/connector emit correct attribution on success and failure and never leak token material; the adapter persists records with no secret.
Deploying mcpproxy-docs with
|
| Latest commit: |
4e5bab6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://20d16e67.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-mcp-2858-coerce-oauth-ca.mcpproxy-docs.pages.dev |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 27738294419 --repo smart-mcp-proxy/mcpproxy-go
|
The raw OAuth AS error= query parameter is now passed through sanitizeCallbackError which maps known error codes to fixed labels and falls back to 'authorization_denied' for anything else. This prevents arbitrary upstream error text from reaching the audit log. Regression tests: - TestCredentialsCallback_DeniedByUpstream: known access_denied passes through the sanitizer unchanged in the audit record. - TestCredentialsCallback_Denied_UnknownErrorCoerced: arbitrary upstream error strings are coerced to 'authorization_denied'. Related MCP-2858
There was a problem hiding this comment.
APPROVE — Claude Code review (Spec 074 T10). Secret-free AuditEvent verified structurally (7 scalar fields, no token/map) + by tests; all 4 resolver lifecycle points + OAuth Complete/Deny audited via SaveActivityAsync; raw upstream body never reaches an audit record (fixed coarse labels, sanitizeCallbackError); go build -tags server + serveredition/storage tests pass; lint clean on changed files. Nits pre-existing. MCP-1043.
…s (MCP-1045) (#739) The T12 security review (Codex, request_changes) found two paths that leak authorization-server-controlled strings into logs and responses, violating the FR-029/SC-005 'no secret in logs/responses/audit' invariant: 1. The credential connect callback coerced the raw ?error= value only for the audit sink, but still logged it verbatim and reflected it into the browser redirect's credential_error param. Now the sanitized label is used on all three sinks (audit, log, redirect). 2. OAuthConnector.postToken returned the raw token-endpoint response body in its error, which is logged on the connect and refresh paths. A hostile/misconfigured AS could embed access/refresh tokens or echoed input there. postToken now surfaces only the HTTP status plus an allowlisted RFC 6749 §5.2 error code, mirroring the RFC 8693 exchanger's sanitizedError. Adds regression tests covering the redirect/log leak and the token-body leak. Related #694, Related MCP-1045
Spec 074 T10 — Audit integration: per-user brokering activity records
Closes the per-user attribution payoff (User Story 4). Emits a secret-free activity-log record on every per-user credential operation — acquisition, refresh, injection, connect — carrying attribution (user id, server, request id), the acquisition method (
token_exchange/entra_obo/connect), and the outcome (success/failure + a coarse reason). No token/refresh/secret value is ever recorded (FR-028, FR-029, SC-006).Design
broker.AuditEvent/broker.AuditSink(internal/serveredition/broker/audit.go): a structurally secret-free port — the event struct has no field able to hold a credential, so auditing cannot leak a secret. Default is a no-op sink.CredentialResolver.Resolveemits exactly one classified event per resolution. The action (acquire/refresh/injectcache-hit /connectnot-connected) is threaded out of the single-flightacquireso success and failure are attributed correctly. Exchanger errors are already sanitized upstream;NotConnectedError/PolicyDeniedError/sentinels are coarse and secret-free.OAuthConnector.Complete/Denyemit the connect-flow event (the connect completion path is REST-driven and never flows throughResolve). Failure reasons are fixed coarse labels, never the raw upstream token-endpoint body.Refreshstays unaudited at the connector — the resolver owns refresh auditing (no double-count).storage.ActivityTypeCredentialBroker+ an activity-log-backed adapter (api.NewActivityAuditSink) usingSaveActivityAsync(non-blocking on the request path). This reuses the existing activity log. Wired into the live connect flow viaNewCredentialHandlers→connectorProvider→NewOAuthConnector.Tests (TDD)
audit_resolver_test.go— cache-hit→inject, fresh→acquire, near-expiry→refresh, entra_obo method mapping, exchange-failure (reason, no secret), policy-denied→inject failure, not-connected→connect failure, store-disabled, anonymous (no event).audit_connector_test.go— connect Complete success/failure (coarse reason, no upstream body), invalid-state, Deny; asserts no upstream token / client secret in any event.broker_audit_test.go— adapter persists a realcredential_brokerrecord with attribution + request_id and no secret; nil-storage → nil sink.Verification
go build ./cmd/mcpproxy(personal) +go build -tags server ./cmd/mcpproxy✅go test -tags server ./internal/serveredition/... -race✅go test ./internal/storage/... ./internal/runtime/... -race -short✅golangci-lint v2.5.0 --config .github/.golangci.yml --new-from-rev=origin/main→ 0 issues ✅Docs
docs/features/activity-log.mdanddocs/cli/activity-commands.mdupdated with the newcredential_brokeractivity type.Related spec 074 (blockers MCP-1039/T6, MCP-1040/T7 merged in #691).