Step 1 of ADR 0001 (tenant-bound, scoped API keys; Werkmeister
prerequisite 1, firmwerk#64 step 1):
- internal/scopes: catalogue <product>:<resource>.<action>, validated
on create against the tenant's entitlements (422 not_entitled);
GET /v1/api-keys/scopes for the portal's picker.
- Migration 0015: kind (user|ci|integration), holder, expires_at,
hash_sha256. New keys are stored as sha256 (indexed lookup); older
keys keep argon2id and every prefix candidate is checked, so a
prefix collision no longer breaks a valid key.
- Verify returns key_id, kind, holder, expires_at, tenant_status and
legacy, and limits scopes to products booked right now. Expired
keys are invalid. Empty scopes stay a legacy full grant.
- ci keys need scopes and an expiry within 365 days; integration keys
are refused here (created by their holder product, next step).
- DELETE /v1/api-keys/{id}?tenant_id= refuses another tenant's key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
14 lines
525 B
SQL
14 lines
525 B
SQL
-- Keys created with only a sha256 hash cannot be represented before 0015;
|
|
-- rolling back drops them (they stop working either way).
|
|
DELETE FROM api_keys WHERE hash IS NULL;
|
|
DROP INDEX IF EXISTS api_keys_hash_sha256_idx;
|
|
ALTER TABLE api_keys
|
|
DROP CONSTRAINT IF EXISTS api_keys_holder_kind,
|
|
DROP CONSTRAINT IF EXISTS api_keys_hash_present;
|
|
ALTER TABLE api_keys ALTER COLUMN hash SET NOT NULL;
|
|
ALTER TABLE api_keys
|
|
DROP COLUMN hash_sha256,
|
|
DROP COLUMN expires_at,
|
|
DROP COLUMN holder,
|
|
DROP COLUMN kind;
|