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-715510: MFA Token cache for libsnowflakeclient #773

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

Conversation

sfc-gh-jszczerbinski
Copy link
Contributor

No description provided.

cpp/lib/CacheFile.cpp Outdated Show resolved Hide resolved
cpp/lib/CacheFile.cpp Outdated Show resolved Hide resolved

std::string credItemStr(const CredentialKey &key)
{
return key.host + ":" + key.user + ":SNOWFLAKE-ODBC-DRIVER:" + credTypeToString(key.type);
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be hardcoded to ODBC-DRIVER? I wonder if there's some way to determine whether libsfclient is executed within ODBC or PHP driver or possibly even other drivers in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

it should be configurable and supported not only for ODBC but also PHP

ensureObject(cache);
picojson::object &obj = cache.get<picojson::object>();
auto pair = obj.emplace(key.account, picojson::value(picojson::object()));
auto accountCacheIt = pair.first;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Here I also wasn't sure why we're calling pair.first then accountCacheIt->second gets the credential value. I admit it's a skill issue but would appreciate getting verbose type instead of auto either here or for pair

Copy link
Contributor Author

@sfc-gh-jszczerbinski sfc-gh-jszczerbinski Nov 19, 2024

Choose a reason for hiding this comment

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

  1. picojson::object in pratice is an alias for std::map<std::string, picojson::value>
    typedef std::map<std::string, value> object;
  1. Doc of the emplace method https://en.cppreference.com/w/cpp/container/map/emplace
  2. This code would be clear with more modern c++
/* inserted is true if key.account wasn't in obj and we added new element */
 auto [accountCacheIt, inserted] = obj.emplace(key.account, picojson::value(picojson::object())); 

cpp/platform/SecureStorageImpl.hpp Outdated Show resolved Hide resolved
cpp/platform/SecureStorageApple.cpp Show resolved Hide resolved
FileLock lock(path);
if (!lock.isLocked())
{
CXX_LOG_ERROR("Failed to get token. Could not acquire file lock(path=%s)", lock.getPath().c_str());

Choose a reason for hiding this comment

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

Should we continue if we don't have the lock? (applies to this and following two functions)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not, but I tried not to change original implementation due to BCR concerns

cpp/platform/SecureStorageApple.cpp Outdated Show resolved Hide resolved
cpp/platform/SecureStorageApple.cpp Outdated Show resolved Hide resolved
cpp/platform/SecureStorageApple.cpp Outdated Show resolved Hide resolved
cpp/platform/SecureStorageApple.cpp Show resolved Hide resolved
cpp/platform/SecureStorageApple.cpp Outdated Show resolved Hide resolved
cpp/platform/SecureStorageWin.cpp Show resolved Hide resolved
cpp/platform/SecureStorageWin.cpp Show resolved Hide resolved
cpp/platform/SecureStorageApple.cpp Show resolved Hide resolved
tests/mock/test_mock_mfa_token_caching.c Show resolved Hide resolved
@@ -0,0 +1,227 @@
//
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's not add author comments but add license header for new files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. CLion generated it and I forgot to delete it.

{
"SF_TEMPORARY_CREDENTIAL_CACHE_DIR",
"HOME",
"TMP"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think TMP should be there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but removing it is a BCR in ODBC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will make changes after security modeling is complete


std::string credItemStr(const CredentialKey &key)
{
return key.host + ":" + key.user + ":SNOWFLAKE-ODBC-DRIVER:" + credTypeToString(key.type);
Copy link
Collaborator

Choose a reason for hiding this comment

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

it should be configurable and supported not only for ODBC but also PHP

bool ensurePermissions(const std::string& path, unsigned mode)
{
CXX_LOG_ERROR("Cannot ensure permissions on current platform");
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it ok that for WINDOWS it will be always false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

File caches are not used on windows at all. This definition ensures that the code compiles on windows, but in practice it's never used.

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe then just make the code unnacessible from the beginning? For MacOS are we using the file cache or some secure storage?

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