Skip to content

Support CAE #16852

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

Merged
merged 6 commits into from
Feb 10, 2022
Merged

Support CAE #16852

merged 6 commits into from
Feb 10, 2022

Conversation

msJinLei
Copy link
Contributor

@msJinLei msJinLei commented Jan 17, 2022

Description

  • Implement CAE by adding handler to http pipeline
  • Improved error message when login is blocked by AAD
  • Improved error message when silent reauthentication failed
  • Enabled CAE for Get-AzTenant and Get-AzSubcription
  • Enable CAE for MSGraph
  • Added test cases

Related issue

Checklist

  • I have read the Submitting Changes section of CONTRIBUTING.md
  • The title of the PR is clear and informative
  • The appropriate ChangeLog.md file(s) has been updated:
    • For any service, the ChangeLog.md file can be found at src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md
    • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header -- no new version header should be added
  • The PR does not introduce breaking changes
  • If applicable, the changes made in the PR have proper test coverage
  • For public API changes to cmdlets:
    • a cmdlet design review was approved for the changes in this repository (Microsoft internal only)
      • {Please put the link here}
    • the markdown help files have been regenerated using the commands listed here

@msJinLei msJinLei changed the title Cae Draft Support CAE Jan 21, 2022
@msJinLei msJinLei marked this pull request as ready for review January 21, 2022 10:30
@msJinLei
Copy link
Contributor Author

/azp run azure-powershell - windows-powershell

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@msJinLei
Copy link
Contributor Author

/azp run azure-powershell - powershell-core

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@wyunchi-ms
Copy link
Contributor

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

@isra-fel
Copy link
Member

Request @dolauli to review the part related to autorest-based cmdlets (src/Accounts/Accounts/CommonModule/ContextAdapter.cs)

Copy link
Member

@isra-fel isra-fel left a comment

Choose a reason for hiding this comment

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

One general comment: to avoid possible breaking change, we should expose as little APIs as we can. For example the ClaimsChallengerHandler class.

Comment on lines +564 to +566
private bool TryParseUnknownAuthenticationException(AuthenticationFailedException exception, out string message)
{

Copy link
Member

Choose a reason for hiding this comment

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

Shall we move the method out of this class because (1) this class is already very long (2) the logic of parsing MsalServiceException is not strongly tied to Connect-AzAccount (3) it's easier to test

We can have a static helper class that handles details of authentication exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently no other place to use the TryParseUnknownAuthenticationException and its logic is very specific for login. We can extract it when we find other place can share the logic.

Comment on lines 22 to 27
* Implemented CAE by adding handler to http pipeline
* Improved error message when login is blocked by AAD
* Improved error message when silent reauthentication failed
* Enabled CAE for Get-AzTenant and Get-AzSubcription
* Enabled CAE for MSGraph
* Added test cases
Copy link
Member

Choose a reason for hiding this comment

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

A few suggestions on the changelogs: (1) use the full term "continuous access evaluation" for the first appearance of "CAE" (2) hide implementation details that are not so useful to the customers (such as adding handler and test cases)

@msJinLei msJinLei requested a review from isra-fel January 26, 2022 19:40
@wyunchi-ms wyunchi-ms changed the base branch from main to release-2022-02-08 January 27, 2022 02:52
Copy link
Member

@isra-fel isra-fel left a comment

Choose a reason for hiding this comment

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

LGTM. Have you tested the autorest-based modules manually?

@dingmeng-xue dingmeng-xue removed this from the Jan 2022 (2022-02-08) milestone Jan 27, 2022
@@ -115,8 +117,7 @@ public void OnNewRequest(InvocationInfo invocationInfo, string correlationId, st
{
endpointResourceIdKey = endpointResourceIdKey ?? AzureEnvironment.Endpoint.ResourceManager;
var context = GetDefaultContext(_provider, invocationInfo);
await AuthorizeRequest(context, request, cancelToken, endpointResourceIdKey, endpointSuffixKey, tokenAudienceConverter);
return await next(request, cancelToken, cancelAction, signal);
Copy link
Member

Choose a reason for hiding this comment

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

As we disscussed in today's meeting, we would like to revisit the part of the design related to autorest -- instead of adding CAE logic to the AddAuthorizeRequestHandler method, which has little to do with CAE, it seems better to spilt that into a new handler specially for CAE.

However, redoing authentication requires information about the access token (such as environment, audience). If the logic is departed from authentication, how does it get those info?

A second concern is about calling next(). We want to retry the failed request by calling next() for the second time (line 211), however if there are more handlers after this one, those handlers will be called twice against the same http request, which may have side-effect such as duplicated HTTP header. Is there a way allowing us to resend the request without duplicately calling the handlers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we disscussed in today's meeting, we would like to revisit the part of the design related to autorest -- instead of adding CAE logic to the AddAuthorizeRequestHandler method, which has little to do with CAE, it seems better to spilt that into a new handler specially for CAE.

However, redoing authentication requires information about the access token (such as environment, audience). If the logic is departed from authentication, how does it get those info?

A second concern is about calling next(). We want to retry the failed request by calling next() for the second time (line 211), however if there are more handlers after this one, those handlers will be called twice against the same http request, which may have side-effect such as duplicated HTTP header. Is there a way allowing us to resend the request without duplicately calling the handlers?

Thanks for @isra-fel's conclusions. After the discussion with @dolauli, we find a way to seperate the authentication and reauthentication steps. However, the codes of these 2 parts are coupled, we decide to include them into one step currently.
@dolauli Could you help to review the related codes?

Thanks

msJinLei and others added 5 commits February 7, 2022 18:09
* prototype for CAE

* CAE issue fix

* Improved error message when login is blocked by AAD
* Improved error message when silent reauthentication failed
* Enable CAE for Get-AzTenant and Get-AzSubcription
* Add test case

Co-authored-by: Erich(Renyong) Wang <[email protected]>
@msJinLei msJinLei changed the base branch from release-2022-02-08 to main February 7, 2022 10:22
@msJinLei msJinLei requested a review from isra-fel February 7, 2022 10:40
@isra-fel
Copy link
Member

isra-fel commented Feb 8, 2022

/azp run azure-powershell - powershell-core

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@msJinLei
Copy link
Contributor Author

msJinLei commented Feb 8, 2022

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

@msJinLei msJinLei requested a review from dolauli February 9, 2022 00:14
Copy link
Contributor

@dolauli dolauli left a comment

Choose a reason for hiding this comment

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

LGTM

@isra-fel
Copy link
Member

isra-fel commented Feb 9, 2022

/azp run azure-powershell - powershell-core

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@isra-fel
Copy link
Member

/azp run azure-powershell - powershell-core

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@msJinLei msJinLei merged commit 6518976 into Azure:main Feb 10, 2022
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.

5 participants