Add optional RSA key authentication and token regeneration support for Snowflake#159
Merged
dewey merged 2 commits intojustwatchcom:masterfrom Jun 16, 2025
Merged
Conversation
Contributor
Author
|
Hello guys! In November, we will no longer be able to log in to snowflake using password anymore. |
Member
|
Hey, I'm assuming you already have this running in production and tested that? I don't have a way to test this myself at the moment. |
dewey
reviewed
Jun 12, 2025
Contributor
Author
Yes, we are already using this branch in our staging environment for two weeks with 19 snowflake accounts connected to it, zero problems and errors so far. |
Member
|
Thank you for this addition, I don't have a way to verify it myself but as you said you are using it and the code seems fine I'm going to merge it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_fileURL query parameter.gosnowflake.ConfigwithAuthTypeJwtusing 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_filein the connection string.Compatibility
✅ Fully backward compatible.
If
private_key_fileis 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 optionalsnowflakeDSNandtokenExpirationTimeto connection struct.