最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Is there a way in snowflake to use sso authentication information via browser mulitple times in a python script? - Stack Overflo

programmeradmin1浏览0评论

I build up a connection to snowflake from python with snowpark session library using the authenticator externalbrowser. When I run the code then the browser opens and I type in my credentials. The python code is executing and I get the data from snowflake.

But this happens everytime when I run the python code. Is there a way to store authenticator information to use them multiple times?

I use the same authentication via externalbrowser with datagrip and I can use the authentication several hours.

from snowflake.snowpark import Session

connection_parameters = {
    "account": "xyz",
    "authenticator": "externalbrowser",
    "user": "abcde",
    "role": "role_one",
    "warehouse": "tiny",
    "database": "db1234"
}

# create session
session = Session.builder.configs(connection_parameters).create()

I build up a connection to snowflake from python with snowpark session library using the authenticator externalbrowser. When I run the code then the browser opens and I type in my credentials. The python code is executing and I get the data from snowflake.

But this happens everytime when I run the python code. Is there a way to store authenticator information to use them multiple times?

I use the same authentication via externalbrowser with datagrip and I can use the authentication several hours.

from snowflake.snowpark import Session

connection_parameters = {
    "account": "xyz",
    "authenticator": "externalbrowser",
    "user": "abcde",
    "role": "role_one",
    "warehouse": "tiny",
    "database": "db1234"
}

# create session
session = Session.builder.configs(connection_parameters).create()
Share Improve this question asked Nov 20, 2024 at 11:21 flubberflubber 32 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

Yes, you can store authentication tokens using Snowflake's private key authentication instead of external browser. Here's how:

  1. Generate a private key pair:
openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocrypt
openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub
  1. Add public key to Snowflake:
ALTER USER your_username SET RSA_PUBLIC_KEY='contents_of_rsa_key.pub';
  1. Update your Python code:
from snowflake.snowpark import Session

connection_parameters = {
    "account": "xyz",
    "user": "abcde",
    "private_key_path": "path/to/rsa_key.p8",
    "role": "role_one",
    "warehouse": "tiny",
    "database": "db1234"
}

session = Session.builder.configs(connection_parameters).create()

This eliminates the need for browser authentication on each run.

The solution is to install this package:

pip install "snowflake-connector-python[secure-local-storage]"

The token is stored in the background so that the browser window no longer opens.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论