-
Notifications
You must be signed in to change notification settings - Fork 378
ImdsV2: Acquire Entra Token Over mTLS #5431
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
ImdsV2: Acquire Entra Token Over mTLS #5431
Conversation
src/client/Microsoft.Identity.Client/ManagedIdentity/ImdsV2ManagedIdentitySource.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ManagedIdentity/ImdsV2ManagedIdentitySource.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ManagedIdentity/ImdsV2ManagedIdentitySource.cs
Outdated
Show resolved
Hide resolved
…quire_entra_token
src/client/Microsoft.Identity.Client/ManagedIdentity/V2/ImdsV2ManagedIdentitySource.cs
Outdated
Show resolved
Hide resolved
| /// <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) |
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.
You could move all this X509 related code to the existing CommonCryptographyManager
src/client/Microsoft.Identity.Client/ManagedIdentity/V2/ImdsV2ManagedIdentitySource.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ManagedIdentity/V2/ImdsV2ManagedIdentitySource.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ManagedIdentity/V2/ImdsV2ManagedIdentitySource.cs
Outdated
Show resolved
Hide resolved
src/client/Microsoft.Identity.Client/ManagedIdentity/V2/ImdsV2ManagedIdentitySource.cs
Outdated
Show resolved
Hide resolved
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.
Approved with comments
…quire_entra_token
ddc2117
into
rginsburg/msiv2_feature_branch
| .ExecuteAsync().ConfigureAwait(false); | ||
|
|
||
| Assert.IsNotNull(result); | ||
| Assert.IsNotNull(result.AccessToken); |
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.
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 -
Line 232 in 7890844
| { |
and here are some existing tests -
Line 28 in 7890844
| new RequestContext(harness.ServiceBundle, Guid.NewGuid(), null), addCommonHeaders: true, onBeforePostRequestHandler: 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.
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?
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.
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.
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
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 is still very unclear to me
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.
I've found another way to check the headers. My PR is here: #5459
| .ExecuteAsync().ConfigureAwait(false); | ||
|
|
||
| Assert.IsNotNull(result); | ||
| Assert.IsNotNull(result.AccessToken); |
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.
can we also ensure the mtls cert is being returned in the result

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