Skip to content

Implementing known_authority_hosts #492

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

Closed
wants to merge 2 commits into from
Closed

Implementing known_authority_hosts #492

wants to merge 2 commits into from

Conversation

rayluo
Copy link
Collaborator

@rayluo rayluo commented Aug 8, 2022

Implementing the known_authorities behaviors based on the internal design.

The unit tests of this PR is almost as readable as plain English, and are considered as generic acceptance tests for this feature.

This PR also contains the "api reference documentation" for the newly introduced known_authority_hosts parameter.

When merged, this PR will close this internal workitem.


This entire PR has been shelved, because later we discovered some new requirements for Azure Stack scenarios (internal link), so we proceeded with #496.

@rayluo rayluo force-pushed the known_authorities branch from cf5f9ab to 0c2a9a3 Compare August 8, 2022 20:38
@rayluo rayluo force-pushed the known_authorities branch from 080061d to 8370a61 Compare August 10, 2022 20:23
Copy link
Member

@sameerag sameerag left a comment

Choose a reason for hiding this comment

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

Added a few comments but looks good.

@rayluo rayluo changed the title Implementing known_authorities Implementing known_authority_hosts Aug 15, 2022
@jiasli
Copy link
Contributor

jiasli commented Aug 17, 2022

Azure CLI never used validate_authority and everything works fine. Per our observation, all Azure Stack environments utilizing ADFS have the /adfs postfix in their authentication endpoint URL, which makes MSAL bypass authority verification:

if (tenant != "adfs" and (not self._is_b2c) and self._validate_authority

For example, to verify with redmond Azure Stack environment:

az cloud register -n redmond --endpoint-resource-manager "https://management.redmond.azurestack.corp.microsoft.com/"
az cloud set -n redmond --profile 2019-03-01-hybrid
az login

az cloud register queries https://management.redmond.azurestack.corp.microsoft.com/metadata/endpoints?api-version=2019-05-01 for endpoints and authentication endpoint is https://adfs.redmond.azurestack.corp.microsoft.com/adfs.

@rayluo rayluo force-pushed the known_authorities branch 3 times, most recently from 7fe661a to 260450c Compare August 18, 2022 22:42
@rayluo rayluo force-pushed the known_authorities branch 3 times, most recently from 8a5905e to eeae9a5 Compare September 9, 2022 20:29
Also test behaviors for instance metadata

Address proofreading feedback

Rename known_authorities to known_authority_hosts

Plan to ship this in 1.19

Address feedback from Xiang Yan from Azure SDK team

Fine tune some wording

known_authority_hosts allows multiple setting but only one modification

Refine test case for idempotency

More descriptive test case names

Use base ClientApplication to test both PCA and CCA
@rayluo rayluo force-pushed the known_authorities branch 2 times, most recently from 296197e to 35e00a3 Compare September 9, 2022 20:56
self, instance_metadata, known_to_microsoft_validation, _):
app = msal.ClientApplication("id", authority="https://login.microsoftonline.com/common")
known_to_microsoft_validation.assert_not_called()
app.get_accounts() # This could make an instance metadata call for authority aliases
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it expected in this case that get_accounts() does instance discovery? That is to say, ClientApplication() doesn't call known_to_microsoft_validation but get_accounts() does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The answer is two-fold.

  • The "validating whether an input authority looks legit" and "getting some metadata for alias grouping" are two different things. This test case, as described in line 141, made a point that one does not necessarily turn off the other. In this case, ClientApplication() skips validation, but get_accounts() would like to know alias groups.
  • The actual timing of when to send out the metadata call, is an implementation detail. Since MSAL Python delays that metadata call to get_accounts(), so this test case is written this way. Your MSAL's implementation does not have to call get_accounts().

Last but not least, this entire PR has been shelved, because later we discovered some new requirements for Azure Stack scenarios (internal link), so we proceeded with #496.

@rayluo
Copy link
Collaborator Author

rayluo commented Nov 18, 2022

Closing this without merging, because we ended up going with #496

@rayluo rayluo closed this Nov 18, 2022
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.

8 participants