Issue
I writing an API using nodejs and express. My database got hacked and I decided to use the Digital Ocean Managed Database. Digital Ocean Managed database requires SSL and they ONLY provide you with one CA certificate. In all the tutorials out there, SSL requires 3 files. I didn't find any tutorial on how to connect node-pg with only one file. I finally found the solution and I want to share it with the community. Hopefully, I save someone a few hours of digging.
Solution
The certificate that the Digital Ocean provides you is a Root Certificate NOT Client Certificate. In node-pg cert
is referring to the client certificate and CA
refers to the root certificate. CA
option is the one that should be used, not Cert
.
- CA: root.crt (For Incoming messages; Digital Ocean gives you this one)
- Key: postgresql.key (You don't need it)
- Cert: Client Certificate (You don't need it)
const config = {
database: 'database-name',
host: 'host-or-ip',
user: 'username',
password: 'password',
port: 1234,
// this object will be passed to the TLSSocket constructor
ssl: {
ca: fs.readFileSync('/path/to/digitalOcean/certificate.crt').toString()
}
}
If this answer was useful to you give a thumbs up so other people can find it as well.
Answered By - Soli Technology LLC Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.