-
Notifications
You must be signed in to change notification settings - Fork 171
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-1895884: Token cache refactor #2044
base: oauth-code-flow
Are you sure you want to change the base?
Conversation
…bc into SNOW-1895884-token-cache-keys
…b/snowflake-jdbc into SNOW-1895884-token-cache-keys
Map<String, String> hostMap = localCredCache.get(host.toUpperCase()); | ||
hostMap.put(SecureStorageManager.convertTarget(host, user, type), token); | ||
|
||
localCredCache.computeIfAbsent(CACHE_FILE_TOKENS_OBJECT_NAME, tokensMap -> new HashMap<>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should read, update and write cache here under one file lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated logic
return null; | ||
} | ||
|
||
return hostMap.get(SecureStorageManager.convertTarget(host, user, type)); | ||
return tokensMap.get(SecureStorageManager.buildCredentialsKey(host, user, type)); | ||
} | ||
|
||
/** May delete credentials which doesn't belong to this process */ | ||
public synchronized SecureStorageStatus deleteCredential(String host, String user, String type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should read, delete entry and write cache here under one file lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored
️✅ There are no secrets present in this pull request anymore.If these secrets were true positive and are still valid, we highly recommend you to revoke them. 🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request. |
74bfcd6
to
6575f5d
Compare
} | ||
for (Iterator<Map.Entry<String, JsonNode>> itr = m.fields(); itr.hasNext(); ) { | ||
for (Iterator<Map.Entry<String, JsonNode>> itr = node.fields(); itr.hasNext(); ) { | ||
Map.Entry<String, JsonNode> hostMap = itr.next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change naming? Those are no longer hosts
private FileCacheManager fileCacheManager; | ||
|
||
private final Map<String, Map<String, String>> localCredCache = new HashMap<>(); | ||
private final FileCacheManager fileCacheManager; | ||
|
||
private SecureStorageLinuxManager() { | ||
fileCacheManager = | ||
FileCacheManager.builder() | ||
.setCacheDirectorySystemProperty(CACHE_DIR_PROP) | ||
.setCacheDirectoryEnvironmentVariable(CACHE_DIR_ENV) | ||
.setBaseCacheFileName(CACHE_FILE_NAME) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should respect XDG_CACHE_HOME
According to XDG specs:
There is a single base directory relative to which user-specific non-essential (cached) data should be written. This directory is defined by the environment variable $XDG_CACHE_HOME.
The design doc:
[Linux only] Directory present in environment var (XDG_CACHE_HOME/snowflake) if set and directory exists or can be created and we can set correct permissions for it (700)
} | ||
|
||
/** Reads the cache file. */ | ||
JsonNode readCacheFile() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we check permissions for parent directory?
* @return true if success or false | ||
*/ | ||
private boolean lockCacheFile() { | ||
return cacheLockFile.mkdirs(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this is the place where we create cache directory if it doesn't exits. I think it's not the best place since:
- We can create a $HOME directory by mistake and not just .cache/snowflake directory
- [Less important] We cannot fallback to other directories if we cannot use the one we chose in build function
@@ -230,32 +249,21 @@ JsonNode readCacheFile() { | |||
|
|||
void writeCacheFile(JsonNode input) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we check permissions for parent directory? should be 0700
Overview
SNOW-1895884
Pre-review self checklist
master
branchmvn -P check-style validate
)mvn verify
and inspecttarget/japicmp/japicmp.html
)SNOW-XXXX:
External contributors - please answer these questions before submitting a pull request. Thanks!
What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Issue: #NNNN
Fill out the following pre-review checklist:
@SnowflakeJdbcInternalApi
(note that public/protected methods/fields in classes marked with this annotation are already internal)Please describe how your code solves the related issue.
Please write a short description of how your code change solves the related issue.