-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Secure Credential Management System #45
Copy link
Copy link
Open
Labels
backendbugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or requestsecurityui/ux
Description
Overview
Build a secure system for storing and managing API keys, OAuth tokens, and other credentials used by plugins.
Context
Related to PR #40 - Plugins need secure credential storage with encryption.
Implementation Steps
1. Database Schema
Update prisma/schema.prisma:
model Credential {
id String @id @default(cuid())
userId String
name String
type String // 'api-key', 'oauth2', 'custom'
pluginName String
// Encrypted credential data
encryptedData String @db.Text
// OAuth2 specific
accessToken String? @db.Text
refreshToken String? @db.Text
expiresAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId, pluginName])
}2. Credential Manager
Create src/lib/plugin-system/credential-manager.ts:
saveCredential(): Encrypt and store credentialsgetCredential(): Decrypt and return credentialsrefreshOAuth2Token(): Auto-refresh expired OAuth tokensdeleteCredential(): Securely delete credentialslistUserCredentials(): List credentials for a user
3. Encryption Implementation
- Use AES-256-GCM for encryption
- Store encryption key in environment variable:
CREDENTIAL_ENCRYPTION_KEY - IV (Initialization Vector) generated per credential
- Auth tag for integrity verification
4. OAuth2 Flow
Create src/app/api/auth/oauth/callback/route.ts:
- Handle OAuth callback
- Exchange code for tokens
- Store encrypted tokens
- Redirect back to plugin configuration
5. Credential UI
Create src/components/credentials/:
credential-selector.tsx: Select existing credential or create newcredential-form.tsx: Form for API key / custom authoauth-button.tsx: Button to initiate OAuth flowcredential-list.tsx: Manage user's credentials
6. Security Measures
- Never log decrypted credentials
- Use secure HTTP-only cookies for OAuth state
- Implement CSRF protection
- Rate limiting on credential endpoints
- Audit log for credential access
Acceptance Criteria
- Prisma schema updated and migration created
- Encryption/decryption functions work correctly
- OAuth2 flow tested with Google (example)
- Token refresh works automatically
- Credentials UI components functional
- No credentials exposed in logs or errors
- Security audit passed
- Documentation written
Security Checklist
- Encryption key is 32 bytes (256 bits)
- New IV generated for each encryption
- Auth tags verified on decryption
- OAuth state parameter used (CSRF)
- Credentials never sent to frontend (only IDs)
Dependencies
- Issue feat: tRPC Initalized #1 (Plugin System Foundation)
Estimated Effort
- Large (10-12 hours)
Backlink: #40
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
backendbugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or requestsecurityui/ux