Skip to content

Commit e8d891e

Browse files
author
Kelly Huntlin
committed
Allow user to provide a specific port and host for containerized environments that need SSO.
1 parent 9cae043 commit e8d891e

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,16 @@ declare module 'snowflake-sdk' {
436436
*/
437437
disableSamlUrlCheck?: boolean;
438438

439+
/**
440+
* Custom socket port to use for the local SAML server. Useful for SSO in containerized environments.
441+
*/
442+
localSamlServerPort?: boolean;
443+
444+
/**
445+
* Custom socket address to use for the local SAML server. Useful for SSO in containerized environments.
446+
*/
447+
localSamlServerHost?: boolean;
448+
439449
/**
440450
* The option to fetch all the null values in the columns as the string null.
441451
*/

lib/authentication/auth_web.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const { rest } = require('../global_config');
2424
function AuthWeb(connectionConfig, httpClient, webbrowser) {
2525

2626
const host = connectionConfig.host;
27+
const localServerPort = connectionConfig.getLocalSamlServerPort();
28+
const localServerHost = connectionConfig.getLocalSamlServerHost();
2729
const browserActionTimeout = connectionConfig.getBrowserActionTimeout();
2830
const ssoUrlProvider = new SsoUrlProvider(httpClient);
2931

@@ -75,8 +77,13 @@ function AuthWeb(connectionConfig, httpClient, webbrowser) {
7577
return result;
7678
});
7779

78-
// Use a free random port and set to no backlog
79-
server.listen(0, 0);
80+
// Preserving previous behavior. If user does not provide a custom port or address,
81+
// it will use a random port and fallback to localhost
82+
// https://github.com/nodejs/node/blob/main/lib/net.js#L1311
83+
server.listen({
84+
port: localServerPort,
85+
host: localServerHost,
86+
});
8087

8188
if (connectionConfig.getDisableConsoleLogin()) {
8289
// Step 1: query Snowflake to obtain SSO url

lib/connection/connection_config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const DEFAULT_PARAMS =
6363
'forceGCPUseDownscopedCredential',
6464
'representNullAsStringNull',
6565
'disableSamlURLCheck',
66+
'localSamlServerPort',
67+
'localSamlServerHost',
6668
'credentialCacheDir',
6769
'passcodeInPassword',
6870
'passcode',
@@ -480,6 +482,20 @@ function ConnectionConfig(options, validateCredentials, qaMode, clientInfo) {
480482
disableSamlURLCheck = options.disableSamlURLCheck;
481483
}
482484

485+
let localSamlServerPort = 0;
486+
if (Util.exists(options.localSamlPort)) {
487+
Errors.checkArgumentValid(Util.isNumber(options.localSamlPort),
488+
ErrorCodes.ERR_CONN_CREATE_INVALID_LOCAL_SAML_SERVER_PORT);
489+
localSamlServerPort = options.localSamlPort;
490+
}
491+
492+
let localSamlServerHost = 0;
493+
if (Util.exists(options.localSamlServerHost)) {
494+
Errors.checkArgumentValid(Util.isString(options.localSamlServerHost),
495+
ErrorCodes.ERR_CONN_CREATE_INVALID_LOCAL_SAML_SERVER_HOST);
496+
localSamlServerHost = options.localSamlServerHost;
497+
}
498+
483499
let clientStoreTemporaryCredential = false;
484500
if (Util.exists(options.clientStoreTemporaryCredential)) {
485501
Errors.checkArgumentValid(Util.isBoolean(options.clientStoreTemporaryCredential),
@@ -811,6 +827,14 @@ function ConnectionConfig(options, validateCredentials, qaMode, clientInfo) {
811827
return disableSamlURLCheck;
812828
};
813829

830+
this.getLocalSamlServerPort = function () {
831+
return localSamlServerPort;
832+
};
833+
834+
this.getLocalSamlServerHost = function () {
835+
return localSamlServerHost;
836+
};
837+
814838
this.getCredentialCacheDir = function () {
815839
return credentialCacheDir;
816840
};

lib/constants/error_messages.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ exports[404053] = 'A host must be specified.';
8484
exports[404054] = 'Invalid host. The specified value must be a string.';
8585
exports[404055] = 'Invalid passcodeInPassword. The specified value must be a boolean';
8686
exports[404056] = 'Invalid passcode. The specified value must be a string';
87+
exports[404057] = 'Invalid port number. The specified value must be a number.';
88+
exports[404058] = 'Invalid address. The specified value must be a string.';
8789

8890
// 405001
8991
exports[405001] = 'Invalid callback. The specified value must be a function.';

lib/errors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ codes.ERR_CONN_CREATE_MISSING_HOST = 404053;
8888
codes.ERR_CONN_CREATE_INVALID_HOST = 404054;
8989
codes.ERR_CONN_CREATE_INVALID_PASSCODE_IN_PASSWORD = 404055;
9090
codes.ERR_CONN_CREATE_INVALID_PASSCODE = 404056;
91+
codes.ERR_CONN_CREATE_INVALID_LOCAL_SAML_SERVER_PORT = 404057;
92+
codes.ERR_CONN_CREATE_INVALID_LOCAL_SAML_SERVER_HOST = 404058;
9193

9294
// 405001
9395
codes.ERR_CONN_CONNECT_INVALID_CALLBACK = 405001;

0 commit comments

Comments
 (0)