mirror of
https://github.com/juanfont/headscale.git
synced 2026-03-18 20:23:37 +09:00
Some checks failed
Build / build-nix (push) Has been cancelled
Build / build-cross (GOARCH=amd64 GOOS=darwin) (push) Has been cancelled
Build / build-cross (GOARCH=amd64 GOOS=linux) (push) Has been cancelled
Build / build-cross (GOARCH=arm64 GOOS=darwin) (push) Has been cancelled
Build / build-cross (GOARCH=arm64 GOOS=linux) (push) Has been cancelled
Check Generated Files / check-generated (push) Has been cancelled
NixOS Module Tests / nix-module-check (push) Has been cancelled
Tests / test (push) Has been cancelled
Close inactive issues / close-issues (push) Has been cancelled
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.