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

Implementation for SNI + MTLS Flow in MSAL #4965

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

gladjohn
Copy link
Contributor

@gladjohn gladjohn commented Oct 22, 2024

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 mTLS

  • ESTS 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

  • unit tests
  • waiting for ests implementation and then add integ tests

Performance impact

Documentation

  • Todo : need to update docs for MTLS POP

internal static class RequestTokenType
{
public const string Bearer = "bearer";
public const string MTLSPop = "mtls_pop";
Copy link
Member

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.

@gladjohn
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@gladjohn
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@gladjohn
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@gladjohn
Copy link
Contributor Author

gladjohn commented Nov 2, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@bgavrilMS
Copy link
Member

When can we review this @gladjohn ? Are there unit tests ?

@gladjohn
Copy link
Contributor Author

gladjohn commented Nov 4, 2024

When can we review this @gladjohn ? Are there unit tests ?

@bgavrilMS working on adding unit tests., I should have PR updated by EOD tomorrow

@gladjohn
Copy link
Contributor Author

gladjohn commented Nov 5, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@gladjohn
Copy link
Contributor Author

gladjohn commented Nov 5, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@gladjohn gladjohn changed the title [draft] sni + mtls Implementation for SNI + MTLS Flow in MSAL Nov 5, 2024
@gladjohn gladjohn marked this pull request as ready for review November 5, 2024 20:07
@gladjohn gladjohn requested a review from a team as a code owner November 5, 2024 20:07
/// <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]
Copy link
Member

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

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

@bgavrilMS bgavrilMS Nov 6, 2024

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,
Copy link
Member

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"];
Copy link
Member

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

@bgavrilMS bgavrilMS Nov 6, 2024

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

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

@bgavrilMS bgavrilMS Nov 6, 2024

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// 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>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// <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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// <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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// <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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// <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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// <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.

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.

[Engineering task] Implement and Test SNI + MTLS Flow in MSAL
4 participants