Snowflake NodeJS Driver
repository·master·Indexed 41 days ago
https://github.com/snowflakedb/snowflake-connector-nodejsThe official Node.js driver (snowflake-sdk v3.3.0) for interacting with Snowflake accounts. It enables developers to execute queries, manage data, and configure connections using various authentication methods including SNOWFLAKE, EXTERNALBROWSER, SNOWFLAKE_JWT, and OAUTH. Features include CRL validation, AWS Workload Identity authentication, and configurable client logging via sf_client_config.json.
What's inside Snowflake
- Minicore is an experimental telemetry core for the Snowflake NodeJS driver written in Rust. It is implemented as a native Node.js addon using napi-rs to bridge Rust code with the Node.js runtime.
Verify the snowflake-sdk package signature
masterStarting from version v1.13.0, the driver package is signed to allow verification of its authenticity and integrity.
To verify a package:
- Install
cosign. - Download the driver package file (
.tgz) from npmjs.org. - Download the corresponding signatures file (
.sigand.pub) from the Snowflake releases page. - Use
cosign verify-blobto validate the package against the public key and signature.
cosign verify-blob snowflake-sdk-1.13.0.tgz --key snowflake-connector-nodejs-v1.13.0.pub --signature resources.snowflake-sdk-1.13.0.tgz.sig- Install
Install the snowflake-sdk package
masterTo use the Snowflake NodeJS driver in your project, install the
snowflake-sdkpackage via npm.npm i snowflake-sdkAccess Snowflake NodeJS Driver documentation
masterFor detailed documentation, API references, and basic usage examples, refer to the official Snowflake documentation: NodeJS Driver for Snowflake.Use CRLValidatorConfig checkMode options
masterThe
checkModeproperty determines the enforcement level of CRL validation:'DISABLED': CRL validation is turned off.'ENABLED': CRL validation is strictly enforced. If a certificate is revoked or validation fails, the connection is terminated.'ADVISORY': CRL validation is attempted. If validation fails (e.g., due to network issues or invalid signatures), a warning is logged but the connection is allowed to proceed.
Locate the client configuration file
masterThe driver searches for the
sf_client_config.jsonfile using the following priority order:- Connection String: If a path is explicitly provided within the connection string.
- Environment Variable: The
SF_CLIENT_CONFIG_FILEenvironment variable. - Default Directories:
- The driver's installation directory.
- The user's home directory.
If no configuration is found through these methods, the driver proceeds without custom client configuration.
Configure Workload Identity authentication
masterThe
WORKLOAD_IDENTITYauthenticator allows the driver to automatically retrieve credentials from cloud environments (AWS, Azure, or GCP).To use it, set
authenticator: 'WORKLOAD_IDENTITY'and specify theworkloadIdentityProvider:AWS: Uses@aws-sdk. SupportsGetCallerIdentity(default) orGetWebIdentityToken(set viaworkloadIdentityAwsUseOutboundToken: true).AZURE: Uses@azure/identity.GCP: Usesgoogle-auth-library.OIDC: Reads the JWT token from thetokenoption.
Advanced AWS Configuration:
workloadIdentityAwsUseOutboundToken: Set totrueto use the recommendedGetWebIdentityTokenmethod (requiressts:GetWebIdentityTokenpermission).workloadIdentityHost: Overrides the AWS STS host (e.g.,sts.sc2s.sgov.gov).
const workloadIdentityOptions = { authenticator: 'WORKLOAD_IDENTITY', workloadIdentityProvider: 'AWS', workloadIdentityAwsUseOutboundToken: true };Configure a custom workloadIdentityHost
masterIf you are working in an AWS environment with a non-standard partition or require a specific STS endpoint, you can provide a
workloadIdentityHost.When a
workloadIdentityHostis provided:- It is parsed into an
StsEndpoint. - The driver uses the provided
baseUrlfor all STS requests. - Note: When using a custom host, AWS FIPS and Dualstack endpoint preferences (
AWS_USE_FIPS_ENDPOINTorAWS_USE_DUALSTACK_ENDPOINT) are ignored because the driver must use the exact endpoint you specified.
- It is parsed into an
Configure client logging via `sf_client_config.json`
masterThe Snowflake NodeJS driver supports a client configuration file named
sf_client_config.jsonto manage logging settings. This file allows you to set a global log level and a specific log path for the driver's operations.The configuration must follow a specific JSON structure where settings are placed under a
commonkey.Supported Log Levels
Level Value Description Off OFFDisables logging Error ERRORLogs only errors Warn WARNLogs warnings and errors Info INFOLogs informational messages Debug DEBUGLogs detailed debug information Trace TRACELogs highly detailed trace information Configuration File Example
{ "common": { "log_level": "DEBUG", "log_path": "/path/to/your/snowflake_driver.log" } }Configure OAuth authentication
masterFor OAuth flows, the driver requires specific parameters depending on the flow type.
Common OAuth options:
oauthClientId: The client ID from your identity provider.oauthClientSecret: The client secret from your identity provider.oauthScope: Space-separated list of requested scopes.oauthRedirectUri: Custom URI for redirection (used withOAUTH_AUTHORIZATION_CODE). Defaults tohttp://127.0.0.1:{randomAvailablePort}.oauthEnableSingleUseRefreshTokens: Enables single-use refresh tokens.
Customizing the Browser Experience: When using
EXTERNALBROWSERorOAUTH_AUTHORIZATION_CODE, you can customize the landing page shown to the user after sign-in usingbrowserResponseRenderer:browserResponseRenderer: ({ error }) => { const message = error ? `<h1>Login failed</h1><p>${error}</p>` : '<h1>All set! You can close this tab.</h1>'; return `<html><body>${message}</body></html>`; }Manage authentication token caching
masterYou can enable MFA/SSO token caching to improve performance and user experience by setting
clientStoreTemporaryCredential: true.When enabled, the driver stores tokens in a directory specified by
credentialCacheDir. IfcredentialCacheDiris not provided, the driver searches in this order:- The
SF_TEMPORARY_CREDENTIAL_CACHE_DIRenvironment variable. - Platform-specific defaults:
- Windows:
<home>/AppData/Local/Snowflake/Caches - Linux:
$XDG_CACHE_HOME/snowflakeor~/.cache/snowflake - macOS:
~/Library/Caches/Snowflake
- Windows:
- The
Configure CRL validation settings
masterThe
CRLValidatorConfigtype defines how Certificate Revocation List (CRL) validation behaves within the driver. Use these options to control strictness and caching behavior.type CRLValidatorConfig = { checkMode: 'DISABLED' | 'ENABLED' | 'ADVISORY'; allowCertificatesWithoutCrlURL: boolean; inMemoryCache: boolean; onDiskCache: boolean; };