11import { PrismaClient } from '@prisma/client' ;
22import { PrismaPg } from '@prisma/adapter-pg' ;
33
4- import { RDS_CA_BUNDLE } from './rds-ca-bundle' ;
5-
64const globalForPrisma = global as unknown as { prisma ?: PrismaClient } ;
75
86const LOCAL_HOSTNAMES = new Set ( [ 'localhost' , '127.0.0.1' , '::1' ] ) ;
@@ -28,21 +26,24 @@ function createPrismaClient(): PrismaClient {
2826 const isLocalhost = isLocalhostUrl ( rawUrl ) ;
2927 const allowInsecure = process . env . PRISMA_ALLOW_INSECURE_TLS === '1' ;
3028
31- let ssl :
32- | undefined
33- | { ca : string ; checkServerIdentity : ( ) => undefined }
34- | { rejectUnauthorized : false } ;
35- if ( isLocalhost ) {
36- ssl = undefined ;
37- } else if ( allowInsecure ) {
38- ssl = { rejectUnauthorized : false } ;
39- } else {
40- // Verified TLS using the inlined AWS RDS CA bundle. Skip hostname check
41- // because connections may traverse an AWS NLB whose hostname isn't in the
42- // RDS Proxy cert's SAN list. The chain check still rejects forged or
43- // wrong-CA certs.
44- ssl = { ca : RDS_CA_BUNDLE , checkServerIdentity : ( ) => undefined } ;
45- }
29+ // Verified TLS via Node's default trust store, which includes Amazon Root
30+ // CA 1 — where AWS RDS Proxy chains terminate. Hostname check is skipped
31+ // because connections traverse an AWS NLB whose hostname isn't in the RDS
32+ // Proxy cert's SAN list; the chain check still rejects forged or wrong-CA
33+ // certs. PRISMA_ALLOW_INSECURE_TLS=1 is an explicit opt-out (no silent
34+ // fallback to unverified TLS).
35+ //
36+ // Previously this passed `ca: RDS_CA_BUNDLE` — but `ssl.ca` *replaces*
37+ // Node's trust store rather than augmenting it, and our bundle only
38+ // contains regional RDS CAs (not Amazon Root CA 1), so the RDS Proxy
39+ // chain failed to validate. Surfaced as P1011 TlsConnectionError /
40+ // "unable to get local issuer certificate" at runtime.
41+ const ssl : undefined | { checkServerIdentity : ( ) => undefined } | { rejectUnauthorized : false } =
42+ isLocalhost
43+ ? undefined
44+ : allowInsecure
45+ ? { rejectUnauthorized : false }
46+ : { checkServerIdentity : ( ) => undefined } ;
4647
4748 const url = ssl !== undefined ? stripSslMode ( rawUrl ) : rawUrl ;
4849 const adapter = new PrismaPg ( { connectionString : url , ssl } ) ;
0 commit comments