Skip to content

[KeyVault] Add KeySize support for Key Vault key outputs#29780

Open
MaddyMicrosoft wants to merge 6 commits into
Azure:mainfrom
MaddyMicrosoft:keyvault-add-keysize-support
Open

[KeyVault] Add KeySize support for Key Vault key outputs#29780
MaddyMicrosoft wants to merge 6 commits into
Azure:mainfrom
MaddyMicrosoft:keyvault-add-keysize-support

Conversation

@MaddyMicrosoft

@MaddyMicrosoft MaddyMicrosoft commented Jun 30, 2026

Copy link
Copy Markdown
Member

Description

Related to https://github.com/Azure/CLIPS/issues/303
Previously Get-AzKeyVaultKey only returned a KeySize for software-backed
RSA keys — RSA-HSM, oct, and oct-HSM keys always came back with KeySize
blank. This PR wires the new KeyProperties.KeySize field (added in
Azure.Security.KeyVault.Keys 4.10.0) through the PS models so all key
types the service reports a size for surface it consistently.

What changed

  • Upgraded Azure.Security.KeyVault.Keys from 4.6.0-beta.1 to 4.10.0
    to pick up KeyProperties.KeySize.
  • Track 2 paths (PSKeyVaultKey, PSDeletedKeyVaultKey,
    PSKeyVaultKeyIdentityItem) now read key.Properties.KeySize directly
    from the service — no client-side computation.
  • Track 1 paths kept their original behaviour: JwkHelper.ConvertToRSAKey
    continues to compute size for RSA keys only. No new Track 1 behaviour.
  • PSKeyVaultKeyIdentityItem gained a KeySize property so
    Get-AzKeyVaultKey (list view) includes the size when the service reports
    it. Format file (KeyVault.format.ps1xml) updated to display it.

What deliberately did not change

  • EC and EC-HSM keys continue to have a null KeySize. The Key Vault
    service intentionally does not return key_size for EC keys, and
    fabricating one from the curve bit-length would be misleading —
    P-256 (secp256r1) and P-256K (secp256k1) are both 256-bit curves
    but are mathematically distinct cryptosystems (y² = x³ − 3x + b vs
    y² = x³ + 7). Consumers should use CurveName to identify EC keys.
    Reviewed and confirmed with the KeyVault team.
  • oct-HSM key material is never returned to the client, so client-side
    computation from K would always yield null anyway — we rely on
    Properties.KeySize from the service, which handles this correctly.

Behaviour summary

Key type Before After
RSA (software) populated populated
RSA-HSM blank populated
oct (software) blank populated
oct-HSM blank populated
EC / EC-HSM blank blank (intentional — use CurveName)
Get-AzKeyVaultKey list view no KeySize field KeySize field where the service reports it

Testing

  • 15 new unit tests in JwkHelperKeySizeTests.cs covering Track 1 RSA
    computation, Track 1 non-RSA null behaviour, Track 2 direct
    Properties.KeySize reads, Track 2 null-service fallback (must stay
    null), and identity-item population.
  • Full existing KeyVault unit + model suite still green (129 / 129).
  • Live-validated against a Premium AKV vault: RSA (2048/3072/4096),
    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 as
    described in the table above.

Mandatory Checklist

  • Please choose the target release of Azure PowerShell.

    • General release
    • Public preview
    • Private preview
    • Engineering build
    • No need for a release
  • Check this box to confirm: I have read the Submitting Changes section of CONTRIBUTING.md and reviewed the following information:

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.
Copilot AI review requested due to automatic review settings June 30, 2026 00:13
@azure-client-tools-bot-prd

Copy link
Copy Markdown
Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 KeySize on PSKeyVaultKeyIdentityItem so Get-AzKeyVaultKey list 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.Keys to 4.10.0 and 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.

Comment thread src/KeyVault/KeyVault/Models/Key/PSKeyVaultKeyIdentityItem.cs Outdated
Comment thread src/KeyVault/KeyVault/Helpers/JwkHelper.cs Outdated
Comment thread src/KeyVault/KeyVault/ChangeLog.md Outdated
Copilot AI review requested due to automatic review settings June 30, 2026 04:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/KeyVault/KeyVault/ChangeLog.md Outdated
Comment thread src/CosmosDB/CosmosDB/ChangeLog.md
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 1, 2026 03:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/KeyVault/KeyVault/ChangeLog.md Outdated
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>
Copilot AI review requested due to automatic review settings July 3, 2026 01:49
if (string.Equals(curveName, JsonWebKeyCurveName.P256, StringComparison.OrdinalIgnoreCase) ||
string.Equals(curveName, JsonWebKeyCurveName.P256K, StringComparison.OrdinalIgnoreCase))
{
return 256;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Magic numbers here, but this is the only place we will need these constants so all good

notyashhh
notyashhh previously approved these changes Jul 3, 2026

@notyashhh notyashhh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

‼️ DO NOT MERGE THIS PR ‼️
This PR was labeled "Do Not Merge" because it contains code change that cannot be merged. Please contact the reviewer for more information.

@notyashhh

Copy link
Copy Markdown
Member

DO NOT MERGE until our current release PR has merged (7th July)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment on lines 127 to +130
public Hashtable Tags { get; set; }

public int? KeySize { get; set; }

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.

3 participants