1

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.

1 Answer 1

9

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.

  1. CA: root.crt (For Incoming messages; Digital Ocean gives you this one)
  2. Key: postgresql.key (You don't need it)
  3. 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.