{"record":{"id":"4fe0ba9e0efa647b","repo":"netbirdio/netbird","slug":"self-deletion-is-not-allowed","errorCode":null,"errorMessage":"self deletion is not allowed","messagePattern":"self deletion is not allowed","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"management/server/user.go","lineNumber":1271,"sourceCode":"func (am *DefaultAccountManager) DeleteRegularUsers(ctx context.Context, accountID, initiatorUserID string, targetUserIDs []string, userInfos map[string]*types.UserInfo) error {\n\tallowed, ctx, err := am.permissionsManager.ValidateUserPermissions(ctx, accountID, initiatorUserID, modules.Users, operations.Delete)\n\tif err != nil {\n\t\treturn status.NewPermissionValidationError(err)\n\t}\n\tif !allowed {\n\t\treturn status.NewPermissionDeniedError()\n\t}\n\n\tinitiatorUser, err := am.Store.GetUserByUserID(ctx, store.LockingStrengthNone, initiatorUserID)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar allErrors error\n\n\tfor _, targetUserID := range targetUserIDs {\n\t\tif initiatorUserID == targetUserID {\n\t\t\tallErrors = errors.Join(allErrors, errors.New(\"self deletion is not allowed\"))\n\t\t\tcontinue\n\t\t}\n\n\t\ttargetUser, err := am.Store.GetUserByUserID(ctx, store.LockingStrengthNone, targetUserID)\n\t\tif err != nil {\n\t\t\tallErrors = errors.Join(allErrors, err)\n\t\t\tcontinue\n\t\t}\n\n\t\tif targetUser.Role == types.UserRoleOwner {\n\t\t\tallErrors = errors.Join(allErrors, fmt.Errorf(\"unable to delete a user: %s with owner role\", targetUserID))\n\t\t\tcontinue\n\t\t}\n\n\t\t// disable deleting integration user if the initiator is not admin service user\n\t\tif targetUser.Issued == types.UserIssuedIntegration && !initiatorUser.IsServiceUser {\n\t\t\tallErrors = errors.Join(allErrors, errors.New(\"only integration service user can delete this user\"))\n\t\t\tcontinue","sourceCodeStart":1253,"sourceCodeEnd":1289,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/management/server/user.go#L1253-L1289","documentation":"Returned in AccountManager.DeleteUsers (management/server/user.go:1271): while iterating over the target user IDs, an initiator may not delete the account they authenticate as. The check compares targetUserID with initiatorUserID and joins this error into the aggregate result instead of aborting the whole batch.","triggerScenarios":"Calling the delete-users API/handler with the caller's own user ID in the targetUserIDs list, e.g. an admin picking themselves in a bulk delete, or a script that passes \"all users\" including the current one.","commonSituations":"Dashboard bulk-select that includes the logged-in admin; cleanup scripts that enumerate every user of the account; inviting user to select themselves accidentally.","solutions":["Remove the initiating user's own ID from the target list before calling DeleteUsers","Have another owner/admin perform the deletion if the goal really is to delete that account"],"exampleFix":"// before\nallUsers := listAccountUserIDs(accountID) // includes current admin\ndeleteUsers(ctx, accountID, adminID, allUsers)\n\n// after\ntargets := filterOut(allUsers, adminID) // never delete self\ndeleteUsers(ctx, accountID, adminID, targets)","handlingStrategy":"validation","validationCode":"func excludeSelf(targets []string, initiator string) []string {\n    out := targets[:0]\n    for _, t := range targets {\n        if t != initiator { out = append(out, t) }\n    }\n    return out\n}\n\ntargets = excludeSelf(targets, initiatorUserID)","typeGuard":null,"tryCatchPattern":"err := am.DeleteUsers(ctx, accountID, initiatorID, targets)\nif err != nil && strings.Contains(err.Error(), \"self deletion is not allowed\") {\n    // remove the initiator's ID from targets and retry the remaining batch\n}","preventionTips":["Filter the caller's own ID out of bulk delete lists at the UI/API-client layer","Require explicit confirmation for destructive bulk operations","For account teardown, transfer ownership first and use dedicated deprovisioning flows"],"tags":["management","users","api","permissions","validation"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}