-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[Core] Enable token cache encryption on MacOS #20636
base: dev
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
# Files extensions for encrypted and plaintext persistence | ||
file_extensions = {True: '.bin', False: '.json'} | ||
|
||
KEYCHAIN_SERVICE_NAME = 'azure-cli' | ||
|
||
|
||
def load_persisted_token_cache(location, encrypt): | ||
persistence = build_persistence(location, encrypt) | ||
|
@@ -38,16 +40,27 @@ def build_persistence(location, encrypt): | |
logger.debug("build_persistence: location=%r, encrypt=%r", location, encrypt) | ||
if encrypt: | ||
if sys.platform.startswith('win'): | ||
# For FilePersistenceWithDataProtection, location is where the credential is stored. | ||
logger.debug("Initializing FilePersistenceWithDataProtection.") | ||
return FilePersistenceWithDataProtection(location) | ||
if sys.platform.startswith('darwin'): | ||
return KeychainPersistence(location, "my_service_name", "my_account_name") | ||
# For KeychainPersistence, location is only used as a signal for the credential's last modified time. | ||
# The credential is stored in Keychain identified by (service_name, account_name) combination. | ||
# msal-extensions automatically computes account_name from signal_location. | ||
# https://github.com/AzureAD/microsoft-authentication-extensions-for-python/pull/103 | ||
logger.debug("Initializing KeychainPersistence") | ||
return KeychainPersistence(location, service_name=KEYCHAIN_SERVICE_NAME) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably already know that, this line won't work until AzureAD/microsoft-authentication-extensions-for-python#103 being released. So, please help review and approve my PR there (otherwise I will not give an approval to your PR here :-D) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have installed the dev code of |
||
if sys.platform.startswith('linux'): | ||
# TODO: Support token cache encryption on Linux | ||
logger.debug("Initializing LibsecretPersistence.") | ||
return LibsecretPersistence( | ||
location, | ||
schema_name="my_schema_name", | ||
attributes={"my_attr1": "foo", "my_attr2": "bar"} | ||
) | ||
else: | ||
# For FilePersistence, location is where the credential is stored. | ||
logger.debug("Initializing FilePersistence") | ||
return FilePersistence(location) | ||
|
||
|
||
|
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.
This comment probably also needs to update to mention macOS now.
By the way, does this comment actually mean to say, "only allow fallback when running on Windows ..."?
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.
Oh. I forgot to update the comment!