{"record":{"id":"184d93f14fe6dac3","repo":"JuliusBrussee/caveman","slug":"postgres-runtime-current-user-q-differs-from-ses","errorCode":null,"errorMessage":"postgres: runtime current_user %q differs from session_user %q","messagePattern":"postgres: runtime current_user %q differs from session_user %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/postgresconfig/postgresconfig.go","lineNumber":176,"sourceCode":"\t\t         WHERE n.nspname='public'\n\t\t           AND c.relkind IN ('r','p')\n\t\t           AND pg_get_userbyid(c.relowner)=current_user\n\t\t       )\n\t\tFROM pg_roles r\n\t\tWHERE r.rolname=current_user\n\t`, expectedRole).Scan(&currentUser, &sessionUser, &superuser, &bypassRLS, &member, &ownsTenantTable)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"postgres: inspect runtime identity: %w\", err)\n\t}\n\treturn validateRuntimeIdentity(currentUser, sessionUser, expectedRole, superuser, bypassRLS, member, ownsTenantTable)\n}\n\nfunc validateRuntimeIdentity(currentUser, sessionUser, expectedRole string, superuser, bypassRLS, member, ownsTenantTable bool) error {\n\t// A safe SET ROLE is not a safe login: session_user may execute SET ROLE\n\t// NONE later and recover its original privileges. Runtime pools therefore\n\t// require the authenticated identity and effective identity to be identical.\n\tif currentUser != sessionUser {\n\t\treturn fmt.Errorf(\"postgres: runtime current_user %q differs from session_user %q\", currentUser, sessionUser)\n\t}\n\tif superuser || bypassRLS || ownsTenantTable {\n\t\treturn fmt.Errorf(\"postgres: unsafe runtime identity %q (session_user=%q superuser=%t bypassrls=%t owns_tenant_table=%t)\", currentUser, sessionUser, superuser, bypassRLS, ownsTenantTable)\n\t}\n\tif !member {\n\t\treturn fmt.Errorf(\"postgres: runtime identity %q is not a member of %q\", currentUser, expectedRole)\n\t}\n\treturn nil\n}\n\ntype tenantTableSchema struct {\n\tname                   string\n\tnullableOrganizationID bool\n\trowSecurity            bool\n\tforceRowSecurity       bool\n\tpolicyExists           bool\n\tpolicyPermissive       bool\n\tpolicyCommand          string","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/shared/platform/postgresconfig/postgresconfig.go#L158-L194","documentation":"Error \"postgres: runtime current_user %q differs from session_user %q\" thrown in JuliusBrussee/caveman.","triggerScenarios":"Thrown at shared/platform/postgresconfig/postgresconfig.go:176 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Connect with a role whose current_user matches session_user (no SET ROLE)."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}