[Bug] Can not delete user #1167

Closed
opened 2025-12-29 02:28:41 +01:00 by adam · 3 comments
Owner

Originally created by @IamTaoChen on GitHub (Dec 2, 2025).

Is this a support request?

  • This is not a support request

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

➜  scripts/headscale users delete -i 3
Do you want to remove the user "derper" (3) and any associated preauthkeys? [y/n] y
Cannot destroy user: constraint failed: FOREIGN KEY constraint failed (787)
➜ scripts/headscale nodes list -u derper
ID | Hostname | Name | MachineKey | NodeKey | User | IP addresses | Ephemeral | Last seen | Expiration | Connected | Expired

➜ scripts/headscale preauthkeys list -u 3
ID | Key    | Reusable | Ephemeral | Used  | Expiration          | Created             | Tags
4  | xxxxxx | true     | false     | true  | 2025-12-02 06:45:56 | 2024-05-11 20:32:02 |     
7  | xxxxxx | true     | false     | true  | 2024-06-30 10:08:00 | 2024-06-18 09:08:23 |     
8  | xxxxxx | true     | false     | false | 2025-12-02 06:46:38 | 2024-06-18 17:45:14 |     
10 | xxxxxx | true     | false     | true  | 2024-07-31 10:48:00 | 2024-07-11 09:48:57 |     
19 | xxxxxx | false    | false     | false | 2024-11-03 01:59:06 | 2024-11-03 01:58:30 |     
26 | xxxxxx | false    | false     | true  | 2025-05-11 16:04:23 | 2025-02-10 17:04:23 |     
38 | xxxxxx | false    | false     | true  | 2025-05-18 09:05:08 | 2025-05-18 08:05:08 |     

I aready delete other user, but faild with derper

Expected Behavior

can delete unused user

Steps To Reproduce

just delete a user

Environment

- OS: Debian13
- Headscale version: 0.27.1
- Tailscale version: 1.90.6

Runtime environment

  • Headscale is behind a (reverse) proxy
  • Headscale runs in a container

Debug information

None

Originally created by @IamTaoChen on GitHub (Dec 2, 2025). ### Is this a support request? - [x] This is not a support request ### Is there an existing issue for this? - [x] I have searched the existing issues ### Current Behavior ```bash ➜ scripts/headscale users delete -i 3 Do you want to remove the user "derper" (3) and any associated preauthkeys? [y/n] y Cannot destroy user: constraint failed: FOREIGN KEY constraint failed (787) ➜ scripts/headscale nodes list -u derper ID | Hostname | Name | MachineKey | NodeKey | User | IP addresses | Ephemeral | Last seen | Expiration | Connected | Expired ➜ scripts/headscale preauthkeys list -u 3 ID | Key | Reusable | Ephemeral | Used | Expiration | Created | Tags 4 | xxxxxx | true | false | true | 2025-12-02 06:45:56 | 2024-05-11 20:32:02 | 7 | xxxxxx | true | false | true | 2024-06-30 10:08:00 | 2024-06-18 09:08:23 | 8 | xxxxxx | true | false | false | 2025-12-02 06:46:38 | 2024-06-18 17:45:14 | 10 | xxxxxx | true | false | true | 2024-07-31 10:48:00 | 2024-07-11 09:48:57 | 19 | xxxxxx | false | false | false | 2024-11-03 01:59:06 | 2024-11-03 01:58:30 | 26 | xxxxxx | false | false | true | 2025-05-11 16:04:23 | 2025-02-10 17:04:23 | 38 | xxxxxx | false | false | true | 2025-05-18 09:05:08 | 2025-05-18 08:05:08 | ``` I aready delete other user, but faild with `derper` ### Expected Behavior can delete unused user ### Steps To Reproduce just delete a user ### Environment ```markdown - OS: Debian13 - Headscale version: 0.27.1 - Tailscale version: 1.90.6 ``` ### Runtime environment - [x] Headscale is behind a (reverse) proxy - [x] Headscale runs in a container ### Debug information None
adam added the bugdatabase labels 2025-12-29 02:28:41 +01:00
adam closed this issue 2025-12-29 02:28:41 +01:00
Author
Owner

@nblock commented on GitHub (Dec 2, 2025):

Can you send us a dump of your database, please? E-Mail address available in the git commits / profile data.

@nblock commented on GitHub (Dec 2, 2025): Can you send us a dump of your database, please? E-Mail address available in the git commits / profile data.
Author
Owner

@IamTaoChen commented on GitHub (Dec 2, 2025):

Can you send us a dump of your database, please? E-Mail address available in the git commits / profile data.

Already sent it to you.

@IamTaoChen commented on GitHub (Dec 2, 2025): > Can you send us a dump of your database, please? E-Mail address available in the git commits / profile data. Already sent it to you.
Author
Owner

@nblock commented on GitHub (Dec 6, 2025):

This turned out to be a bug with the (now removed headscale nodes move):

  • Several preauthkeys were generated for the user derper
  • Nodes got registered with those preauthkeys
  • Nodes got moved from user derper to other users
  • Deletion of user derper failed with a FK-constraint violation because the preauthkeys were not moved over to the new users

For anyone hitting the same issue with a similar description: Either remove all nodes that use non-migrated preauthkeys
or reassign ownership in the pre_auth_keys table manually (be sure to keep a backup of the database) and delete the
user afterwards:

SELECT id FROM pre_auth_keys where user_id=ID_OF_USER_TO_DELETE;
UPDATE pre_auth_keys SET user_id=ID_OF_NEW_USER where id=ID_FROM_ABOVE;
@nblock commented on GitHub (Dec 6, 2025): This turned out to be a bug with the (now removed `headscale nodes move`): - Several preauthkeys were generated for the user `derper` - Nodes got registered with those preauthkeys - Nodes got moved from user `derper` to other users - Deletion of user `derper` failed with a FK-constraint violation because the preauthkeys were not moved over to the new users For anyone hitting the same issue with a similar description: Either remove all nodes that use non-migrated preauthkeys *or* reassign ownership in the `pre_auth_keys` table manually (be sure to keep a backup of the database) and delete the user afterwards: ```sql SELECT id FROM pre_auth_keys where user_id=ID_OF_USER_TO_DELETE; UPDATE pre_auth_keys SET user_id=ID_OF_NEW_USER where id=ID_FROM_ABOVE; ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#1167