Skip to content

Conversation

@Robbie-Microsoft
Copy link
Contributor

@Robbie-Microsoft Robbie-Microsoft commented Aug 8, 2025

Finishing up the remainder of the flow for ImdsV2... this PR builds the request to acquire the entra token over mTLS.

@Robbie-Microsoft Robbie-Microsoft marked this pull request as ready for review August 28, 2025 22:09
@Robbie-Microsoft Robbie-Microsoft requested a review from a team as a code owner August 28, 2025 22:09
@Robbie-Microsoft Robbie-Microsoft changed the title ImdsV2: Acquire Entra Token ImdsV2: Acquire Entra Token Over mTLS Aug 28, 2025
/// <exception cref="ArgumentNullException">Thrown when certificatePem or privateKey is null</exception>
/// <exception cref="ArgumentException">Thrown when certificatePem is not a valid PEM certificate</exception>
/// <exception cref="FormatException">Thrown when the certificate cannot be parsed</exception>
internal X509Certificate2 AttachPrivateKeyToCert(string certificatePem, RSA privateKey)
Copy link
Member

@bgavrilMS bgavrilMS Aug 29, 2025

Choose a reason for hiding this comment

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

You could move all this X509 related code to the existing CommonCryptographyManager

Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

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

Approved with comments

@Robbie-Microsoft Robbie-Microsoft merged commit ddc2117 into rginsburg/msiv2_feature_branch Aug 29, 2025
3 checks passed
@Robbie-Microsoft Robbie-Microsoft deleted the rginsburg/msiv2_acquire_entra_token branch August 29, 2025 22:02
.ExecuteAsync().ConfigureAwait(false);

Assert.IsNotNull(result);
Assert.IsNotNull(result.AccessToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

overall looks good. can we also assert common headers we send to ESTS. which will contain correlation id MSAL version etc.

you can see the common headers being set here -

and here are some existing tests -

new RequestContext(harness.ServiceBundle, Guid.NewGuid(), null), addCommonHeaders: true, onBeforePostRequestHandler: null);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The example you pointed me to in the tests is not clear to me. Can you please show me exactly how you would check that the headers from MsalIdHelper.GetMsalIdParameters exist in the request in the unit test?

Copy link
Contributor

@gladjohn gladjohn Sep 4, 2025

Choose a reason for hiding this comment

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

one way to check would be to run this test, (manual inspection)

Sni_Gets_Pop_Token_Successfully_TestAsync

And get the time stamp and correlation id from the logs

image

Then inspect MSAL related properties in LogsMiner.

And then you can debug that test and see where those headers are set.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please show me exactly how you would check that the headers

For unit test, you can check the headers in the outgoing request. for e.g take a look at CertificateOverrideAsync test. it uses MockHttpMessageHandler to check for ActualRequestHeaders

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is still very unclear to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've found another way to check the headers. My PR is here: #5459

.ExecuteAsync().ConfigureAwait(false);

Assert.IsNotNull(result);
Assert.IsNotNull(result.AccessToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

can we also ensure the mtls cert is being returned in the result

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.

4 participants