Version: 1.0.0Documentation Index
Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
Use this file to discover all available pages before exploring further.
Last Updated: 2025-01-07 This guide documents the secrets management strategy for the Encore Health OS Platform, covering development, staging, and production environments.
Table of Contents
- Overview
- Secrets Inventory
- Development Secrets
- Production Secrets
- Key Rotation Procedures
- Access Control
- Audit Logging
- Emergency Procedures
- Best Practices
- Troubleshooting
Overview
Secrets management is critical for security and compliance. This guide covers:- Where secrets are stored
- How to access secrets
- Key rotation procedures
- Access control policies
- Audit logging requirements
Secrets Inventory
Client-Side Secrets (Environment Variables)
Location:.env.local (development) or Vercel Environment Variables (production)
| Secret | Purpose | Client Access | Security Level |
|---|---|---|---|
VITE_SUPABASE_URL | Supabase project URL | ✅ Public | Low (public URL) |
VITE_SUPABASE_PUBLISHABLE_KEY | Supabase anon key | ✅ Public | Low (RLS enforced) |
VITE_* variables are exposed to the client bundle. Never put sensitive secrets in VITE_* variables.
Server-Side Secrets (Supabase Edge Functions)
Location: Supabase Secrets (set via CLI or Dashboard)| Secret | Purpose | Function | Security Level |
|---|---|---|---|
SUPABASE_SERVICE_ROLE_KEY | Bypass RLS (edge functions) | All functions | ⚠️ CRITICAL |
ENTRA_CLIENT_SECRET | Entra ID / Graph API (email) | Email provider (Entra) | High |
GMAIL_SERVICE_ACCOUNT_JSON | Gmail API (org-level email) | Email provider (Gmail) | High |
TWILIO_ACCOUNT_SID | SMS delivery | send-sms-notification | High |
TWILIO_AUTH_TOKEN | SMS delivery | send-sms-notification | ⚠️ CRITICAL |
TWILIO_PHONE_NUMBER | SMS sender number | send-sms-notification | Medium |
LOVABLE_API_KEY | AI Gateway access | ai-assistant, ai-document-analyze | High |
Testing Secrets (Development Only)
Location:.env.local (gitignored)
| Secret | Purpose | Usage | Security Level |
|---|---|---|---|
SUPABASE_SERVICE_ROLE_KEY | Test database access | RLS tests only | ⚠️ CRITICAL |
Development Secrets
Local Development Setup
1. Create.env.local file:
.gitignore:
Local Supabase Secrets
For Local Edge Functions:Production Secrets
Supabase Edge Function Secrets
Set via Supabase CLI:- Go to Project Settings → Edge Functions → Secrets
- Click Add Secret
- Enter key and value
- Click Save
Vercel Environment Variables
For Client Application:- Go to Vercel Dashboard → Project → Settings → Environment Variables
- Add variables:
VITE_SUPABASE_URL(Production)VITE_SUPABASE_PUBLISHABLE_KEY(Production)
- Do NOT add
SUPABASE_SERVICE_ROLE_KEY(never in client)
- Set variables per environment (Production, Preview, Development)
- Use Production values for production deployments
Key Rotation Procedures
Supabase Service Role Key
⚠️ CRITICAL: Service role key bypasses all RLS policies. Rotate immediately if compromised. Rotation Steps:-
Generate New Key:
- Go to Supabase Dashboard → Settings → API
- Click Reset service_role key
- Copy new key (save securely)
-
Update Edge Functions:
-
Update Test Environment:
- Update
.env.localwith new key - Verify tests still pass
- Update
-
Verify Functions Work:
- Test edge functions that use service role key
- Check function logs for errors
-
Revoke Old Key:
- Old key is automatically invalidated when reset
Entra Client Secret / Gmail Service Account
Entra: Rotate in Azure Portal (App registration → Certificates & secrets). UpdateENTRA_CLIENT_SECRET in Supabase secrets. Rotation frequency: Per Microsoft guidance (e.g. before expiry).
Gmail: Create a new service account key in Google Cloud Console, set GMAIL_SERVICE_ACCOUNT_JSON, then remove the old key. Rotation frequency: Every 180 days (or if compromised).
Twilio Credentials
Rotation Steps:-
Generate New Auth Token:
- Go to Twilio Console → Account → API Keys & Tokens
- Click Create new Auth Token
- Copy new token
-
Update Supabase Secrets:
-
Deploy Edge Function:
-
Test SMS Delivery:
- Send test SMS
- Verify delivery
-
Revoke Old Token:
- Delete old token in Twilio console
Supabase Anon Key
Rotation Steps:-
Generate New Key:
- Go to Supabase Dashboard → Settings → API
- Click Reset anon key
- Copy new key
-
Update Environment Variables:
- Vercel: Update
VITE_SUPABASE_PUBLISHABLE_KEY - Local: Update
.env.local
- Vercel: Update
-
Redeploy Application:
- Vercel will auto-deploy with new key
- Or manually trigger deployment
-
Verify Application Works:
- Test authentication
- Test database queries
- Check for errors
Access Control
Who Can Access Secrets?
Development Secrets (.env.local):
- Local developers only
- Never shared via chat/email
- Stored locally only
- Platform team members only
- Access via Supabase CLI (authenticated)
- Or Supabase Dashboard (with 2FA)
- Team members with project access
- Set via Vercel Dashboard
- Access logged in Vercel audit log
Access Policies
Principle of Least Privilege:- Only grant access to those who need it
- Use separate accounts for different environments
- Require 2FA for production access
- Review access quarterly
- Quarterly review of who has access
- Remove access for team members who left
- Document access in secure location (not in code)
Audit Logging
Secret Access Logging
Supabase:- Edge function invocations logged
- Secret access not directly logged (functions use secrets)
- Function execution logs available in dashboard
- Environment variable changes logged
- Access via Vercel audit log
- Review quarterly
What to Log
Secret Operations:- Secret creation
- Secret updates
- Secret deletion
- Key rotations
- Access attempts (if available)
- 90 days for secret operations
- 1 year for security incidents
- Permanent for key rotations
Monitoring
Set up alerts for:- Unusual secret access patterns
- Failed authentication attempts
- Secret rotation events
- Edge function errors (may indicate secret issues)
Emergency Procedures
Compromised Secret
If a secret is compromised:-
Immediately Rotate:
- Generate new secret
- Update in all locations
- Revoke old secret
-
Assess Impact:
- What data was accessible?
- When was secret compromised?
- Who had access?
-
Notify Team:
- Alert security team
- Document incident
- Update security procedures if needed
-
Monitor:
- Watch for unauthorized access
- Review audit logs
- Check for data breaches
Lost Secret
If a secret is lost:-
Regenerate:
- Create new secret
- Update all systems
- Test functionality
-
Document:
- Record when secret was lost
- Document recovery steps
- Update procedures if needed
Secret Rotation Failure
If rotation fails:-
Rollback:
- Revert to previous secret
- Verify system works
- Investigate failure
-
Fix Issue:
- Identify root cause
- Fix configuration
- Retry rotation
-
Document:
- Record failure and resolution
- Update procedures
- Add monitoring if needed
Best Practices
1. Secret Storage
✅ DO:- Store secrets in secure systems (Supabase Secrets, Vercel)
- Use
.env.localfor local development (gitignored) - Rotate secrets regularly
- Use different secrets per environment
- Commit secrets to version control
- Share secrets via chat/email
- Hardcode secrets in code
- Use same secrets across environments
2. Secret Access
✅ DO:- Use principle of least privilege
- Require 2FA for production access
- Review access quarterly
- Document who has access
- Grant access unnecessarily
- Share accounts
- Store secrets in plain text files
- Leave secrets in code comments
3. Secret Rotation
✅ DO:- Rotate secrets regularly (90-180 days)
- Rotate immediately if compromised
- Test rotation in staging first
- Document rotation procedures
- Skip rotation
- Rotate without testing
- Use same secret forever
- Forget to update all locations
4. Monitoring
✅ DO:- Monitor secret access (if available)
- Set up alerts for unusual activity
- Review audit logs regularly
- Track secret rotation dates
- Ignore security alerts
- Skip audit log reviews
- Forget to monitor
- Assume secrets are safe
Troubleshooting
Issue: Edge Function Can’t Access Secret
Symptoms:- Function fails with “not configured” error
- Function returns 500 error
- Verify secret is set:
- Check secret name matches exactly (case-sensitive)
- Redeploy function after setting secret:
- Check function logs in Supabase dashboard
Issue: Secret Not Found in Production
Symptoms:- Function works locally but fails in production
- “Environment variable not set” error
- Verify you’re linked to correct project:
- Set secret in production:
- Redeploy function to production
Issue: Service Role Key in Client Code
Symptoms:- Build warnings about service role key
- Security audit flags
- Remove
SUPABASE_SERVICE_ROLE_KEYfrom.env.local - Only use in test files:
tests/**/*.ts - Never import in client code:
src/**/*.tsx - Use
VITE_SUPABASE_PUBLISHABLE_KEYin client
Issue: Secret Rotation Broke Function
Symptoms:- Function fails after secret rotation
- Authentication errors
- Verify new secret is correct
- Check secret name matches exactly
- Redeploy function after rotation
- Test function with new secret
- Rollback if needed (revert to old secret)
Secret Management Checklist
Development Setup
-
.env.localcreated from.env.example -
.env.localin.gitignore - No secrets committed to version control
- Service role key only in test files
Production Setup
- All edge function secrets set in Supabase
- Vercel environment variables configured
- No service role key in client code
- Secrets rotated within last 90 days
- Access control reviewed
- 2FA enabled for production access
Ongoing Maintenance
- Quarterly secret rotation
- Quarterly access review
- Audit logs reviewed
- Monitoring alerts configured
- Emergency procedures documented
Related Documentation
- Environment Variables:
docs/development/ENVIRONMENT_VARIABLES.md - Supabase Setup:
docs/integrations/SUPABASE_SETUP.md - Edge Functions:
docs/integrations/EDGE_FUNCTIONS.md - Constitution:
constitution.md§4.1 (Security)
Document Owner: Platform Security Team
Review Frequency: Quarterly
Last Updated: 2025-01-07