Skip to content

Allow users to pass certs when PG environment variable PGSSLMODE=require/verify-ca/verify-full #2517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 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,15 @@ var readSSLConfigFromEnvironment = function () {
case 'disable':
return false
case 'prefer':
return true
case 'require':
case 'verify-ca':
case 'verify-full':
return true
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,
}
case 'no-verify':
return { rejectUnauthorized: false }
}
Expand Down
10 changes: 3 additions & 7 deletions packages/pg/test/integration/connection-pool/tls-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ const suite = new helper.Suite()

if (process.env.PG_CLIENT_CERT_TEST) {
suite.testAsync('client certificate', async () => {
const pool = new pg.Pool({
ssl: {
ca: fs.readFileSync(process.env.PGSSLROOTCERT),
cert: fs.readFileSync(process.env.PGSSLCERT),
key: fs.readFileSync(process.env.PGSSLKEY),
},
})
// PGSSLROOTCERT, PGSSLCERT, and PGSSLKEY are all set as environment
// variables in .travis.yml
const pool = new pg.Pool()

await pool.query('SELECT 1')
await pool.end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ testVal('', false)
testVal('disable', false)
testVal('allow', false)
testVal('prefer', true)
testVal('require', true)
testVal('verify-ca', true)
testVal('verify-full', true)
testVal('require', { ca: undefined, cert: undefined, key: undefined })
testVal('verify-ca', { ca: undefined, cert: undefined, key: undefined })
testVal('verify-full', { ca: undefined, cert: undefined, key: undefined })
testVal('no-verify', { rejectUnauthorized: false })

// restore process.env
Expand Down