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-715524: Add SSO token cache #921

Open
wants to merge 110 commits into
base: master
Choose a base branch
from

Conversation

sfc-gh-ext-simba-lf
Copy link
Collaborator

Description

Add SSO token cache

Checklist

  • Code compiles correctly
  • Code is formatted according to Coding Conventions
  • Created tests which fail without the change (if possible)
  • All tests passing (dotnet test)
  • Extended the README / documentation, if necessary
  • Provide JIRA issue id (if possible) or GitHub issue id in PR name

Copy link

codecov bot commented Apr 18, 2024

Codecov Report

Attention: Patch coverage is 87.11656% with 21 lines in your changes missing coverage. Please review.

Project coverage is 87.49%. Comparing base (444a2c1) to head (b4fdf7e).

Files with missing lines Patch % Lines
Snowflake.Data/Core/Tools/BrowserOperations.cs 5.55% 17 Missing ⚠️
...Core/Authenticator/ExternalBrowserAuthenticator.cs 97.08% 3 Missing ⚠️
Snowflake.Data/Core/Session/SFSession.cs 96.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #921      +/-   ##
==========================================
+ Coverage   86.23%   87.49%   +1.25%     
==========================================
  Files         132      133       +1     
  Lines       12664    12721      +57     
  Branches     1299     1305       +6     
==========================================
+ Hits        10921    11130     +209     
+ Misses       1417     1267     -150     
+ Partials      326      324       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sfc-gh-ext-simba-lf sfc-gh-ext-simba-lf marked this pull request as ready for review April 20, 2024 00:42
@sfc-gh-ext-simba-lf sfc-gh-ext-simba-lf requested a review from a team as a code owner April 20, 2024 00:42
@rafael-sotelo
Copy link

Any updates on this PR ? Can I help ? I been waiting for this SSO Token Cache for long time

@sfc-gh-ext-simba-lf
Copy link
Collaborator Author

Any updates on this PR ? Can I help ? I been waiting for this SSO Token Cache for long time

Currently we're trying out different libraries/packages for the credential manager. Then it'll be reviewed if it meets the security requirements


namespace Snowflake.Data.Client
{
public class SnowflakeCredentialManagerNativeImpl : ISnowflakeCredentialManager
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could move all the implementations into subpackage Infrastructure

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

sfc-gh-ext-simba-lf and others added 26 commits July 9, 2024 09:35
…nector-net into SNOW-715524-SSO-Token-Cache

# Conflicts:
#	Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs
…nector-net into SNOW-715524-SSO-Token-Cache

# Conflicts:
#	Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs
…nector-net into SNOW-715524-SSO-Token-Cache

# Conflicts:
#	Snowflake.Data/Core/SFError.cs
…nector-net into SNOW-715524-SSO-Token-Cache

# Conflicts:
#	Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs
#	Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs
#	Snowflake.Data/Core/Authenticator/ExternalBrowserAuthenticator.cs
#	Snowflake.Data/Core/CredentialManager/Infrastructure/SFCredentialManagerFileImpl.cs
#	Snowflake.Data/Core/CredentialManager/Infrastructure/SFCredentialManagerInMemoryImpl.cs
#	Snowflake.Data/Core/CredentialManager/Infrastructure/SFCredentialManagerWindowsNativeImpl.cs
#	Snowflake.Data/Core/RestResponse.cs
#	Snowflake.Data/Core/SFError.cs
#	Snowflake.Data/Core/Session/SFSession.cs
#	Snowflake.Data/Core/Session/SFSessionParameter.cs
#	Snowflake.Data/Core/Session/SFSessionProperty.cs
#	Snowflake.Data/Core/Tools/FileOperations.cs
#	Snowflake.Data/Core/Tools/UnixOperations.cs
#	doc/Connecting.md

int localPort = GetRandomUnusedPort();
using (var httpListener = GetHttpListener(localPort))
var idToken = new NetworkCredential(string.Empty, session._idToken).Password;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use SecureStringHelper.Decode()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

data.Token = _samlResponseToken;
data.ProofKey = _proofKey;
SetSecondaryAuthenticationData(ref data);
var idToken = new NetworkCredential(string.Empty, session._idToken).Password;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use SecureStringHelper.Decode()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

else
{
data.Token = idToken;
data.Authenticator = TokenType.IdToken.GetAttribute<StringAttr>().value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be id_token not externalbrowser?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's for the server response to contain an ID token

It's similar to how other connectors handle it: https://github.com/snowflakedb/snowflake-connector-nodejs/blob/9cae04323ef4f76d91342e80cfef39952fe652c3/lib/authentication/auth_idtoken.js#L28

}
s_logger.Info("Unable to get credentials for the specified key");
return "";
s_logger.Debug($"Getting credentials from memory for key: {key}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this extra tab is not needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not able to see an extra tab. I checked with the formatter and it doesn't find anything either

@@ -12,7 +12,6 @@

namespace Snowflake.Data.Core.CredentialManager.Infrastructure
{

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would revert this change

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants