[KeyVault] Add KeySize support for Key Vault key outputs#29780
Open
MaddyMicrosoft wants to merge 6 commits into
Open
[KeyVault] Add KeySize support for Key Vault key outputs#29780MaddyMicrosoft wants to merge 6 commits into
MaddyMicrosoft wants to merge 6 commits into
Conversation
Track2 paths read KeyProperties.KeySize directly (added in SDK 4.10.0). - Track1 and fallback paths derive the size locally via JwkHelper: RSA from modulus length, oct from symmetric-key length, EC from the named curve. - KeySize is also surfaced on PSKeyVaultKeyIdentityItem so it appears in the Get-AzKeyVaultKey list view (note: the service omits key_size from list responses for EC keys, so list output for those remains blank). Upgrades Azure.Security.KeyVault.Keys 4.6.0-beta.1 -> 4.10.0. Adds 49 unit tests covering every Kty, curve and null-material edge case. Live- validated end-to-end against a Premium AKV vault.
| Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status. |
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates the Key Vault key PowerShell models and formatting to surface KeySize consistently across Track1 and Track2 SDK paths, aligning with newer Azure.Security.KeyVault.Keys behavior and adding unit coverage for key-size derivation.
Changes:
- Surfaced
KeySizeonPSKeyVaultKeyIdentityItemsoGet-AzKeyVaultKeylist output can display key sizes when available. - Added local key-size derivation for Track1 / fallback scenarios via
JwkHelper.ComputeKeySize(RSA modulus bytes, oct key bytes, EC curve mapping). - Upgraded
Azure.Security.KeyVault.Keysto4.10.0and introduced comprehensive unit tests for key-size behavior and wiring.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/KeyVault/KeyVault/Models/Key/PSKeyVaultKeyIdentityItem.cs | Adds KeySize to the shared identity model and wires Track2 KeyProperties.KeySize into list items. |
| src/KeyVault/KeyVault/Models/Key/PSKeyVaultKey.cs | Uses Track2 KeyProperties.KeySize when present; otherwise computes from JWK material. |
| src/KeyVault/KeyVault/Models/Key/PSDeletedKeyVaultKey.cs | Mirrors the KeySize preference/fallback behavior for deleted key models, including null-material cases. |
| src/KeyVault/KeyVault/KeyVault.format.ps1xml | Updates list formatting to display KeySize. |
| src/KeyVault/KeyVault/KeyVault.csproj | Updates Azure.Security.KeyVault.Keys dependency version to 4.10.0. |
| src/KeyVault/KeyVault/Helpers/JwkHelper.cs | Introduces ComputeKeySize and key-type helpers for Track1/fallback derivation. |
| src/KeyVault/KeyVault/ChangeLog.md | Documents the behavior and dependency update in the KeyVault module changelog. |
| src/KeyVault/KeyVault.Test/UnitTests/JwkHelperKeySizeTests.cs | Adds unit tests covering key-size derivation and Track2 KeyProperties.KeySize wiring. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
+47
to
+50
| private const string VaultDnsSuffix = "vault.azure.net"; | ||
| private const string HsmDnsSuffix = "managedhsm.azure.net"; | ||
| private const string OctHsm = "oct-HSM"; | ||
|
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
notyashhh
reviewed
Jul 3, 2026
| if (string.Equals(curveName, JsonWebKeyCurveName.P256, StringComparison.OrdinalIgnoreCase) || | ||
| string.Equals(curveName, JsonWebKeyCurveName.P256K, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return 256; |
Member
There was a problem hiding this comment.
Magic numbers here, but this is the only place we will need these constants so all good
|
|
Member
|
DO NOT MERGE until our current release PR has merged (7th July) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Related to https://github.com/Azure/CLIPS/issues/303
Previously
Get-AzKeyVaultKeyonly returned aKeySizefor software-backedRSA keys — RSA-HSM, oct, and oct-HSM keys always came back with
KeySizeblank. This PR wires the new
KeyProperties.KeySizefield (added inAzure.Security.KeyVault.Keys4.10.0) through the PS models so all keytypes the service reports a size for surface it consistently.
What changed
Azure.Security.KeyVault.Keysfrom4.6.0-beta.1to4.10.0to pick up
KeyProperties.KeySize.PSKeyVaultKey,PSDeletedKeyVaultKey,PSKeyVaultKeyIdentityItem) now readkey.Properties.KeySizedirectlyfrom the service — no client-side computation.
JwkHelper.ConvertToRSAKeycontinues to compute size for RSA keys only. No new Track 1 behaviour.
PSKeyVaultKeyIdentityItemgained aKeySizeproperty soGet-AzKeyVaultKey(list view) includes the size when the service reportsit. Format file (
KeyVault.format.ps1xml) updated to display it.What deliberately did not change
KeySize. The Key Vaultservice intentionally does not return
key_sizefor EC keys, andfabricating one from the curve bit-length would be misleading —
P-256(secp256r1) andP-256K(secp256k1) are both 256-bit curvesbut are mathematically distinct cryptosystems (
y² = x³ − 3x + bvsy² = x³ + 7). Consumers should useCurveNameto identify EC keys.Reviewed and confirmed with the KeyVault team.
computation from
Kwould always yield null anyway — we rely onProperties.KeySizefrom the service, which handles this correctly.Behaviour summary
CurveName)Get-AzKeyVaultKeylist viewKeySizefieldKeySizefield where the service reports itTesting
JwkHelperKeySizeTests.cscovering Track 1 RSAcomputation, Track 1 non-RSA null behaviour, Track 2 direct
Properties.KeySizereads, Track 2 null-service fallback (must staynull), and identity-item population.
EC (P-256/P-384/P-521/P-256K), RSA-HSM, EC-HSM, oct-HSM 256, and the
deleted-key path (
Get-AzKeyVaultKey -InRemovedState) all behave asdescribed in the table above.
Mandatory Checklist
Please choose the target release of Azure PowerShell.
Check this box to confirm: I have read the Submitting Changes section of
CONTRIBUTING.mdand reviewed the following information: