{"record":{"id":"53a6799074f0accf","repo":"JuliusBrussee/caveman","slug":"postgres-unsafe-runtime-identity-q-session-user","errorCode":null,"errorMessage":"postgres: unsafe runtime identity %q (session_user=%q superuser=%t bypassrls=%t owns_tenant_table=%t)","messagePattern":"postgres: unsafe runtime identity %q \\(session_user=%q superuser=%t bypassrls=%t owns_tenant_table=%t\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/postgresconfig/postgresconfig.go","lineNumber":179,"sourceCode":"\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\n\tpolicyAppliesToPublic  bool\n\tpolicyUsingExpression  string\n\tpolicyCheckExpression  string","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/shared/platform/postgresconfig/postgresconfig.go#L161-L197","documentation":"Error \"postgres: unsafe runtime identity %q (session_user=%q superuser=%t bypassrls=%t owns_tenant_table=%t)\" thrown in JuliusBrussee/caveman.","triggerScenarios":"Thrown at shared/platform/postgresconfig/postgresconfig.go:179 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a non-superuser, non-BYPASSRLS runtime role that does not own the tenant table."],"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"}