Skip to content

Commit 9c052dc

Browse files
committed
parametrize service principal and host
1 parent 93f30ed commit 9c052dc

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/pg/lib/client.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var Query = require('./query')
1010
var defaults = require('./defaults')
1111
var Connection = require('./connection')
1212
const crypto = require('./crypto/utils')
13+
const kerberos = require('kerberos').Kerberos
1314

1415
class Client extends EventEmitter {
1516
constructor(config) {
@@ -20,6 +21,7 @@ class Client extends EventEmitter {
2021
this.database = this.connectionParameters.database
2122
this.port = this.connectionParameters.port
2223
this.host = this.connectionParameters.host
24+
this.principal = this.connectionParameters.principal
2325

2426
// "hiding" the password so it doesn't show up in stack traces
2527
// or if the client is console.logged
@@ -204,8 +206,7 @@ class Client extends EventEmitter {
204206

205207
async _handleGSSInit(msg) {
206208
try {
207-
// TODO: Below needs to be parameterized
208-
this.client = await kerberos.initializeClient('[email protected]', {
209+
this.client = await kerberos.initializeClient(`${this.principal}@${this.host}`, {
209210
mechOID: kerberos.GSS_MECH_OID_SPNEGO,
210211
})
211212

@@ -226,7 +227,7 @@ class Client extends EventEmitter {
226227

227228
// TODO: probably a better way to handle this.
228229
if (token == null) {
229-
return
230+
this.emit('error', 'Received null GSSAPI token on continue')
230231
}
231232
const buf = Buffer.from(token, 'base64')
232233
this.connection.sendBinaryPassword(buf)

packages/pg/lib/connection-parameters.js

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class ConnectionParameters {
6565

6666
this.port = parseInt(val('port', config), 10)
6767
this.host = val('host', config)
68+
// Kerberos/GSSAPI service principal
69+
this.principal = val('principal', config)
6870

6971
// "hiding" the password so it doesn't show up in stack traces
7072
// or if the client is console.logged

0 commit comments

Comments
 (0)