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

[Core] Enable token cache encryption on MacOS #20636

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft

Conversation

jiasli
Copy link
Member

@jiasli jiasli commented Dec 7, 2021

Description

Utilize AzureAD/microsoft-authentication-extensions-for-python#103 to enable token cache encryption on MacOS.

We don't need to provide account_name by ourselves. Instead, msal-extensions automatically computes account_name from signal_location.

See code comment for more information.

After this change, user will have to re-login so that credential is stored into Keychain.

References

Related email discussion: Naming for service_name and account_name for MacOS token encryption

@jiasli jiasli marked this pull request as draft December 7, 2021 09:48
@jiasli jiasli requested a review from rayluo December 7, 2021 09:48
@jiasli jiasli self-assigned this Dec 7, 2021
@jiasli jiasli added this to the Dec 2021 (2022-01-04) milestone Dec 7, 2021
@@ -861,7 +861,7 @@ def _create_identity_instance(cli_ctx, *args, **kwargs):
from .auth.identity import Identity

# Only enable encryption for Windows (for now).
Copy link
Member

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 ..."?

Copy link
Member Author

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!

# 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)
Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Member Author

@jiasli jiasli Dec 8, 2021

Choose a reason for hiding this comment

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

I have installed the dev code of msal-extensions and it works perfectly.

@yonzhan
Copy link
Collaborator

yonzhan commented Dec 22, 2021

Enable token cache encryption on MacOS

@jiasli
Copy link
Member Author

jiasli commented Mar 15, 2022

Given we are seeing a plethora of issues with Windows DPAPI encryption (#19506, https://github.com/Azure/azure-cli/issues?q=is%3Aissue+label%3A%22common+issue%22+winerror), it may not be a good idea to rush this PR.

@rayluo
Copy link
Member

rayluo commented Mar 15, 2022

Given we are seeing a plethora of issues with Windows DPAPI encryption (https://github.com/Azure/azure-cli/issues?q=is%3Aissue+label%3A%22common+issue%22+winerror), it may not be a good idea to rush this PR.

Different encryption mechanisms are used on different platforms. All those DPAPI issues will not be observed on macOS platform. On the other hand, we do not know whether there would be "plethora of issues" with macOS's Keychain. @bgavrilMS may comment based on the observation of keychain on .Net side.

@bgavrilMS
Copy link

bgavrilMS commented Mar 15, 2022

There is a plethora of issues on Mac as well. They mainly stem from how you package your app, in this case how you package Azure CLI.

If you package it as Apple like it, with bundle id and via the app store, then you'll have access to the newest KeyChain APIs, which I think work rather well (this is what MSAL iOS uses on Mac, and I discussed it with them and it looks ok).

If however you don't have a bundle id, then you can't use the newest KeyChain APIs and the older ones are not as reliable.

Example of "old" API: SecKeychainFindGenericPassword and new API: SecItemAdd

@rayluo
Copy link
Member

rayluo commented Mar 15, 2022

@jiasli
Copy link
Member Author

jiasli commented Mar 16, 2022

Different encryption mechanisms are used on different platforms.

I understand. I am only saying if encryption problems occur on MacOS, this will heavy the burden we currently have.

According to our internal email discussion "Workaround for DPAPI/KeyChain Errors": Azure/azure-powershell#14478 is one example of KeyChain not working as expected on MacOS:

The root cause seems to be using the older version of KeyChain APIs.

@gattjoe
Copy link

gattjoe commented Feb 2, 2023

Hi @rayluo @jiasli I submitted a PR in MSAL EX to use the modern OS X Keyring API, take a look and let me know if we can help move this forward AzureAD/microsoft-authentication-extensions-for-python#119

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

Successfully merging this pull request may close these issues.

6 participants