{"record":{"id":"3326408986e4d2ee","repo":"n8n-io/n8n","slug":"instance-owner-cannot-be-deleted","errorCode":null,"errorMessage":"Instance owner cannot be deleted.","messagePattern":"Instance owner cannot be deleted\\.","errorType":"exception","errorClass":"ForbiddenError","httpStatus":403,"severity":"error","filePath":"packages/cli/src/controllers/users.controller.ts","lineNumber":249,"sourceCode":"\t\t\t);\n\t\t\tthrow new BadRequestError('Cannot delete your own user');\n\t\t}\n\n\t\tconst { transferId } = req.query;\n\n\t\tconst userToDelete = await this.userRepository.findOne({\n\t\t\twhere: { id: idToDelete },\n\t\t\trelations: ['role'],\n\t\t});\n\n\t\tif (!userToDelete) {\n\t\t\tthrow new NotFoundError(\n\t\t\t\t'Request to delete a user failed because the user to delete was not found in DB',\n\t\t\t);\n\t\t}\n\n\t\tif (userToDelete.role.slug === GLOBAL_OWNER_ROLE.slug) {\n\t\t\tthrow new ForbiddenError('Instance owner cannot be deleted.');\n\t\t}\n\n\t\tconst personalProjectToDelete = await this.projectRepository.getPersonalProjectForUserOrFail(\n\t\t\tuserToDelete.id,\n\t\t);\n\n\t\tif (transferId === personalProjectToDelete.id) {\n\t\t\tthrow new BadRequestError(\n\t\t\t\t'Request to delete a user failed because the user to delete and the transferee are the same user',\n\t\t\t);\n\t\t}\n\n\t\tlet transfereeId;\n\t\tlet transfereeProject: Project | null = null;\n\n\t\tif (transferId) {\n\t\t\ttransfereeProject = await this.projectRepository.findOneBy({ id: transferId });\n","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/controllers/users.controller.ts#L231-L267","documentation":"Returned by DELETE /users/:id when the target user's role slug equals GLOBAL_OWNER_ROLE.slug. The instance owner is undeletable; this guard fires after the existence check and before the transferee logic. HTTP 403.","triggerScenarios":"An admin or owner attempts DELETE /users/<owner-id>; the target row's role.slug is the global owner slug.","commonSituations":"Bulk-delete script iterating all users including the owner; UI showing a delete action on the owner row; attempting to remove the original setup account.","solutions":["Never include the global owner in deletion targets.","Transfer ownership to another user first via the documented ownership-transfer flow if you need to retire the current owner.","Filter the owner out of bulk operations by role.slug."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function excludeOwnerFromDeletes(users: Array<{id:string;roleSlug:string}>) {\n  return users.filter((u) => u.roleSlug !== 'global:owner').map((u) => u.id);\n}","typeGuard":"const isOwnerRole = (slug: string) => slug === 'global:owner';","tryCatchPattern":null,"preventionTips":["Never include the global owner in deletion targets.","Use ownership-transfer flow to retire the current owner.","Filter by role.slug before any bulk delete."],"tags":["users","delete","rbac","forbidden","owner","authorization"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}