feat(keys): API keys — mint/list/rotate/revoke (task 8.2, SDK-03) #100
No reviewers
Labels
No labels
epic
phase-0
phase-1
phase-2
phase-3
phase-4
phase-5
phase-6
phase-7
phase-8
phase-9
priority/P0
priority/P1
priority/P2
type/backend
type/client
type/docs
type/ops
type/security
type/spike
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/failsulit!100
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/1.5-api-keys"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
First PR of the M1.5 M2M early slice (dev plan v1.6 §5.5).
SDK-03 — API keys
ApiKeyentity (api_keys + migration): tenant-scoped,sdid_-prefixed secret with only its SHA-256 stored, prefix for identification, space-separated Drive-side scopes (SDK-04 set, validated at mint), optional expiry, last-used tracking, immediate revocationPOST /api/keys/api-keys— mint, 201 + secret shown onceGET /api/keys/api-keys— prefix + metadata; secret/hash never in payloadPOST /api/keys/api-keys/{id}/rotate— new secret once; old valid 24 h graceDELETE /api/keys/api-keys/{id}— immediate revoke; grace hashes clearedApiKeyAuthentication.ValidateAsync— acceptance core (revoked/expired/grace rules + LastUsedAt stamp) for the 8.3/api/m2m/*auth middlewareVerification
TDD: 8 tests first (mint-once/hash-only, member-403, unknown-scope-400, list-no-secrets, rotate-grace, revoke-immediate, expiry-reject). Suite 888 / 0 / 39 (Release ×2) · gate 85.12% ≥ 80
ApiKey entity (api_keys): tenant-scoped, name, KeyPrefix (identification), SecretHash only (SHA-256 hex — raw secret shown exactly once at mint/rotate), PreviousSecretHash + PreviousExpiresAt (24 h rotation grace), space-separated Drive-side scopes (SDK-04 known set validated at mint), optional ExpiresAt, LastUsedAt (set on acceptance), RevokedAt (immediate). Endpoints under /api/keys/api-keys (Owner/Admin only, tenant-scoped): - POST / mint — 201 + secret ONCE; validates name ≤200, scopes against the SDK-04 known set, future expiry - GET / list — prefix + metadata; raw secret and hash never in payload - POST /{id}/rotate — new secret ONCE; old hash retained with 24 h grace - DELETE /{id} — immediate revoke; grace hashes cleared (no grace after revoke); revoked keys vanish from the default list ApiKeyAuthentication.ValidateAsync — SDK-03 acceptance core (rules: not revoked, not expired, current hash always, previous hash only within grace; stamps LastUsedAt). Wired for the 8.3 /api/m2m/* authentication middleware; tests exercise it directly. Authz-matrix rows added for the four routes (RouteClass.Account — Owner/Admin enforced in-handler). Expiry-rejection test backdates via DB (the endpoint correctly refuses past expiry at mint). TDD: 8 tests first — RED (routes 404 pre-registration, bounds missing). Suite 888 / 0 failed / 39 skipped (Release ×2); gate 85.12% ≥ 80.