logger.CloneContext rebuilds a fresh context.Background() and only copies a hand-curated allow-list of context keys (LoggerContextKey, TenantIDContextKey, UserContextKey, etc.) before passing it to downstream handlers — the chat / agent QA pipelines all do `ctx := logger.CloneContext(c.Request.Context())` at the top of parseQARequest. TenantRoleContextKey was missing from that allow-list. Any call site that read the role via TenantRoleFromContext(reqCtx.ctx) saw the type-zero TenantRole and the helper's least-privilege fallback returned Viewer. The auth middleware had set role=Owner correctly on the parent context, but the cloned context lost it. Symptom: an Owner of their home tenant got 403 on POST /agent-chat when the agent had runnable_by_viewer=false, because the gate at session/qa.go:520 saw role=viewer despite middleware logging role=owner two ms earlier. Diagnostic log lines added in the previous commits (auth.go:145 "[auth] resolved role=...", auth.go:283 "[auth] resolveTenantRole step1 hit row_role=...") made this immediately visible — a request showed role=owner at the middleware layer and role=viewer at the handler layer, which can only mean ctx propagation lost it. Keeping the diagnostic logs in place so similar regressions surface fast. Fix is one line: add TenantRoleContextKey to the CloneContext allow-list, with a comment pinning it to the bug it fixes so a future drive-by removal has to weigh that loss. |
||
|---|---|---|
| .. | ||
| asynqdl | ||
| access.go | ||
| access_test.go | ||
| audit_provider.go | ||
| auth.go | ||
| auth_role_test.go | ||
| error_handler.go | ||
| language.go | ||
| logger.go | ||
| logger_test.go | ||
| rbac.go | ||
| rbac_audit_test.go | ||
| rbac_test.go | ||
| recovery.go | ||
| trace.go | ||