Skip to content

Commit

Permalink
Require users to pass certs when PG environment variable PGSSLMODE is…
Browse files Browse the repository at this point in the history
… specified

and is either require, verify-ca or verify-full.
  • Loading branch information
RichardJCai committed Apr 9, 2021
1 parent 6121bd3 commit 29e0be5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/pg/lib/connection-parameters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

var dns = require('dns')
var fs = require('fs')

var defaults = require('./defaults')

Expand All @@ -23,10 +24,20 @@ var readSSLConfigFromEnvironment = function () {
case 'disable':
return false
case 'prefer':
return true
case 'require':
case 'verify-ca':
case 'verify-full':
return true
if (process.env.PGSSLROOTCERT && process.env.PGSSLKEY && process.env.PGSSLCERT) {
return {
ca: process.env.PGSSLROOTCERT ? fs.readFileSync(process.env.PGSSLROOTCERT).toString() : undefined,
key: process.env.PGSSLKEY ? fs.readFileSync(process.env.PGSSLKEY).toString() : undefined,
cert: process.env.PGSSLCERT ? fs.readFileSync(process.env.PGSSLCERT).toString() : undefined,
}
} else {
console.error(`PG Environment Variables PGSSLROOTCERT, PGSSLKEY and PGSSLCERT must be specified when PGSSLMODE=${process.env.PGSSLMODE} is specified`)
process.exit(-1)
}
case 'no-verify':
return { rejectUnauthorized: false }
}
Expand Down

0 comments on commit 29e0be5

Please sign in to comment.