-
Notifications
You must be signed in to change notification settings - Fork 371
CSR Metadata request acts as a probe for ImdsV2 #5359
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
Merged
Robbie-Microsoft
merged 30 commits into
rginsburg/msiv2_feature_branch
from
rginsburg/msiv2_probe
Aug 4, 2025
Merged
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
f6f627f
Implemented ImdsV2 class and it's probe
Robbie-Microsoft cb2c763
Implemented unit tests
Robbie-Microsoft e96c630
added try/catch to network request
Robbie-Microsoft 6ffafec
Merge branch 'main' into rginsburg/msiv2_probe
Robbie-Microsoft f28b71f
Merged from main
Robbie-Microsoft b9f12b1
Merge branch 'rginsburg/msiv2_feature_branch' into rginsburg/msiv2_probe
Robbie-Microsoft 6aa43d0
Refactored ManagedIdentityClient
Robbie-Microsoft c2a8282
Renamed variable since it's no longer static
Robbie-Microsoft da727eb
ManagedIdentityClient's identitySource and sourceName are now static,…
Robbie-Microsoft 3588084
Fixed many broken unit tests
Robbie-Microsoft ba43757
ManagedIdentityClient is now per ManagedIdentityApplication instead o…
Robbie-Microsoft 78730ba
Merge branch 'rginsburg/msiv2_feature_branch' into rginsburg/msiv2_probe
Robbie-Microsoft 9706db6
Merge branch 'rginsburg/msiv2_feature_branch' into rginsburg/msiv2_probe
Robbie-Microsoft d894554
Implemented some GitHub feedback
Robbie-Microsoft 71a654e
Refactored GetCsrMetadataAsync method into smaller methods
Robbie-Microsoft 7450081
Implemented some GitHub feedback and fixed rebase errors
Robbie-Microsoft 8ddfe93
Small updates and fixed some unit tests
Robbie-Microsoft 3783f3d
undo changes to global.json
Robbie-Microsoft f986c51
Refactor. All unit tests pass now.
Robbie-Microsoft c7af31c
Implemented some feedback + improvements
Robbie-Microsoft 1d3d3db
Implemented some feedback
Robbie-Microsoft 80215a3
CsrMetadata follows new spec now
Robbie-Microsoft 3a1dfe2
IMDSv2: Created a retry policy for the CSR Metadata Probe (#5419)
Robbie-Microsoft 24bccf7
removed unused imports in test file
Robbie-Microsoft 8788b51
Fixed minor spec issue
Robbie-Microsoft f0589c1
Implemented some feedback
Robbie-Microsoft cb2647e
refactored Imds UAMI id switch statement
Robbie-Microsoft 1398d92
Implemented feedback
Robbie-Microsoft 961d787
undid changes to global.json
Robbie-Microsoft 56742cd
Implemented final feedback
Robbie-Microsoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/client/Microsoft.Identity.Client/Http/Retry/CsrMetadataProbeRetryPolicy.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Identity.Client.Http.Retry | ||
{ | ||
internal class CsrMetadataProbeRetryPolicy : ImdsRetryPolicy | ||
{ | ||
protected override bool ShouldRetry(HttpResponse response, Exception exception) | ||
{ | ||
return HttpRetryConditions.CsrMetadataProbe(response, exception); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/client/Microsoft.Identity.Client/ManagedIdentity/CsrMetadata.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#if SUPPORTS_SYSTEM_TEXT_JSON | ||
using Microsoft.Identity.Client.Platforms.net; | ||
using JsonProperty = System.Text.Json.Serialization.JsonPropertyNameAttribute; | ||
#else | ||
using Microsoft.Identity.Json; | ||
#endif | ||
|
||
namespace Microsoft.Identity.Client.ManagedIdentity | ||
{ | ||
/// <summary> | ||
/// Represents metadata required for Certificate Signing Request (CSR) operations. | ||
/// </summary> | ||
internal class CsrMetadata | ||
{ | ||
/// <summary> | ||
/// VM unique Id | ||
/// </summary> | ||
[JsonProperty("cuid")] | ||
public CuidInfo Cuid { get; set; } | ||
|
||
/// <summary> | ||
/// client_id of the Managed Identity | ||
/// </summary> | ||
[JsonProperty("clientId")] | ||
public string ClientId { get; set; } | ||
|
||
/// <summary> | ||
/// AAD Tenant of the Managed Identity | ||
/// </summary> | ||
[JsonProperty("tenantId")] | ||
public string TenantId { get; set; } | ||
|
||
/// <summary> | ||
/// MAA Regional / Custom Endpoint for attestation purposes. | ||
/// </summary> | ||
[JsonProperty("attestationEndpoint")] | ||
public string AttestationEndpoint { get; set; } | ||
|
||
// Parameterless constructor for deserialization | ||
public CsrMetadata() { } | ||
|
||
/// <summary> | ||
/// Validates a JSON decoded CsrMetadata instance. | ||
/// </summary> | ||
/// <param name="csrMetadata">The CsrMetadata object.</param> | ||
/// <returns>false if any field is null.</returns> | ||
public static bool ValidateCsrMetadata(CsrMetadata csrMetadata) | ||
{ | ||
if (csrMetadata == null || | ||
csrMetadata.Cuid == null || | ||
string.IsNullOrEmpty(csrMetadata.Cuid.Vmid) || | ||
string.IsNullOrEmpty(csrMetadata.Cuid.Vmssid) || | ||
string.IsNullOrEmpty(csrMetadata.ClientId) || | ||
string.IsNullOrEmpty(csrMetadata.TenantId) || | ||
string.IsNullOrEmpty(csrMetadata.AttestationEndpoint)) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Represents VM unique Ids for CSR metadata. | ||
/// </summary> | ||
internal class CuidInfo | ||
Robbie-Microsoft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
[JsonProperty("vmid")] | ||
public string Vmid { get; set; } | ||
|
||
[JsonProperty("vmssid")] | ||
public string Vmssid { get; set; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.