Skip to content

Commit 9a6bacf

Browse files
committed
Minimal bits to make Snowflake SPCS OIDC authentication work
This commit is mainly meant as an example to complement changes in how we will be performing authentication within the Snowflake Posit Team Native Application. When / if that PR of work for OIDC goes through this will serve as a good example of how it can be supported. I think this PR also highlights the importance of OIDC device flow authentication which is supported in PPM https://packagemanager.rstudio.com/__docs__/admin/appendix//cli/rspm_login_sso.html which would again eliminate the need for an api key. I REALLY like how this package uses the snow command to generate the jwt used for snowflake ingress as this means our Posit libraries don't have to re-implement the snowflake authentication. Going to put this PR in draft and will contribute more after I share this with our team tomorrow at Standup.
1 parent 1a1ae59 commit 9a6bacf

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

rsconnect/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ class SPCSConnectServer(AbstractRemoteServer):
246246
def __init__(
247247
self,
248248
url: str,
249+
api_key: str,
249250
snowflake_connection_name: Optional[str],
250251
insecure: bool = False,
251252
ca_data: Optional[str | bytes] = None,
@@ -256,7 +257,7 @@ def __init__(
256257
self.ca_data = ca_data
257258
# for compatibility with RSConnectClient
258259
self.cookie_jar = CookieJar()
259-
self.api_key = None
260+
self.api_key = api_key
260261
self.bootstrap_jwt = None
261262

262263
def token_endpoint(self) -> str:
@@ -396,6 +397,7 @@ def __init__(self, server: Union[RSConnectServer, SPCSConnectServer], cookies: O
396397
if server.snowflake_connection_name and isinstance(server, SPCSConnectServer):
397398
token = server.exchange_token()
398399
self.snowflake_authorization(token)
400+
self._headers["X-RSC-Authorization"] = server.api_key
399401

400402
def _tweak_response(self, response: HTTPResponse) -> JsonData | HTTPResponse:
401403
return (

rsconnect/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def add(
584584

585585
if server and ("snowflakecomputing.app" in server or snowflake_connection_name):
586586

587-
real_server_spcs = api.SPCSConnectServer(server, snowflake_connection_name)
587+
real_server_spcs = api.SPCSConnectServer(server, api_key, snowflake_connection_name)
588588

589589
_test_spcs_creds(real_server_spcs)
590590

0 commit comments

Comments
 (0)