Admin Guide
Last updated: 2025-09-19
Overview
Section titled “Overview”This secure notes application is designed with end-to-end encryption where each user manages their own encrypted workspace. This guide explains how to manage users, configure admin access, and maintain the system while respecting the zero-knowledge architecture.
Current System Architecture
Section titled “Current System Architecture”The application uses:
- Zero-knowledge encryption: Server never sees plaintext data
- User workspaces: Each user has their own encrypted workspace
- Note-level permissions: Users can share notes with
read
,write
, oradmin
permissions - PostgreSQL database: User data stored in encrypted format
Admin Access Setup
Section titled “Admin Access Setup”Grant Admin Access (Development)
Section titled “Grant Admin Access (Development)”-
Get your user ID (UUID):
- Log in, then open browser DevTools → Application → Local Storage → find
current_user_id
- Or decode the JWT stored in
secure_token
:JSON.parse(atob(localStorage.getItem('secure_token').split('.')[1])).user_id
- Log in, then open browser DevTools → Application → Local Storage → find
-
Add to environment variables:
- Add your UUID to
.env
:ADMIN_USER_IDS=<your-uuid-here>
- Multiple admins:
ADMIN_USER_IDS=<uuid-1>,<uuid-2>
- Add your UUID to
-
Restart the application:
Terminal window make down && make up
Database Admin Management
Section titled “Database Admin Management”Add Admin Column (One-time Setup)
Section titled “Add Admin Column (One-time Setup)”-- Connect to PostgreSQL databasepsql -U postgres -d notes
-- Add admin role columnALTER TABLE users ADD COLUMN is_admin BOOLEAN DEFAULT false;
-- Create index for faster admin queriesCREATE INDEX idx_users_is_admin ON users(is_admin);
Make User Admin
Section titled “Make User Admin”-- Grant admin access by emailUPDATE usersSET is_admin = trueWHERE email = 'admin@example.com';
-- Or by user IDUPDATE usersSET is_admin = trueWHERE id = 'your-user-uuid-here';
Remove Admin Access
Section titled “Remove Admin Access”-- Revoke admin accessUPDATE usersSET is_admin = falseWHERE email = 'user@example.com';
Admin Panel Usage
Section titled “Admin Panel Usage”Enable Admin Panel
Section titled “Enable Admin Panel”- In builds: Set
VITE_ENABLE_ADMIN_PANEL=true
for the frontend - Local development:
Terminal window export VITE_ENABLE_ADMIN_PANEL=true && docker compose up -d --build
Using the Admin Panel
Section titled “Using the Admin Panel”- Log in as an admin user
- Click the shield icon in the app header
- The Admin Panel allows you to:
- Toggle user’s built-in
is_admin
flag - Assign or remove RBAC roles (
moderator
,auditor
) - Load current roles for users
- Enable/disable user registration
- Toggle user’s built-in
Admin Settings
Section titled “Admin Settings”Database User Management
Section titled “Database User Management”View All Users
Section titled “View All Users”-- List all users with basic infoSELECT id, email, COALESCE(is_admin, false) as is_admin, created_at, last_login, failed_attemptsFROM usersORDER BY created_at DESC;
Find Admin Users
Section titled “Find Admin Users”-- List all admin usersSELECT id, email, created_at, last_loginFROM usersWHERE is_admin = true;
User Activity Monitoring
Section titled “User Activity Monitoring”-- Find inactive users (haven't logged in recently)SELECT id, email, created_at, last_login, (NOW() - last_login) as inactive_periodFROM usersWHERE last_login < NOW() - INTERVAL '30 days' OR last_login IS NULL;
Account Security Management
Section titled “Account Security Management”-- Check users with too many failed attemptsSELECT id, email, failed_attempts, locked_untilFROM usersWHERE failed_attempts > 5;
-- Unlock a locked user accountUPDATE usersSET failed_attempts = 0, locked_until = NULLWHERE email = 'user@example.com';
User Statistics
Section titled “User Statistics”-- Count total usersSELECT COUNT(*) as total_users FROM users;
-- Count active users (logged in last 30 days)SELECT COUNT(*) as active_usersFROM usersWHERE last_login > NOW() - INTERVAL '30 days';
-- Count notes per userSELECT u.email, COUNT(n.id) as note_countFROM users uLEFT JOIN workspaces w ON u.id = w.owner_idLEFT JOIN notes n ON w.id = n.workspace_idWHERE n.deleted_at IS NULLGROUP BY u.id, u.emailORDER BY note_count DESC;
Security Considerations
Section titled “Security Considerations”Zero-Knowledge Limitations
Section titled “Zero-Knowledge Limitations”Recommended Admin Capabilities
Section titled “Recommended Admin Capabilities”Safe admin operations that preserve encryption:
- ✅ View user list and metadata
- ✅ Monitor login attempts and security events
- ✅ Disable/enable user accounts
- ✅ View system statistics and usage
- ✅ Manage system-wide settings
- ❌ Read user notes or content
- ❌ Reset passwords without user involvement
Database Administration
Section titled “Database Administration”Database Connection
Section titled “Database Connection”# Using PostgreSQL command lineexport PGPASSWORD="your-postgres-password"psql -h localhost -U postgres -d notes
# Or connect via URL# postgresql://postgres:password@localhost:5432/notes
Backup User Data
Section titled “Backup User Data”Before making changes, always backup:
# Backup users tablepg_dump -h localhost -U postgres -d notes -t users > users_backup.sql
# Full database backuppg_dump -h localhost -U postgres -d notes > full_backup.sql
Common Admin Tasks
Section titled “Common Admin Tasks”Creating the First Admin
Section titled “Creating the First Admin”-- After first user registers, make them adminUPDATE usersSET is_admin = trueWHERE email = ( SELECT email FROM users ORDER BY created_at ASC LIMIT 1);
Emergency Account Recovery
Section titled “Emergency Account Recovery”-- If admin is locked out, unlock manuallyUPDATE usersSET failed_attempts = 0, locked_until = NULLWHERE is_admin = true;
System Maintenance
Section titled “System Maintenance”-- Clean up old deleted notes (after 30 days)DELETE FROM notesWHERE deleted_at IS NOT NULL AND deleted_at < NOW() - INTERVAL '30 days';
Monitoring and Logging
Section titled “Monitoring and Logging”For production admin management:
- Enable PostgreSQL logging for audit trails
- Monitor authentication failures for security
- Set up alerts for suspicious activity
- Regular backups of user data
Security Notes
Section titled “Security Notes”Contact
Section titled “Contact”For admin-related questions, contact contact@leaflock.app
.