-
Notifications
You must be signed in to change notification settings - Fork 340
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
Implementation for SNI + MTLS Flow in MSAL #4965
base: main
Are you sure you want to change the base?
Conversation
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ApiConfig/Executors/ConfidentialClientExecutor.cs
Outdated
Show resolved
Hide resolved
...oft.Identity.Client/ApiConfig/Parameters/AbstractAcquireTokenConfidentialClientParameters.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/AppConfig/ApplicationConfiguration.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/AuthScheme/PoP/MtlsPopAuthenticationOperation.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/AuthScheme/PoP/MtlsPopAuthenticationOperation.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/AuthScheme/PoP/MtlsPopAuthenticationOperation.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/AuthScheme/PoP/MtlsPopAuthenticationOperation.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Instance/Discovery/RegionDiscoveryProvider.cs
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Instance/Discovery/RegionDiscoveryProvider.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Instance/Discovery/RegionDiscoveryProvider.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs
Outdated
Show resolved
Hide resolved
internal static class RequestTokenType | ||
{ | ||
public const string Bearer = "bearer"; | ||
public const string MTLSPop = "mtls_pop"; |
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.
Pls consolidate with SHR POP.
...s/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/ClientCredentialsTests.NetFwk.cs
Outdated
Show resolved
Hide resolved
...s/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/ClientCredentialsTests.NetFwk.cs
Outdated
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
When can we review this @gladjohn ? Are there unit tests ? |
...icrosoft.Identity.Client/ApiConfig/AbstractConfidentialClientAcquireTokenParameterBuilder.cs
Show resolved
Hide resolved
...icrosoft.Identity.Client/ApiConfig/AbstractConfidentialClientAcquireTokenParameterBuilder.cs
Outdated
Show resolved
Hide resolved
...icrosoft.Identity.Client/ApiConfig/AbstractConfidentialClientAcquireTokenParameterBuilder.cs
Outdated
Show resolved
Hide resolved
@bgavrilMS working on adding unit tests., I should have PR updated by EOD tomorrow |
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/AuthScheme/PoP/MtlsPopAuthenticationOperation.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/AuthScheme/PoP/MtlsPopAuthenticationOperation.cs
Outdated
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/// <item><description>The PoP token is bound to the HTTP request, more specifically to the HTTP method (GET, POST, etc.) and to the Uri (path and query, but not query parameters).</description></item> | ||
/// <item><description>MSAL creates, reads and stores a key in memory that will be cycled every 8 hours.</description></item> | ||
/// <item><description>This is an experimental API. The method signature may change in the future without involving a major version upgrade.</description></item> | ||
/// </list> | ||
/// </remarks> | ||
[EditorBrowsable(EditorBrowsableState.Never)] // Soft deprecate | ||
[Obsolete] |
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.
Pls add an error message explaining the rename.
/// MTLS Pop token type. | ||
/// MTLS_Pop = 5 | ||
/// </summary> | ||
Mtls_Pop = 5 |
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.
Extension
is 5, this needs to be at least 6.
return $"{region}.{host}"; | ||
|
||
// Decide whether to use MTLS or standard environment | ||
if (!requestContext.UseMtlsPop) |
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.
In region is configured by app developer, and public cloud is used, then the regional env will be returned at line 65. So it will ignore mTLS endpoint.
This shows there is insufficient unit testing in this area.
@@ -32,6 +32,12 @@ internal enum TokenType | |||
/// Extension token type. | |||
/// Extension = 5 | |||
/// </summary> | |||
Extension = 5 | |||
Extension = 5, |
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.
unrelated - @trwalke, what will happen if we create another extension ?
@@ -17,18 +17,21 @@ namespace Microsoft.Identity.Test.Unit.ExceptionTests | |||
[TestClass] | |||
public class ExperimentalFeatureTests | |||
{ | |||
private static readonly string[] s_scopes = ["scope"]; |
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.
nit: I am generally a fan of refactoring, but it's making life harder for reviewers. Next time, pls try to separate out refactoring either in a separate PR or in a separate commit.
[TestCleanup] | ||
public override void TestCleanup() | ||
{ | ||
Environment.SetEnvironmentVariable("REGION_NAME", null); |
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.
Not a good idea. This is set to some value when running on ADO agent.
See how all the MSI unit tests are doing it instead.
|
||
Assert.AreEqual("header.payload.signature", result.AccessToken); | ||
Assert.AreEqual(region, result.ApiEvent.RegionUsed); | ||
Assert.AreEqual(RegionOutcome.UserProvidedValid, result.ApiEvent.RegionOutcome); |
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.
No need to use ApiEvent to check this. Use result.Metadata
.ConfigureAwait(false); | ||
|
||
Assert.AreEqual("header.payload.signature", result.AccessToken); | ||
Assert.AreEqual(region, result.ApiEvent.RegionUsed); |
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.
Use result.AuthenticationResultMetadata.TokenEndpoint to check the mTLS endpoint. This is a comment for all tests
@@ -89,5 +91,29 @@ public T WithProofOfPossession(PoPAuthenticationConfiguration popAuthenticationC | |||
|
|||
return this as T; | |||
} | |||
|
|||
/// <summary> | |||
/// Modifies the token acquisition request so that the acquired token is a Signed HTTP Request (SHR) Proof-of-Possession (PoP) token, rather than a Bearer token. |
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.
/// Modifies the token acquisition request so that the acquired token is a Signed HTTP Request (SHR) Proof-of-Possession (PoP) token, rather than a Bearer token. | |
/// Modifies the request to acquire a Signed HTTP Request (SHR) Proof-of-Possession (PoP) token, rather than a Bearer. |
|
||
/// <summary> | ||
/// Modifies the token acquisition request so that the acquired token is a Signed HTTP Request (SHR) Proof-of-Possession (PoP) token, rather than a Bearer token. | ||
/// SHR PoP tokens are bound to the HTTP request and to a cryptographic key, which MSAL can manage 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.
/// SHR PoP tokens are bound to the HTTP request and to a cryptographic key, which MSAL can manage on Windows. | |
/// SHR PoP tokens are bound to the HTTP request and to a cryptographic key, which MSAL manages on Windows. |
/// <summary> | ||
/// Modifies the token acquisition request so that the acquired token is a Signed HTTP Request (SHR) Proof-of-Possession (PoP) token, rather than a Bearer token. | ||
/// SHR PoP tokens are bound to the HTTP request and to a cryptographic key, which MSAL can manage on Windows. | ||
/// This differs from MTLS PoP tokens, which are used for Mutual TLS (mTLS) authentication. See <see href="https://aka.ms/mtls-pop"/> for mTLS PoP details. |
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 differs from MTLS PoP tokens, which are used for Mutual TLS (mTLS) authentication. See <see href="https://aka.ms/mtls-pop"/> for mTLS PoP details. | |
/// SHR PoP tokens are different from mTLS PoP tokens, which are used for Mutual TLS (mTLS) authentication. See <see href="https://aka.ms/mtls-pop"/> for details. |
/// Modifies the token acquisition request so that the acquired token is a Signed HTTP Request (SHR) Proof-of-Possession (PoP) token, rather than a Bearer token. | ||
/// SHR PoP tokens are bound to the HTTP request and to a cryptographic key, which MSAL can manage on Windows. | ||
/// This differs from MTLS PoP tokens, which are used for Mutual TLS (mTLS) authentication. See <see href="https://aka.ms/mtls-pop"/> for mTLS PoP details. | ||
/// See <see href="https://aka.ms/msal-net-pop"/> for general PoP token information. |
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.
/// See <see href="https://aka.ms/msal-net-pop"/> for general PoP token information. |
This is not needed because the previous link points to the exact same page.
/// <returns>The builder.</returns> | ||
/// <remarks> | ||
/// <list type="bullet"> | ||
/// <item><description>The SHR PoP token is bound to the HTTP request, more specifically to the HTTP method (GET, POST, etc.) and to the URI (path and query, but not query parameters).</description></item> |
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.
/// <item><description>The SHR PoP token is bound to the HTTP request, more specifically to the HTTP method (GET, POST, etc.) and to the URI (path and query, but not query parameters).</description></item> | |
/// <item><description>The SHR PoP token is bound to the HTTP request, specifically to the HTTP method (for example, `GET` or `POST`) and to the URI path and query, excluding query parameters.</description></item> |
@@ -428,5 +428,18 @@ public static string InvalidTokenProviderResponseValue(string invalidValueName) | |||
public const string SetCiamAuthorityAtRequestLevelNotSupported = "Setting the CIAM authority (ex. \"{tenantName}.ciamlogin.com\") at the request level is not supported. The CIAM authority must be set during application creation"; | |||
public const string ClaimsChallenge = "The returned error contains a claims challenge. For additional info on how to handle claims related to multifactor authentication, Conditional Access, and incremental consent, see https://aka.ms/msal-conditional-access-claims. If you are using the On-Behalf-Of flow, see https://aka.ms/msal-conditional-access-claims-obo for details."; | |||
public const string CryptographicError = "A cryptographic exception occurred. Possible cause: the certificate has been disposed. See inner exception for full details."; | |||
|
|||
/// <summary> | |||
/// MTLS Proof of Possession (PoP) requires a region to be specified in the configuration. |
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.
/// MTLS Proof of Possession (PoP) requires a region to be specified in the configuration. | |
/// mTLS Proof-of-Possession (PoP) requires a region to be specified in the configuration. |
|
||
/// <summary> | ||
/// MTLS Proof of Possession (PoP) requires a region to be specified in the configuration. | ||
/// <para>What happens?</para> You have enabled MTLS PoP, but no region is specified. |
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.
/// <para>What happens?</para> You have enabled MTLS PoP, but no region is specified. | |
/// <para>What happened?</para> You enabled mTLS PoP but no region was specified. |
/// <summary> | ||
/// MTLS Proof of Possession (PoP) requires a region to be specified in the configuration. | ||
/// <para>What happens?</para> You have enabled MTLS PoP, but no region is specified. | ||
/// <para>Mitigation</para> Ensure that a region is set when using MTLS PoP by configuring AzureRegion in the application. |
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.
/// <para>Mitigation</para> Ensure that a region is set when using MTLS PoP by configuring AzureRegion in the application. | |
/// <para>Mitigation</para> Ensure that a region is set when using mTLS PoP by configuring `AzureRegion` in the application. |
public const string MtlsPopWithoutRegion = "MTLS Proof of Possession requires a region to be specified. Please set AzureRegion in the configuration at the application level."; | ||
|
||
/// <summary> | ||
/// <para>What happens?</para> MTLS Proof of Possession requires a certificate to be configured. |
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.
/// <para>What happens?</para> MTLS Proof of Possession requires a certificate to be configured. | |
/// <para>What happened?</para> mTLS Proof-of-Possession requires a certificate to be configured. |
|
||
/// <summary> | ||
/// <para>What happens?</para> MTLS Proof of Possession requires a certificate to be configured. | ||
/// <para>Mitigation</para> Provide a certificate in the configuration to enable MTLS PoP. This is required to perform mutual TLS. |
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.
/// <para>Mitigation</para> Provide a certificate in the configuration to enable MTLS PoP. This is required to perform mutual TLS. | |
/// <para>Mitigation</para> Provide a certificate in the configuration to enable mTLS PoP. |
Fixes : #4986
Changes proposed in this request
When
.WithCertificate
API is used and if the new.WithMtlsPop...
API is used at request level, we now use that cert over mTLSESTS on the other hand, will use the mTLS cert as the auth cert in this client credentials flow
MSAL will simply pass the client id and the MTLS cert and will also specify that the
token type = mtls_pop
and ESTS will issue a token that will contain the cnf claim in it.Todo : need to test passing X5C and skipping it when ESTS is ready to observe errors they send
Testing
Performance impact
Documentation