Skip to content
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-1694143: Authentication Token Caching is not working with v1.13 #921

Closed
supermacro opened this issue Sep 27, 2024 · 6 comments
Closed
Assignees
Labels
bug Something isn't working status-fixed_awaiting_release The issue has been fixed, its PR merged, and now awaiting the next release cycle of the connector. status-triage_done Initial triage done, will be further handled by the driver team

Comments

@supermacro
Copy link

supermacro commented Sep 27, 2024

  1. What version of NodeJS driver are you using?

1.13.1

  1. What operating system and processor architecture are you using?

MacOSX 14.17 (Sonoma) on M3 macbook pro

  1. What version of NodeJS are you using?

node v20.17.0
pnpm 9.11.0

  1. What are the component versions in the environment (npm list)?
Legend: production dependency, optional only, dev only

[email protected] /Users/gio/dev/sf-nodejs-driver-test

dependencies:
snowflake-sdk 1.13.1

5.Server version:* E.g. 1.90.1

8.36.2

  1. What did you do?

#820 Implemented sso token caching. However token caching does not work in version 1.13.1 of this lib (and possibly other versions). Every new connection fails to use the id token that is written to disk.

Issues found:

  • in order for an ID token to be written to disk, clientStoreTemporaryCredential needs to be set to true in the connection config, yet it's not a field defined in index.d.ts.
  • Every new connection initiates a new SSO flow. An id token is cached to $HOME correctly, but it is not read or used by the snowflake-sdk

To reproduce the issue, run the code snippet below TWICE.

const sf = require('snowflake-sdk')

const conn = sf.createConnection({
  username: '<redacted>',
  account: '<redacted>',
  authenticator: 'externalbrowser',
  database: '<redacted>',
  schema: '<redacted>',
  clientStoreTemporaryCredential: true,
})

conn.connectAsync((err, econnected) => {
  if (err) {
    console.error('Unable to connect: ' + err.message);
    return
  }

  console.log('Connection successfully established!')
})
image
  1. What did you expect to see?

The expected behaviour when you run the above code snippet twice is:

  • First run opens up a new browser tab to initiate external SSO flow
  • Second run DOES NOT open a new browser tab and instead snowflake-sdk uses id token inside of temporary_credential.json file that was written to disk during initial authentication flow

However, the current behaviour is that a new browser tab is opened to initiate the external SSO flow and the cached token is not used. See screenshot for proof that a token is cached to disk at $HOME

  1. Can you set logging to DEBUG and collect the logs?
{"level":"INFO","message":"[10:15:19.480 AM]: Connecting to GLOBAL Snowflake domain"}
{"level":"INFO","message":"[10:15:19.484 AM]: Custom credential manager is set by a user."}
{"level":"INFO","message":"[10:15:19.487 AM]: Trying to initialize Easy Logging"}
{"level":"INFO","message":"[10:15:19.487 AM]: No client config file found in default directories"}
{"level":"INFO","message":"[10:15:19.487 AM]: Easy Logging is disabled as no config has been found"}
Connection successfully established!
  1. What is your Snowflake account identifier, if any? (Optional)

COPLANE.JRB00548

@supermacro supermacro added the bug Something isn't working label Sep 27, 2024
@github-actions github-actions bot changed the title Authentication Token Caching is not working SNOW-1694143: Authentication Token Caching is not working Sep 27, 2024
@tarruda
Copy link

tarruda commented Sep 27, 2024

I'm unable to use externalbrowser authentication.

Using the same settings as @supermacro , I get the following logs:
image

Update: Ignore it, I was using wrong credentials.

I confirm what @supermacro said, every new connection starts a new flow.

If I apply #918, things work correctly

@sfc-gh-dszmolka sfc-gh-dszmolka self-assigned this Sep 27, 2024
@sfc-gh-dszmolka sfc-gh-dszmolka added the status-triage Issue is under initial triage label Sep 27, 2024
@sfc-gh-dszmolka
Copy link
Collaborator

thank for reporting this ! so tested the feature when it was released with v1.12.0 and it worked - it still works today with v1.12.0

but something between v1.12.0 (initial release of the feature) and v1.13.1 (latest) broke because i can confirm, it doesn't work anymore with v1.13.1

as a workaround you can consider using v1.12.0 while the issue is fixed. also thank you for the PR suggestion !

@sfc-gh-dszmolka sfc-gh-dszmolka added status-triage_done Initial triage done, will be further handled by the driver team and removed status-triage Issue is under initial triage labels Sep 27, 2024
@sfc-gh-dszmolka sfc-gh-dszmolka changed the title SNOW-1694143: Authentication Token Caching is not working SNOW-1694143: Authentication Token Caching is not working with v1.13 Sep 27, 2024
@vimota
Copy link

vimota commented Sep 27, 2024

I think this might've broken it: eddce19 - it removed passing in the connectionConfig even though connectAsync updates the connectionConfig in place

@sfc-gh-dszmolka
Copy link
Collaborator

confirmed - this broke it indeed. working on a fix. workaround is to use v1.12.0 (or @supermacro 's patch)

@sfc-gh-dszmolka sfc-gh-dszmolka added the status-pr_pending_merge A PR is made and is under review label Sep 30, 2024
@sfc-gh-dszmolka sfc-gh-dszmolka added status-fixed_awaiting_release The issue has been fixed, its PR merged, and now awaiting the next release cycle of the connector. and removed status-pr_pending_merge A PR is made and is under review labels Oct 1, 2024
@sfc-gh-dszmolka
Copy link
Collaborator

issues is fixed now with #919 , thank you for your contribution @supermacro and detailed analysis !
awaiting release

@sfc-gh-dszmolka
Copy link
Collaborator

released with Snowflake Node.js driver version 1.14.0 in September 2024 release cycle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working status-fixed_awaiting_release The issue has been fixed, its PR merged, and now awaiting the next release cycle of the connector. status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
Development

No branches or pull requests

5 participants