-
Notifications
You must be signed in to change notification settings - Fork 373
Imdsv2: Generate CSR and execute CSR request #5427
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 32 commits into
rginsburg/msiv2_feature_branch
from
rginsburg/msiv2_csr
Aug 27, 2025
Merged
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
5498968
Initial commit. 2 TODOs
Robbie-Microsoft e04e408
Merge branch 'rginsburg/msiv2_feature_branch' into rginsburg/msiv2_csr
Robbie-Microsoft 4e096b7
Merge branch 'rginsburg/msiv2_feature_branch' into rginsburg/msiv2_csr
Robbie-Microsoft 6bc2164
Implemented CSR generator
Robbie-Microsoft 762ccdf
first pass at improved unit tests
Robbie-Microsoft 4ea6c09
Finished improving unit tests
Robbie-Microsoft 009f948
Updates to CUID
Robbie-Microsoft 21d4ef3
Unit test improvements
Robbie-Microsoft cd013a3
Implemented Feedback
Robbie-Microsoft 480ae9e
renamed file
Robbie-Microsoft 0aa8692
small improvement
Robbie-Microsoft 621c566
added missing awaitor for async method
Robbie-Microsoft 068461b
Fixed bugs discovered from unit testing in child branch
Robbie-Microsoft 2034b25
undid changes to .proj
Robbie-Microsoft 2b7486a
undid change to global.json
Robbie-Microsoft 189ff9e
added missing sets
Robbie-Microsoft 92b325f
Inplemented some feedback
Robbie-Microsoft 067c83c
Implemented some feedback
Robbie-Microsoft f7d6f88
PKCS1 -> Pss padding
Robbie-Microsoft 74e8e60
re-used imports
Robbie-Microsoft 152f396
Implemented feedback
Robbie-Microsoft d46c853
Changes from manual testing.
Robbie-Microsoft 3f75e3a
ImdsV2: Reworked Custom ASN1 Encoder to use System.Formats.Asn1 Nuget…
Robbie-Microsoft 253993d
Merge branch 'rginsburg/msiv2_feature_branch' into rginsburg/msiv2_csr
Robbie-Microsoft 3481c39
Implemented feedback
Robbie-Microsoft 92158bb
Small rework due to spec changes
Robbie-Microsoft 729a56a
Additional rework due to spec changes
Robbie-Microsoft 3027392
Implemented feedback
Robbie-Microsoft 3c3dcdf
Removed null check on vmId. Created CuidInfo.IsNullOrEmpty
Robbie-Microsoft f51cdf9
Implemented feedback
Robbie-Microsoft 5e7ab07
Updated min version of imds, spec has incorrect info
Robbie-Microsoft 362b407
Updated a comment
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
41 changes: 41 additions & 0 deletions
41
src/client/Microsoft.Identity.Client/ManagedIdentity/CsrRequest.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,41 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Identity.Client.ManagedIdentity | ||
{ | ||
internal class CsrRequest | ||
{ | ||
public string Pem { get; } | ||
|
||
public CsrRequest(string pem) | ||
{ | ||
Pem = pem ?? throw new ArgumentNullException(nameof(pem)); | ||
} | ||
|
||
/// <summary> | ||
/// Generates a CSR for the given client, tenant, and CUID info. | ||
/// </summary> | ||
/// <param name="clientId">Managed Identity client_id.</param> | ||
/// <param name="tenantId">AAD tenant_id.</param> | ||
/// <param name="cuid">CuidInfo object containing VMID and VMSSID.</param> | ||
/// <returns>CsrRequest containing the PEM CSR.</returns> | ||
public static CsrRequest Generate(string clientId, string tenantId, CuidInfo cuid) | ||
{ | ||
if (string.IsNullOrWhiteSpace(clientId)) | ||
throw new ArgumentException("clientId must not be null or empty.", nameof(clientId)); | ||
if (string.IsNullOrWhiteSpace(tenantId)) | ||
throw new ArgumentException("tenantId must not be null or empty.", nameof(tenantId)); | ||
if (cuid == null) | ||
throw new ArgumentNullException(nameof(cuid)); | ||
if (string.IsNullOrWhiteSpace(cuid.Vmid)) | ||
throw new ArgumentException("cuid.Vmid must not be null or empty.", nameof(cuid.Vmid)); | ||
Robbie-Microsoft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (string.IsNullOrWhiteSpace(cuid.Vmssid)) | ||
throw new ArgumentException("cuid.Vmssid must not be null or empty.", nameof(cuid.Vmssid)); | ||
|
||
// TODO: Implement the actual CSR generation logic. | ||
return new CsrRequest("pem"); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/client/Microsoft.Identity.Client/ManagedIdentity/CsrRequestResponse.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,53 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#if SUPPORTS_SYSTEM_TEXT_JSON | ||
using JsonProperty = System.Text.Json.Serialization.JsonPropertyNameAttribute; | ||
#else | ||
using Microsoft.Identity.Client.Utils; | ||
using Microsoft.Identity.Json; | ||
#endif | ||
|
||
namespace Microsoft.Identity.Client.ManagedIdentity | ||
{ | ||
/// <summary> | ||
/// Represents the response for a Managed Identity CSR request. | ||
/// </summary> | ||
internal class CsrRequestResponse | ||
Robbie-Microsoft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
[JsonProperty("client_id")] | ||
public string ClientId { get; } | ||
|
||
[JsonProperty("tenant_id")] | ||
public string TenantId { get; } | ||
|
||
[JsonProperty("client_credential")] | ||
public string ClientCredential { get; } | ||
|
||
[JsonProperty("regional_token_url")] | ||
public string RegionalTokenUrl { get; } | ||
|
||
[JsonProperty("expires_in")] | ||
public int ExpiresIn { get; } | ||
|
||
[JsonProperty("refresh_in")] | ||
public int RefreshIn { get; } | ||
|
||
public CsrRequestResponse() { } | ||
|
||
public static bool ValidateCsrRequestResponse(CsrRequestResponse csrRequestResponse) | ||
{ | ||
if (string.IsNullOrEmpty(csrRequestResponse.ClientId) || | ||
string.IsNullOrEmpty(csrRequestResponse.TenantId) || | ||
string.IsNullOrEmpty(csrRequestResponse.ClientCredential) || | ||
string.IsNullOrEmpty(csrRequestResponse.RegionalTokenUrl) || | ||
csrRequestResponse.ExpiresIn <= 0 || | ||
csrRequestResponse.RefreshIn <= 0) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
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
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.