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

Certificate authentication: Enable cert auth and start the shift away from ICredentialProvider. #2524

Merged
merged 5 commits into from
Sep 18, 2019

Conversation

carlosscastro
Copy link
Member

Enable cert-based authentication of AAD apps. Currently we only support app id + password, but AAD also supports certificates:

image

To enable this, we start some key refactors after identifying shortcomings of the current model. ICredentialProvider has 2 problems:

  1. It is used for AAD verification and for JwtToken validation, serving 2 purposes that should not necessarily be coupled
  2. It assumes that the authentication is based on password (evident by the GetAppPassowrd() method in the interface)

To overcome this, this is the small first step towards using AppCredentials for AAD verifications, which currently supports Certs or Password, but as-is can simply be extended to support any of the 7 ADAL client flows.

The default paths still use ICredentialProvider and we are enabling AppCredentials for new scenarios. A second iteration will make AppCredentials be the default, but we want to stage that transition to minimize risk.

@coveralls
Copy link
Collaborator

coveralls commented Sep 16, 2019

Pull Request Test Coverage Report for Build 79473

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 25 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.7%) to 79.889%

Files with Coverage Reduction New Missed Lines %
/libraries/Microsoft.Bot.Builder.Dialogs/Prompts/OAuthPrompt.cs 1 56.41%
/libraries/Microsoft.Bot.Builder/TurnContext.cs 1 61.4%
/libraries/Microsoft.Bot.Builder.Azure/CosmosDbStorageOptions.cs 2 50.0%
/libraries/Microsoft.Bot.Builder/BotFrameworkAdapter.cs 21 11.94%
Totals Coverage Status
Change from base Build 79149: -0.7%
Covered Lines: 4604
Relevant Lines: 5763

💛 - Coveralls

@fuselabs
Copy link
Collaborator

✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.Luis.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.QnA.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.ApplicationInsights.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Azure.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Dialogs.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.TemplateManager.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Configuration.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Connector.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Schema.dll compared against version 4.3.1

@fuselabs
Copy link
Collaborator

✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.Luis.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.QnA.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.ApplicationInsights.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Azure.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Dialogs.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.TemplateManager.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Configuration.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Connector.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Schema.dll compared against version 4.3.1

@carlosscastro
Copy link
Member Author

And just to set expectations, this change goes from Only App id + password can be done, to 'We natively support password or certificate authentication, but the design allows for simple extension to any other client flow supported by aad apps, only by adding a new AppCredentials subclass without any further modifications to existing abstractions.'

@carlosscastro
Copy link
Member Author

Also, tests exist but not checked in, waiting for us to figure out some build details

@fuselabs
Copy link
Collaborator

✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.Luis.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.QnA.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.ApplicationInsights.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Azure.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Dialogs.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.TemplateManager.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Configuration.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Connector.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Schema.dll compared against version 4.3.1

Copy link
Contributor

@cleemullins cleemullins left a comment

Choose a reason for hiding this comment

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

We need this in JS before we can merge it.

/// <param name="expirationTime">The expiration time after which this service url is not trusted anymore.</param>
public static void TrustServiceUrl(string serviceUrl, DateTime expirationTime)
{
lock (TrustedHostNames)
Copy link
Contributor

Choose a reason for hiding this comment

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

if the dictionary TrustedHostNames were a Concurrent Dictionary, could we eliminate these locks?

if (TrustedHostNames.TryGetValue(uri.Host, out DateTime trustedServiceUrlExpiration))
{
// check if the trusted service url is still valid
if (trustedServiceUrlExpiration > DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why "5 minutes" is a magic number. Wouldn't it simply be >= for the true/false check?

@@ -19,7 +19,7 @@ namespace Microsoft.Bot.Connector.Authentication
/// <summary>
/// MicrosoftAppCredentials auth implementation and cache.
/// </summary>
public class MicrosoftAppCredentials : ServiceClientCredentials
public class MicrosoftAppCredentials : AppCredentials
Copy link
Contributor

Choose a reason for hiding this comment

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

From an OO perspective, this is certainly legit. I think it as as well from a .NET compat perspetive.

@cleemullins
Copy link
Contributor

This dropped code coverage by 3%. Can you please add relevant tests to get back to the basleine number?

@fuselabs
Copy link
Collaborator

✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.Luis.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.QnA.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.ApplicationInsights.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Azure.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Dialogs.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.TemplateManager.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Configuration.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Connector.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Schema.dll compared against version 4.3.1

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.

None yet

4 participants