|
| 1 | +rules: |
| 2 | + - metadata: |
| 3 | + kind: prequel |
| 4 | + id: SB3DbConn3ct11nT1m31ut |
| 5 | + gen: 1 |
| 6 | + cre: |
| 7 | + id: CRE-2025-0132 |
| 8 | + severity: 2 |
| 9 | + title: "Supabase Self-Hosted: Database Connection Timeout and Service Failure" |
| 10 | + category: "database-problem" |
| 11 | + author: Prequel |
| 12 | + description: | |
| 13 | + Detects when Supabase services lose connection to the PostgreSQL database due to timeouts, network issues, |
| 14 | + or database unavailability. This affects Auth, REST API, Storage, and all database-dependent operations. |
| 15 | + Occurs during database restarts, network partitions, or when database becomes unresponsive. |
| 16 | + cause: | |
| 17 | + - PostgreSQL database container stopped or crashed |
| 18 | + - Network connectivity issues between services and database |
| 19 | + - Database server overloaded and not responding to connections |
| 20 | + - Database connection pool exhaustion |
| 21 | + - Firewall rules blocking database access |
| 22 | + - DNS resolution failures for database hostname |
| 23 | + tags: |
| 24 | + - supabase |
| 25 | + - postgres |
| 26 | + - connection |
| 27 | + - timeout |
| 28 | + - network |
| 29 | + - self-hosted |
| 30 | + - connectivity |
| 31 | + - public |
| 32 | + mitigation: | |
| 33 | + IMMEDIATE: |
| 34 | + - Check database container status: `docker-compose ps db` |
| 35 | + - Restart database service: `docker-compose restart db` |
| 36 | + - Verify database connectivity: `docker-compose exec db pg_isready -U postgres` |
| 37 | + INVESTIGATION: |
| 38 | + - Check database logs: `docker-compose logs db` |
| 39 | + - Monitor connection pool: Check for connection limit errors |
| 40 | + - Verify network connectivity between containers |
| 41 | + PREVENTION: |
| 42 | + - Implement database health checks with proper timeouts |
| 43 | + - Configure connection pooling limits appropriately |
| 44 | + - Set up database monitoring and alerting |
| 45 | + - Use connection retry logic with exponential backoff |
| 46 | + references: |
| 47 | + - https://www.postgresql.org/docs/current/runtime-config-connection.html |
| 48 | + - https://supabase.com/docs/guides/platform/troubleshooting |
| 49 | + applications: |
| 50 | + - name: gotrue |
| 51 | + containerName: supabase-auth |
| 52 | + - name: postgrest |
| 53 | + containerName: supabase-rest |
| 54 | + - name: storage-api |
| 55 | + containerName: supabase-storage |
| 56 | + - name: realtime |
| 57 | + containerName: supabase-realtime |
| 58 | + impact: | |
| 59 | + - API requests fail with database connection errors |
| 60 | + - User authentication becomes unavailable |
| 61 | + - File storage operations fail |
| 62 | + - Real-time subscriptions disconnect |
| 63 | + - Application becomes unusable until database connectivity is restored |
| 64 | + impactScore: 8 |
| 65 | + mitigationScore: 5 |
| 66 | + reports: 30 |
| 67 | + rule: |
| 68 | + set: |
| 69 | + window: 5m |
| 70 | + event: |
| 71 | + source: cre.log.supabase |
| 72 | + match: |
| 73 | + - regex: 'connection.*refused.*5432|timeout.*database|dial tcp.*5432.*connection refused' |
| 74 | + - regex: 'failed to connect to.*postgres|database connection.*timeout|connection reset by peer' |
| 75 | + - regex: 'could not connect to server|server closed the connection|connection timed out' |
| 76 | + - value: "database" |
| 77 | + |
| 78 | + |
0 commit comments