Create UserCredential Prisma model with RLS policies #355

Closed
opened 2026-02-07 17:11:43 +00:00 by jason.woltje · 0 comments
Owner

Phase 3a - User Credential Storage

Problem

There is no database model for users to store their own API keys, git tokens, or OAuth tokens for integrations. Users need a secure, RLS-protected table to manage personal and workspace-scoped credentials.

Requirements

  1. Create UserCredential Prisma model with encrypted value storage
  2. Add CredentialType enum (API_KEY, OAUTH_TOKEN, ACCESS_TOKEN, SECRET, PASSWORD, CUSTOM)
  3. Add CredentialScope enum (USER, WORKSPACE, SYSTEM)
  4. Add RLS policies: USER-scoped visible only to owner, WORKSPACE-scoped visible to workspace admins, SYSTEM-scoped via admin bypass
  5. Extend EntityType enum with CREDENTIAL
  6. Extend ActivityAction enum with CREDENTIAL_CREATED, CREDENTIAL_ACCESSED, CREDENTIAL_ROTATED, CREDENTIAL_REVOKED
  7. Add relations to User and Workspace models

Model Design

UserCredential fields:

  • id (UUID)
  • userId (FK to User)
  • workspaceId (optional FK to Workspace)
  • name (display name, e.g. GitHub
## Phase 3a - User Credential Storage ### Problem There is no database model for users to store their own API keys, git tokens, or OAuth tokens for integrations. Users need a secure, RLS-protected table to manage personal and workspace-scoped credentials. ### Requirements 1. Create UserCredential Prisma model with encrypted value storage 2. Add CredentialType enum (API_KEY, OAUTH_TOKEN, ACCESS_TOKEN, SECRET, PASSWORD, CUSTOM) 3. Add CredentialScope enum (USER, WORKSPACE, SYSTEM) 4. Add RLS policies: USER-scoped visible only to owner, WORKSPACE-scoped visible to workspace admins, SYSTEM-scoped via admin bypass 5. Extend EntityType enum with CREDENTIAL 6. Extend ActivityAction enum with CREDENTIAL_CREATED, CREDENTIAL_ACCESSED, CREDENTIAL_ROTATED, CREDENTIAL_REVOKED 7. Add relations to User and Workspace models ### Model Design UserCredential fields: - id (UUID) - userId (FK to User) - workspaceId (optional FK to Workspace) - name (display name, e.g. GitHub
jason.woltje added this to the M9-CredentialSecurity (0.0.9) milestone 2026-02-07 17:11:43 +00:00
jason.woltje added the databasesecuritydatabasep1 labels 2026-02-07 17:11:43 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaic/stack#355