feat(apikeys): service API keys with channel and role scope (#13) #118
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/kws!118
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/13-service-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?
What
Service API keys (#13):
Authorization: Bearer kws_…for machine callers. A key is a serviceusersrow plus a platform-scope membership holding one existing custom role, so every guard, the audit actor andcreated_bywork unchanged. Secret = 32 random bytes, stored only as SHA-256, shown once. Each key has a channel (website,mobile,usher,agent,tour_portal), an optional expiry and a revoked state.administration.manage):POST|GET /v1/admin/api-keys,DELETE /v1/admin/api-keys/{id}. Create is not replayable (sameIdempotency-Key= 409already_created) so the secret is never stored inidempotency_keys.api_keys(audit withsecret_hashandlast_used_atexcluded) and widenstransactions.channelto includetour_portal. ADR 0027, CLAUDE.md section, OpenAPI (tagApiKeys), live contract test.Verification
make cover: 91.2% (minimum 80%), run on the final code commit.make lint0 issues,make contractok,go test -race -count=1 ./...ok,scripts/generate-clients.shok./v1/mebuying routes), both fixed in one wave; scoped re-review APPROVE, Ponytail Must fix none.Rulings made without you (owner to check, all marked [verify] in ADR 0027)
/v1/me(403): a reports-only key must not buy tickets.GET /v1/meand/v1/me/accessstay open.Kioskdeferred. The 0032downfails iftour_portalsales exist, and leaves the service users behind.administration.managecan mint keys that outlive its revocation.last_used_atis written on the request path at most once a minute per key.api/.golangci.yml: G117 forinternal/apikeys/handler.goonly (the create response carries the secret by design).Not verified
kws_tokens costs one indexed query each (per-IP rate limiting is #62).Closes nothing; #13 stays open until you close it.
🤖 Generated with Claude Code
POST/GET /v1/admin/api-keys and DELETE /v1/admin/api-keys/{id}, platform scope only with admin_portal.administration.manage. Create calls idempotency Runner.Run directly: the record keeps the key without its secret, the 201 shows the secret once and a repeated Idempotency-Key is 409 already_created. The creator must hold every permission of the role; organization, unknown and Super Admin roles are 422. Revoke evicts the key from this node's verifier and invalidates the authorizer. Store.Create now runs inside the caller's transaction; idempotency exposes WriteError (Handle's error mapping). The verifier no longer re-caches a key evicted during an in-flight lookup, and Touch ignores a client disconnect. Report and spec channel filters accept tour_portal. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>