1
0
mirror of https://github.com/juanfont/headscale.git synced 2025-11-10 01:20:58 +01:00
juanfont.headscale/hscontrol/db
Kristoffer Dalby d49ae71a80
db: use partial unique index for pre_auth_keys.prefix
This commit fixes the UNIQUE constraint on the pre_auth_keys.prefix
column to allow multiple legacy keys (with NULL or empty prefix) while
still enforcing uniqueness for new bcrypt-based keys.

Changes:
- Modified migration to create partial unique index with WHERE clause
- Updated schema.sql to match migration
- Added comprehensive test (TestMultipleLegacyKeysAllowed) to verify:
  * Multiple legacy keys with empty prefix can coexist
  * New bcrypt keys have unique prefixes
  * Duplicate non-empty prefixes are rejected
- Fixed lint issues (errcheck, intrange)
- Fixed hardening: position-based parsing instead of separator-based
- Added validation for empty string, length, separator, and character set

The partial index uses:
  WHERE prefix IS NOT NULL AND prefix != ''

This allows unlimited legacy keys (backward compatibility) while
preventing duplicate prefixes for new keys (security).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 15:26:55 +01:00
..
sqliteconfig db: add sqlite "source of truth" schema 2025-07-07 15:48:38 +01:00
testdata db: ignore _litestream tables when validating (#2843) 2025-11-01 07:08:22 +00:00
api_key_test.go
api_key.go
db_test.go mapper: produce map before poll (#2628) 2025-07-28 11:15:53 +02:00
db.go db: use partial unique index for pre_auth_keys.prefix 2025-11-02 15:26:55 +01:00
ephemeral_garbage_collector_test.go db: add sqlite "source of truth" schema 2025-07-07 15:48:38 +01:00
ip_test.go types: make pre auth key use bcrypt 2025-11-02 15:26:54 +01:00
ip.go lint and leftover 2025-09-09 09:40:00 +02:00
node_test.go state: use AllApprovedRoutes instead of SubnetRoutes 2025-11-02 13:19:59 +01:00
node.go state: use AllApprovedRoutes instead of SubnetRoutes 2025-11-02 13:19:59 +01:00
policy.go
preauth_keys_test.go db: use partial unique index for pre_auth_keys.prefix 2025-11-02 15:26:55 +01:00
preauth_keys.go db: use partial unique index for pre_auth_keys.prefix 2025-11-02 15:26:55 +01:00
schema.sql db: use partial unique index for pre_auth_keys.prefix 2025-11-02 15:26:55 +01:00
suite_test.go types: make pre auth key use bcrypt 2025-11-02 15:26:54 +01:00
text_serialiser.go Refactor to use reflect.TypeFor 2025-08-23 20:43:49 +02:00
users_test.go db: use partial unique index for pre_auth_keys.prefix 2025-11-02 15:26:55 +01:00
users.go stricter hostname validation and replace (#2383) 2025-10-22 13:50:39 +02:00