Unify credential tables and incident actor columns #38

Open
opened 2026-10-09 12:42:38 +00:00 by niklas · 0 comments
Owner

Deferred from the Oct 2026 design review (schema is a single baseline now, so this is cheap before first release).

Credentials

api_keys, service_account_keys, integrations.key_hash, sessions, incident_ack_tokens, invites, device_logins, oidc_logins each carry their own hash/lookup/expiry code (apiKeyUser, serviceAccountFor, sourceForKey, randomToken, randomServiceAccountToken). Only api_keys has expires_at. Consider one credentials(kind, principal_id, key_hash, expires_at, last_used_at) table and one resolver.

Actors

Incident actors are bolted on as parallel columns: incidents.acknowledged_by + acknowledged_by_service_account_id; incident_events has user_id, service_account_id, actor_user_id, actor_service_account_id with two XOR constraints, and user_id means the actor for most events but the assignee for assigned. Consider a principals supertype or actor_kind + actor_id plus a separate subject_user_id. Related: #36 (assignable service accounts).

Also while in the schema

  • service_accounts.name is globally UNIQUE; make it (team_id, name) (a 409 currently reveals other teams' account names).
  • Authorization predicates are spread over AdminOnly, requireSelfOrAdmin, requireTeamOwner, callerOwnsTeam, callerMayManageServiceAccount, handleCreateTeam's inline check: one authorize(caller, action, resource) policy file, with an audit event for admin overrides.
  • Four code paths create users and six insert team_members: one createUser and one addMember.
Deferred from the Oct 2026 design review (schema is a single baseline now, so this is cheap before first release). ## Credentials `api_keys`, `service_account_keys`, `integrations.key_hash`, `sessions`, `incident_ack_tokens`, `invites`, `device_logins`, `oidc_logins` each carry their own hash/lookup/expiry code (`apiKeyUser`, `serviceAccountFor`, `sourceForKey`, `randomToken`, `randomServiceAccountToken`). Only `api_keys` has `expires_at`. Consider one `credentials(kind, principal_id, key_hash, expires_at, last_used_at)` table and one resolver. ## Actors Incident actors are bolted on as parallel columns: `incidents.acknowledged_by` + `acknowledged_by_service_account_id`; `incident_events` has `user_id`, `service_account_id`, `actor_user_id`, `actor_service_account_id` with two XOR constraints, and `user_id` means the actor for most events but the assignee for `assigned`. Consider a `principals` supertype or `actor_kind` + `actor_id` plus a separate `subject_user_id`. Related: #36 (assignable service accounts). ## Also while in the schema - `service_accounts.name` is globally UNIQUE; make it `(team_id, name)` (a 409 currently reveals other teams' account names). - Authorization predicates are spread over `AdminOnly`, `requireSelfOrAdmin`, `requireTeamOwner`, `callerOwnsTeam`, `callerMayManageServiceAccount`, `handleCreateTeam`'s inline check: one `authorize(caller, action, resource)` policy file, with an audit event for admin overrides. - Four code paths create users and six insert `team_members`: one `createUser` and one `addMember`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: niklas/terdut-server#38