Add optional RSA key authentication and token regeneration support for Snowflake #159
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces optional support for Snowflake JWT authentication using RSA private keys, in addition to the existing password-based approach. It also implements automatic token regeneration to support long-lived or spaced query executions.
These enhancements maintain backward compatibility with existing configurations and require no changes for current users using password authentication.
Key Changes
🔐 RSA Private Key Authentication (JWT)
private_key_file
URL query parameter.gosnowflake.Config
withAuthTypeJwt
using the RSA key.Usage Example:
🔁 Automatic JWT Token Regeneration
Tracks token expiration time and automatically regenerates the connection/token before each job run if expired (default: every 1 hour).
Enables safe execution of scheduled jobs with long intervals (e.g., 1h, 6h+) without risk of token expiry.
Why This Matters
Security: RSA keys provide stronger, more secure authentication than passwords.
Reliability: Spaced jobs won't fail due to token expiry — ideal for Prometheus scraping Snowflake at longer intervals.
Flexibility: Auth method is automatically inferred based on the presence of
private_key_file
in the connection string.Compatibility
✅ Fully backward compatible.
If
private_key_file
is not present, the connection will use the default password method as before.Related Files Modified
job.go
: Dual-mode auth logic (RSA vs. password), token tracking.config.go
: Adds optionalsnowflakeDSN
andtokenExpirationTime
to connection struct.