fix(drivers): read every Snowflake private-key format

Merged
HK
12h ago
+273-27

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The local Snowflake driver's key-pair handling only decrypted keys when a passphrase was set or the text contained "ENCRYPTED", and only normalized literal \n. PEMs whose line breaks became spaces, encrypted PKCS#8 keys without a passphrase, and legacy encrypted PKCS#1 keys (Proc-Type/DEK-Info) failed with raw OpenSSL errors such as 1E08010C:DECODER routines::unsupported.

The key handling now lives in packages/drivers/src/snowflake-key.ts: it strips surrounding quotes, converts literal \n, CRLF and space-separated bodies back to 64-char lines between the BEGIN/END markers (keeping legacy headers on their own lines), then converts any supported key (unencrypted PKCS#1/PKCS#8, encrypted PKCS#8, legacy-encrypted PKCS#1) to unencrypted PKCS#8 for the SDK. A missing passphrase gives "key is encrypted; set the passphrase", a wrong passphrase or unparseable key gives a fixed message; no key material or OpenSSL text is included.

How did you verify your code works?

New packages/drivers/test/snowflake-key.test.ts generates keys at test time with node:crypto for each format and variant (multiline, CRLF, space-separated, \n-escaped, quoted), plus error cases and connect() wiring. The connect() tests fail on origin/main. bun typecheck and the snowflake driver tests pass.

Cost side effects

None.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

Summary by cubic

Makes the Snowflake driver accept every common private-key format, so key-pair auth no longer fails on formatting quirks like escaped newlines, quotes, CRLF, or space-separated bodies.

  • Normalizes pasted PEMs (quotes, literal \n sequences, space-joined bodies, CRLF) back to canonical 64-char-line form.
  • Finds the private key even when other PEM blocks (certificates, public keys) come first.
  • Converts unencrypted PKCS#1/RSA and SEC1 keys, encrypted PKCS#8, and legacy-encrypted PKCS#1 (Proc-Type/DEK-Info) to unencrypted PKCS#8 for snowflake-sdk.
  • A missing or wrong private_key_passphrase now raises a clear, actionable error without echoing key material or OpenSSL internals.
  • Moves key handling into snowflake-key.ts with a test suite covering every format and variant.

Summary by CodeRabbit

  • New Features
    • Snowflake key-pair authentication supports private keys with varied quoting, whitespace, and newline formats, as well as supported encrypted key formats.
    • Encrypted keys require a passphrase. Error messages distinguish missing passphrases from invalid or unsupported key input without revealing key contents.
  • Bug Fixes
    • Supported private keys are converted into the format required for Snowflake authentication, improving compatibility with pasted key formats.