headscale/hscontrol/state
Kristoffer Dalby 46daa659e2 state: omit AuthKeyID/AuthKey in node Updates to prevent FK errors
When a PreAuthKey is deleted, the database correctly sets auth_key_id
to NULL on referencing nodes via ON DELETE SET NULL. However, the
NodeStore (in-memory cache) retains the old AuthKeyID value.

When nodes send MapRequests (e.g., after tailscaled restart), GORM's
Updates() tries to persist the stale AuthKeyID, causing a foreign key
constraint error when trying to reference a deleted PreAuthKey.

Fix this by adding AuthKeyID and AuthKey to the Omit() call in all
three places where nodes are updated via GORM's Updates():
- persistNodeToDB (MapRequest processing)
- HandleNodeFromAuthPath (re-auth via web/OIDC)
- HandleNodeFromPreAuthKey (re-registration with preauth key)

This tells GORM to never touch the auth_key_id column or AuthKey
association during node updates, letting the database handle the
foreign key relationship correctly.

Added TestDeletedPreAuthKeyNotRecreatedOnNodeUpdate to verify that
deleted PreAuthKeys are not recreated when nodes send MapRequests.
2026-01-26 12:12:11 +00:00
..
debug.go db: use PolicyManager for RequestTags migration 2026-01-21 15:10:29 +01:00
debug_test.go hscontrol/state: make NodeStore batch configuration tunable (#2886) 2025-11-28 16:38:29 +01:00
endpoint_test.go hscontrol/state: make NodeStore batch configuration tunable (#2886) 2025-11-28 16:38:29 +01:00
ephemeral_test.go hscontrol/state: make NodeStore batch configuration tunable (#2886) 2025-11-28 16:38:29 +01:00
maprequest.go stability and race conditions in auth and node store (#2781) 2025-10-16 12:17:43 +02:00
maprequest_test.go make tags first class node owner (#2885) 2025-12-02 12:01:25 +01:00
node_store.go cli: ensure tagged-devices is included in profile list (#2991) 2026-01-09 16:31:23 +01:00
node_store_test.go policy: more accurate node change 2025-12-16 10:12:36 +01:00
state.go state: omit AuthKeyID/AuthKey in node Updates to prevent FK errors 2026-01-26 12:12:11 +00:00
tags.go Conversion from personal to tagged node is reversible 2026-01-24 17:18:59 +01:00
test_helpers.go hscontrol/state: make NodeStore batch configuration tunable (#2886) 2025-11-28 16:38:29 +01:00