posit-dev / posit-dev/snowflakeauth

Keypair auth does not use the shared session cache

Open
#38 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
1
Forks
0
Avg merge
37m
Merged PRs (30d)
1

Description

Problem

Currently, keypair_credentials() has different behavior from other authenticators (externalbrowser, workload_identity):

Auth Method Uses login_request? Uses Session Cache?
externalbrowser Yes Yes
workload_identity Yes Yes
keypair (non-SPCS) No No
keypair (SPCS) No (uses /oauth/token) No

For non-SPCS cases, keypair_credentials() returns the JWT directly as a Bearer token with X-Snowflake-Authorization-Token-Type: KEYPAIR_JWT. This seems to work in most cases, but:

  1. We regenerates the JWT on every call (~10ms overhead per my benchmarking last year).
  2. No participation in the session and keychain caching.
  3. We're inconsistent with other auth methods, which all go through /login-request.

How the Python connector handles this

The Python connector always goes through /session/v1/login-request for keypair auth:

def update_body(self, body: dict[Any, Any]) -> None:
    body["data"]["AUTHENTICATOR"] = KEY_PAIR_AUTHENTICATOR  # "SNOWFLAKE_JWT"
    body["data"]["TOKEN"] = self._jwt_token

I can't find any evidence that they do the OAuth token exchange thing.

Proposed fix

Refactor keypair_credentials() to match the session caching pattern used by workload_identity_credentials() and externalbrowser_credentials().

We need to investigate whether SPCS also accepts session tokens from login_request or whether this needs to remain a separate path.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with keypair_credentials() and compare its flow with workload_identity_credentials() and externalbrowser_credentials(). Verify how non-SPCS keypair authentication currently handles the JWT, login_request, and session or keychain caching, then investigate whether SPCS accepts login_request session tokens. Done means keypair authentication follows the shared caching pattern where supported without breaking the separate SPCS path.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
authentication
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.