-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SNOW-1825608: does the CLIENT_SESSION_KEEP_ALIVE
prevent an OAuth token from expiring
#550
Comments
CLIENT_SESSION_KEEP_ALIVE
prevent an OAuth token from expiringCLIENT_SESSION_KEEP_ALIVE
prevent an OAuth token from expiring
hi, thanks for raising this question. From an initial review, it looks to be working as intended.
X is by default 4 hours, but enter session policies: by configuring session policies, you can define a more customized lifetime validity for your sessions, e.g. you can consider them invalid even after 10 minutes if you wish. Or 1 hour.
Hope this answers the questions. |
@sfc-gh-dszmolka, thanks for your reply ! I still have a few questions about this topic:
Here’s a bit of background: |
Thank you for providing the background here. Looks like this Issue is starting to be a bit more than an actual bug or enhancement request filed against the snowflake-sqlalchemy library, and as I see it, it doesn't even deal with this library but more likely designing a solution based on OAuth.
See more on how OAuth in Snowflake works:
This is not really related to this library.
(or, if
Thus a 1-hour valid OAuth token you mentioned is not recommended from a security best practices perspective, but it's up to you really.
When the Snowflake authentication token expires, then you'll need to reauthenticate.(somehow).
At this point, considering you building a new solution, if your company is a Snowflake customer (or the company who contracted you or your company), I highly recommend considering reaching out to your Snowflake Account Team and asking for a design and implementation consultation. That's why I recommend involving people from Snowflake who can provide closer and more customized guidance; and your account team can help in that. If you don't have any further questions, perhaps we can consider closing this Issue. If you do, let me know and I'll try my best to help. |
Thank you for all the clarifications so far! Before the issue is closed, I have one last question please 🙏 : I’m not building a utility in parallel to By default, once the Snowflake-specific authentication token expires after Should I:
|
after a brief consultation with my colleagues, they advised that we saw users can define a pool engine which always has a valid connection, and recreates said connection if it expires. example_engine = create_engine(
URL(account=...), #usual stuff
pool_size=10, # The size of the pool to maintain
max_overflow=20, # The number of connections to allow beyond pool_size
pool_timeout=30, # How long to wait before giving up on getting a connection from the pool
pool_recycle=3600, # How long to keep connections before recycling (in seconds)
echo=True # Enable logging of all SQL commands
) then using do_connect event to modify how connection parameters are created @event.listens_for(example_engine, 'do_connect')
def receive_do_connect(dialect, conn_rec, cargs, cparams):
cparams["token"] = get_token() Hope this helps providing inspiration for the implementation |
Great, thanks a lot for the help! I think also using an event listener should be the final solution. I'm closing this issue and will drop a comment if anything doesn't work. |
What is the current behavior?
I have an one hour life time oauth token, and I create the engine by
engine = Engine(URL(..., token=ouath_token, "authenticator": "oauth"))
, whereURL
isfrom snowflake.sqlalchemy import URL
It seems that as long as I don't dispose the engine, I can always query Snowflake use the same engine object.
What is the desired behavior?
Snowflake should refuse to process queries after 1 hour.
How would this improve
snowflake-connector-python
?First, could you please confirm whether it's
CLIENT_SESSION_KEEP_ALIVE
that prevents an OAuth token from expiring or if the token does expire but the user session remains valid ?Additionally, is
CLIENT_SESSION_KEEP_ALIVE
set toTrue
by default, as I dont't specifiy it during the engine creation.By the way, could you please also confirm whether the keep alive signal is sent as soon as the engine is created by
engine = Engine(URL(...))
, or if it only starts after calling theengine.connect()
, and when it stops to send the signal ? Thanks.The text was updated successfully, but these errors were encountered: