fix(orgtoken): capture WorkOS user_id in created_by for session-minted tokens #3014
Reference in New Issue
Block a user
Delete Branch "fix/orgtoken-session-userid"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes KI-004 item 5 (WorkOS user_id provenance for session-minted org API tokens).
VerifiedCPSessionalready parseduser_idfrom/cp/auth/tenant-member; this change threads it through the session cache and Gin context soorgTokenActorcan recordsession:<user_id>ascreated_byinstead of an opaque session hash.Changes
internal/middleware/session_auth.go:VerifiedCPSessionnow returns(valid, presented, userID);sessionCachestores the userID.internal/middleware/wsauth_middleware.go:AdminAuthandWorkspaceAuthsetcp_session_user_id.internal/handlers/discovery.go: updated caller to the new triple return.internal/handlers/org_tokens.go:orgTokenActorpreferscp_session_user_idfor session callers.Test plan
go test ./internal/middleware ./internal/handlers -count=1passes locally.cp_session_user_idis set and used in org-token INSERT.SOP checklist
comprehensive-testing): unit tests added/updated; middleware + handlers test suites passlocal-postgres-e2e): N/A — pure handler/middleware change, no DB surface beyond existing pathstaging-smoke): N/A — no runtime deploy path touchedroot-cause): Closes KI-004 item 5 (WorkOS user_id provenance gap)five-axis-review): reviewedno-backwards-compat): no shim; existing session hash actor remains, created_by enrichedmemory-consulted): N/A — aligned with existing actor/session patterns5-axis review on head
27c35f32: APPROVED. Correctness: WorkOSuser_idis already returned by the trusted tenant-member verification call, is cached with the session result, set on AdminAuth/WorkspaceAuth contexts, andorgTokenActornow recordssession:<user_id>with fallback to the existing session actor. Robustness: invalid/transport failure paths keep empty userID and existing auth semantics. Security: improves audit provenance without granting privileges or exposing raw cookies. Performance: no extra CP round trip due cache threading. Readability/tests are clear. Visible status includes review/SOP gates and one E2E failure, but the reviewed code path is sound.APPROVED after independent 5-axis review.
Correctness:
VerifiedCPSessionnow returns the WorkOSuser_id, caches it with the verified result, middleware stores it ascp_session_user_id, and org-token creation recordssession:<user_id>while retaining the previous fallback. Robustness: negative/transport handling and cache expiry behavior remain intact; tests cover middleware propagation and token provenance. Security: this improves audit attribution without exposing raw cookies. Performance: no extra CP round trip is introduced because the existing tenant-member response is reused and cached. Readability: call sites were updated coherently; I only noticed a stale tuple-shape comment in discovery, not a blocker./sop-ack comprehensive-testing
/sop-ack local-postgres-e2e
/sop-ack staging-smoke
/sop-ack root-cause
/sop-ack five-axis-review
/sop-ack no-backwards-compat
/sop-ack memory-consulted