Supabase SSL Configuration
Overview
This guide covers how to configure SSL connections to Supabase databases in the MOOD MNKY ecosystem. Secure connections are essential for protecting sensitive data and are required for production environments.SSL Certificate Management
Certificate Storage
SSL certificates for Supabase are stored in the repository at:.gitignore to prevent accidental commit of actual certificate files. The directory structure is maintained in git, but certificate files (.crt, .key, .pem) must be distributed through secure channels.
Production Certificate Setup
-
Download the SSL certificate from your Supabase dashboard:
- Navigate to Project Settings > Database
- Under “SSL Connection”, click “Download CA Certificate”
-
Save the certificate to
infra/certs/supabase/production.crt -
Update your production environment variables to reference the certificate:
-
You can use the provided script to update your
.env.productionfile:
Client Configuration
TypeScript Client Configuration
The shared Supabase client inpackages/supabase-client should be configured to use SSL in production environments. The client automatically detects the environment and configures SSL appropriately.
Environment-Specific Configuration
Different environments may have different SSL requirements:- Development: Local development typically doesn’t require SSL
- Staging: May use the same certificate as production or a separate one
- Production: Always requires SSL with valid certificates
Verifying SSL Connection
To verify that SSL is correctly configured, you can check the connection status:SSL Configuration on Supabase
Enforcing SSL Connections
In the Supabase dashboard:- Navigate to Project Settings > Database
- Enable “Enforce SSL Connection”
- Check “Reject non-SSL connections to your database”
Database URL with SSL Parameters
When connecting directly to the Postgres database (not through the Supabase client), use a connection string with SSL parameters:Deployment Configuration
Vercel Deployment
For Vercel deployments:-
Add the SSL certificate as an environment variable or secret:
- Convert the certificate to a base64 string:
- Add the base64 content as
SUPABASE_SSL_CERT_BASE64in Vercel environment variables
- Convert the certificate to a base64 string:
-
Modify the client to use the base64 certificate:
Docker Deployment
For Docker deployments:- Include the certificate in your Docker image or mount it as a volume
- Configure the container environment to point to the certificate location
Certificate Rotation
SSL certificates typically have an expiration date. To rotate certificates:- Download the new certificate from Supabase
- Replace the existing certificate file
- Deploy the updated certificate to all environments
- Verify connections work correctly with the new certificate
Troubleshooting
Common SSL Connection Issues
- Certificate not found: Verify the path in
SUPABASE_DB_SSL_CERT_PATHis correct - Invalid certificate: Ensure you’re using the correct certificate for your environment
- SSL mode conflicts: Check that the connection string uses the correct SSL mode