The current code I have set up works fine, but it is not secure.
const { Pool } = require('pg')
const pgPool = new Pool({
user: process.env.PGUSER,
password: process.env.PGPASSWORD,
host: process.env.PGHOST,
database: process.env.PGDATABASE,
port: process.env.PGPORT,
ssl: {
rejectUnauthorized: false
},
})
What I would like the ssl object to look like is this.
ssl: {
rejectUnauthorized: true,
ca: process.env.CACERT,
},
Unfortunately I am having trouble figuring out how to put make the certificate available to my app.I would prefer not to commit the certificate to my source control…
Thanks, Peter
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $100 of credit to try our products over 60 days!
Hi there @peterjf2,
You would need to pass the CA certificate to your application as an environment variable.
You can refer to the
CA_CERT
variable which holds the CA certificate for the Managed databases.For more information on how to use the environment variables on the App platform, I could suggest taking a look at the official documentation here:
https://www.digitalocean.com/docs/app-platform/how-to/use-environment-variables/
Hope that this helps. Regards, Bobby
Okay, for anyone else who gets stuck on this, I had to put the entire cert into double quotes and add a \n after each line.
So now my database connection code looks like
with the CA_CERT env for dotenv and my App Platform looks like:
I go a little bit more into detail in my stack overflow question here: Example link
I do not think it is possible to do this with the $7 development database as I was unable to find a CA_cert anywhere to download. Would probably just have to leave the unauthorized portion as false.