Skip to content

fix(ibis): Restore support for Snowflake password authentication#1236

Merged
goldmedal merged 3 commits intoCanner:mainfrom
douenergy:snowflake-password
Jun 27, 2025
Merged

fix(ibis): Restore support for Snowflake password authentication#1236
goldmedal merged 3 commits intoCanner:mainfrom
douenergy:snowflake-password

Conversation

@douenergy
Copy link
Copy Markdown
Contributor

@douenergy douenergy commented Jun 27, 2025

We will support password login until Snowflake sunsets it.

related to #1230

Summary by CodeRabbit

  • New Features

    • Added support for connecting to Snowflake using a password as an alternative to private key authentication.
  • Bug Fixes

    • Improved handling of optional fields for Snowflake connection settings, allowing connections without specifying a password or warehouse.
  • Tests

    • Introduced a new test to verify Snowflake connections using password authentication.

@github-actions github-actions bot added ibis python Pull requests that update Python code labels Jun 27, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 27, 2025

Caution

Review failed

The pull request is closed.

"""

Walkthrough

The changes introduce optional password-based authentication for Snowflake connections in addition to the existing private key method. The Snowflake connection info model is updated to allow optional password and warehouse fields. The connection logic now branches based on authentication method, and a new test verifies password-based connection functionality.

Changes

File(s) Change Summary
ibis-server/app/model/init.py Made password and warehouse fields in SnowflakeConnectionInfo optional; added password field.
ibis-server/app/model/data_source.py Updated get_snowflake_connection to support both password and private key authentication methods.
ibis-server/tests/routers/v2/connector/test_snowflake.py Added password_connection_info and a new async test for password-based Snowflake connection.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DataSource
    participant Snowflake

    Client->>DataSource: Request connection (with info)
    alt info has private_key
        DataSource->>Snowflake: Connect using private_key
    else info has password
        DataSource->>Snowflake: Connect using password
    end
    Snowflake-->>DataSource: Connection established
    DataSource-->>Client: Return connection/result
Loading

Possibly related PRs

Suggested reviewers

  • goldmedal

Poem

In the warren where data flows free,
A rabbit codes with glee and esprit—
Now Snowflake unlocks with a key or a word,
Both secrets and passwords are equally heard.
Two paths to connect, one hop at a time,
Testing ensures it all works just fine! 🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce58328 and 089bea0.

📒 Files selected for processing (1)
  • ibis-server/tests/routers/v2/connector/test_snowflake.py (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@douenergy douenergy force-pushed the snowflake-password branch from df23ded to ce58328 Compare June 27, 2025 10:06
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
ibis-server/app/model/data_source.py (1)

227-227: Address static analysis hints for cleaner code.

The static analysis tools correctly identified opportunities for improvement:

  • Remove unnecessary else after return
  • Use {} instead of dict() calls

Also applies to: 238-238

ibis-server/tests/routers/v2/connector/test_snowflake.py (1)

121-156: Consider adding edge case tests for authentication.

While the main password authentication test is comprehensive, consider adding tests for edge cases such as:

  • Missing password when private key is also missing
  • Invalid password scenarios
  • Mixed authentication parameters

Would you like me to generate additional test cases to cover these authentication edge cases?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16f19b0 and ce58328.

📒 Files selected for processing (3)
  • ibis-server/app/model/__init__.py (2 hunks)
  • ibis-server/app/model/data_source.py (1 hunks)
  • ibis-server/tests/routers/v2/connector/test_snowflake.py (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: goldmedal
PR: Canner/wren-engine#1053
File: ibis-server/app/model/__init__.py:187-196
Timestamp: 2025-02-04T12:08:44.141Z
Learning: In GcsFileConnectionInfo, both secret-based (key_id/secret_key) and credentials-based (service account) authentication methods are required fields.
🪛 Pylint (3.3.7)
ibis-server/app/model/data_source.py

[refactor] 221-239: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 229-229: Consider using '{}' instead of a call to 'dict'.

(R1735)


[refactor] 238-238: Consider using '{}' instead of a call to 'dict'.

(R1735)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ci
🔇 Additional comments (4)
ibis-server/app/model/__init__.py (2)

321-323: LGTM! Password field correctly made optional for dual authentication support.

The change to make the password field optional with SecretStr | None and default None correctly supports both password-based and private key authentication methods.


335-339: LGTM! Warehouse field appropriately made optional.

Making the warehouse field optional aligns with the authentication method branching, where password-based connections may not require specifying a warehouse.

ibis-server/tests/routers/v2/connector/test_snowflake.py (2)

22-28: LGTM! Password connection info correctly configured.

The password-based connection configuration appropriately uses environment variables and omits the warehouse field, aligning with the connection logic changes.


121-156: ```shell
#!/bin/bash

Locate the test file path

echo "Locating test_snowflake.py:"
fd -e py test_snowflake.py

Show snippet around private key authentication test

echo -e "\nPrivate key test snippet:"
rg -n -C5 "private_key_connection_info" ibis-server/tests/routers/v2/connector/test_snowflake.py || echo "No private_key fixture found"

Show all test_query_with_ occurrences for context

echo -e "\nAll test_query_with_ occurrences:"
rg -n "test_query_with_" ibis-server/tests/routers/v2/connector/test_snowflake.py


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment on lines +221 to +239
if hasattr(info, "private_key") and info.private_key:
return ibis.snowflake.connect(
user=info.user.get_secret_value(),
account=info.account.get_secret_value(),
database=info.database.get_secret_value(),
schema=info.sf_schema.get_secret_value(),
warehouse=info.warehouse.get_secret_value(),
private_key=info.private_key.get_secret_value(),
**info.kwargs if info.kwargs else dict(),
)
else:
return ibis.snowflake.connect(
user=info.user.get_secret_value(),
password=info.password.get_secret_value(),
account=info.account.get_secret_value(),
database=info.database.get_secret_value(),
schema=info.sf_schema.get_secret_value(),
**info.kwargs if info.kwargs else dict(),
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Verify authentication credential validation and improve code style.

The authentication branching logic is sound, but consider these improvements:

  1. Add explicit validation for missing credentials to provide clearer error messages
  2. Simplify the else clause and improve dictionary usage per static analysis hints

Apply this diff to improve the implementation:

 @staticmethod
 def get_snowflake_connection(info: SnowflakeConnectionInfo) -> BaseBackend:
-    if hasattr(info, "private_key") and info.private_key:
+    if hasattr(info, "private_key") and info.private_key:
         return ibis.snowflake.connect(
             user=info.user.get_secret_value(),
             account=info.account.get_secret_value(),
             database=info.database.get_secret_value(),
             schema=info.sf_schema.get_secret_value(),
             warehouse=info.warehouse.get_secret_value(),
             private_key=info.private_key.get_secret_value(),
-            **info.kwargs if info.kwargs else dict(),
+            **info.kwargs if info.kwargs else {},
         )
-    else:
+    
+    if not info.password:
+        raise ValueError("Either private_key or password must be provided for Snowflake authentication")
+    
+    return ibis.snowflake.connect(
+        user=info.user.get_secret_value(),
+        password=info.password.get_secret_value(),
+        account=info.account.get_secret_value(),
+        database=info.database.get_secret_value(),
+        schema=info.sf_schema.get_secret_value(),
+        **info.kwargs if info.kwargs else {},
+    )
-        return ibis.snowflake.connect(
-            user=info.user.get_secret_value(),
-            password=info.password.get_secret_value(),
-            account=info.account.get_secret_value(),
-            database=info.database.get_secret_value(),
-            schema=info.sf_schema.get_secret_value(),
-            **info.kwargs if info.kwargs else dict(),
-        )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if hasattr(info, "private_key") and info.private_key:
return ibis.snowflake.connect(
user=info.user.get_secret_value(),
account=info.account.get_secret_value(),
database=info.database.get_secret_value(),
schema=info.sf_schema.get_secret_value(),
warehouse=info.warehouse.get_secret_value(),
private_key=info.private_key.get_secret_value(),
**info.kwargs if info.kwargs else dict(),
)
else:
return ibis.snowflake.connect(
user=info.user.get_secret_value(),
password=info.password.get_secret_value(),
account=info.account.get_secret_value(),
database=info.database.get_secret_value(),
schema=info.sf_schema.get_secret_value(),
**info.kwargs if info.kwargs else dict(),
)
@staticmethod
def get_snowflake_connection(info: SnowflakeConnectionInfo) -> BaseBackend:
if hasattr(info, "private_key") and info.private_key:
return ibis.snowflake.connect(
user=info.user.get_secret_value(),
account=info.account.get_secret_value(),
database=info.database.get_secret_value(),
schema=info.sf_schema.get_secret_value(),
warehouse=info.warehouse.get_secret_value(),
private_key=info.private_key.get_secret_value(),
**info.kwargs if info.kwargs else {},
)
if not info.password:
raise ValueError(
"Either private_key or password must be provided for Snowflake authentication"
)
return ibis.snowflake.connect(
user=info.user.get_secret_value(),
password=info.password.get_secret_value(),
account=info.account.get_secret_value(),
database=info.database.get_secret_value(),
schema=info.sf_schema.get_secret_value(),
**info.kwargs if info.kwargs else {},
)
🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 221-239: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 229-229: Consider using '{}' instead of a call to 'dict'.

(R1735)


[refactor] 238-238: Consider using '{}' instead of a call to 'dict'.

(R1735)

🤖 Prompt for AI Agents
In ibis-server/app/model/data_source.py around lines 221 to 239, add explicit
checks to validate that required authentication credentials (like user,
password, or private_key) are present before attempting connection, raising
clear errors if missing. Simplify the else clause by using a single dictionary
unpacking with a default empty dict for info.kwargs, avoiding redundant
conditional expressions to improve code clarity and comply with static analysis
recommendations.

Copy link
Copy Markdown
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @douenergy

@goldmedal goldmedal merged commit 1477cf6 into Canner:main Jun 27, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ibis python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants