VOOZH about

URL: https://www.nuget.org/packages/Azure.Security.KeyVault.Administration

⇱ NuGet Gallery | Azure.Security.KeyVault.Administration 4.8.0




👁 Image
Azure.Security.KeyVault.Administration 4.8.0

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Azure.Security.KeyVault.Administration --version 4.8.0
 
 
NuGet\Install-Package Azure.Security.KeyVault.Administration -Version 4.8.0
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Azure.Security.KeyVault.Administration" Version="4.8.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Azure.Security.KeyVault.Administration" Version="4.8.0" />
 
Directory.Packages.props
<PackageReference Include="Azure.Security.KeyVault.Administration" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Azure.Security.KeyVault.Administration --version 4.8.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Azure.Security.KeyVault.Administration, 4.8.0"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Azure.Security.KeyVault.Administration@4.8.0
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Azure.Security.KeyVault.Administration&version=4.8.0
 
Install as a Cake Addin
#tool nuget:?package=Azure.Security.KeyVault.Administration&version=4.8.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Azure KeyVault Administration client library for .NET

Azure Key Vault Managed HSM is a fully-managed, highly-available, single-tenant, standards-compliant cloud service that enables you to safeguard cryptographic keys for your cloud applications using FIPS 140-2 Level 3 validated HSMs.

The Azure Key Vault administration library clients support administrative tasks such as full backup / restore and key-level role-based access control (RBAC).

Source code | Package (NuGet) | Product documentation | Samples

Getting started

Install the package

Install the Azure Key Vault administration client library for .NET with NuGet:

dotnet add package Azure.Security.KeyVault.Administration

Prerequisites

To create a Managed HSM resource, run the following CLI command:

az keyvault create --hsm-name <your-key-vault-name> --resource-group <your-resource-group-name> --administrators <your-user-object-id> --location <your-azure-location>

To get <your-user-object-id> you can run the following CLI command:

az ad user show --id <your-user-principal> --query id

Authenticate the client

In order to interact with the Azure Key Vault service, you'll need to create an instance of the client classes below. You need a vault url, which you may see as "DNS Name" in the portal, and credentials to instantiate a client object.

The examples shown below use a DefaultAzureCredential, which is appropriate for most scenarios including local development and production environments. Additionally, we recommend using a managed identity for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the Azure Identity documentation.

To use the DefaultAzureCredential provider shown below, or other credential providers provided with the Azure SDK, you must first install the Azure.Identity package:

dotnet add package Azure.Identity
Activate your managed HSM

All data plane commands are disabled until the HSM is activated. You will not be able to create keys or assign roles. Only the designated administrators that were assigned during the create command can activate the HSM. To activate the HSM you must download the security domain.

To activate your HSM you need:

  • A minimum of 3 RSA key-pairs (maximum 10)
  • Specify the minimum number of keys required to decrypt the security domain (quorum)

To activate the HSM you send at least 3 (maximum 10) RSA public keys to the HSM. The HSM encrypts the security domain with these keys and sends it back. Once this security domain is successfully downloaded, your HSM is ready to use. You also need to specify quorum, which is the minimum number of private keys required to decrypt the security domain.

The example below shows how to use openssl to generate 3 self-signed certificates.

openssl req -newkey rsa:2048 -nodes -keyout cert_0.key -x509 -days 365 -out cert_0.cer
openssl req -newkey rsa:2048 -nodes -keyout cert_1.key -x509 -days 365 -out cert_1.cer
openssl req -newkey rsa:2048 -nodes -keyout cert_2.key -x509 -days 365 -out cert_2.cer

Use the az keyvault security-domain download command to download the security domain and activate your managed HSM. The example below uses 3 RSA key pairs (only public keys are needed for this command) and sets the quorum to 2.

az keyvault security-domain download --hsm-name <your-managed-hsm-name> --sd-wrapping-keys ./certs/cert_0.cer ./certs/cert_1.cer ./certs/cert_2.cer --sd-quorum 2 --security-domain-file ContosoMHSM-SD.json
Controlling access to your managed HSM

The designated administrators assigned during creation are automatically added to the "Managed HSM Administrators" built-in role, who are able to download a security domain and manage roles for data plane access, among other limited permissions.

To perform other actions on keys, you need to assign principals to other roles such as "Managed HSM Crypto User", which can perform non-destructive key operations:

az keyvault role assignment create --hsm-name <your-managed-hsm-name> --role "Managed HSM Crypto User" --scope / --assignee-object-id <principal-or-user-object-ID> --assignee-principal-type <principal-type>

Please read best practices for properly securing your managed HSM.

Create KeyVaultAccessControlClient

Instantiate a DefaultAzureCredential to pass to the KeyVaultAccessControlClient. The same instance of a token credential can be used with multiple clients if they will be authenticating with the same identity.

KeyVaultAccessControlClient client = new KeyVaultAccessControlClient(new Uri(managedHsmUrl), new DefaultAzureCredential());
Create KeyVaultBackupClient

Instantiate a DefaultAzureCredential to pass to the KeyVaultBackupClient. The same instance of a token credential can be used with multiple clients if they will be authenticating with the same identity.

KeyVaultBackupClient client = new KeyVaultBackupClient(new Uri(managedHsmUrl), new DefaultAzureCredential());
Create KeyVaultSettingClient

Instantiate a DefaultAzureCredential to pass to the KeyVaultSettingsClient. The same instance of a token credential can be used with multiple clients if they will be authenticating with the same identity.

KeyVaultSettingsClient client = new KeyVaultSettingsClient(new Uri(managedHsmUrl), new DefaultAzureCredential());

Key concepts

KeyVaultRoleDefinition

A KeyVaultRoleDefinition is a collection of permissions. A role definition defines the operations that can be performed, such as read, write, and delete. It can also define the operations that are excluded from allowed operations.

KeyVaultRoleDefinitions can be listed and specified as part of a KeyVaultRoleAssignment.

KeyVaultRoleAssignment

A KeyVaultRoleAssignment is the association of a KeyVaultRoleDefinition to a service principal. They can be created, listed, fetched individually, and deleted.

KeyVaultAccessControlClient

A KeyVaultAccessControlClient provides both synchronous and asynchronous operations allowing for management of KeyVaultRoleDefinition and KeyVaultRoleAssignment objects.

KeyVaultBackupClient

A KeyVaultBackupClient provides both synchronous and asynchronous operations for performing full key backups, full key restores, and selective key restores.

BackupOperation

A BackupOperation represents a long running operation for a full key backup.

RestoreOperation

A RestoreOperation represents a long running operation for both a full key and selective key restore.

Thread safety

We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.

Additional concepts

Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime

Examples

The Azure.Security.KeyVault.Administration package supports synchronous and asynchronous APIs.

The following section provides several code snippets using the client created above for either access control or backup clients, covering some of the most common Azure Key Vault access control related tasks:

Sync examples

Async examples

Troubleshooting

See our troubleshooting guide for details on how to diagnose various failure scenarios.

General

When you interact with the Azure Key Vault Administration library using the .NET SDK, errors returned by the service correspond to the same HTTP status codes returned for REST API requests.

For example, if you try to retrieve a role assignment that doesn't exist in your Azure Key Vault, a 404 error is returned, indicating "Not Found".

try
{
 KeyVaultRoleAssignment roleAssignment = client.GetRoleAssignment(KeyVaultRoleScope.Global, "example-name");
}
catch (RequestFailedException ex)
{
 Console.WriteLine(ex.ToString());
}
Azure.RequestFailedException: Service request failed.
Status: 404 (Not Found)

Content:
{"error":{"code":"RoleAssignmentNotFound","message":"Requested role assignment not found (Activity ID: a67f09f4-b68e-11ea-bd6d-0242ac120006)"}}

Headers:
X-Content-Type-Options: REDACTED
x-ms-request-id: a67f09f4-b68e-11ea-bd6d-0242ac120006
Content-Length: 143
Content-Type: application/json

Setting up console logging

The simplest way to see the logs is to enable the console logging. To create an Azure SDK log listener that outputs messages to console, use the AzureEventSourceListener.CreateConsoleLogger method.

// Setup a listener to monitor logged events.
using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger();

To learn more about other logging mechanisms see here.

Next steps

Get started with our samples.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact with any additional questions or comments.

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Azure.Security.KeyVault.Administration:

Repository Stars
Azure/azure-powershell
Microsoft Azure PowerShell
microsoft/mcp
Catalog of official Microsoft MCP (Model Context Protocol) server implementations for AI-powered data access and tool integration
Version Downloads Last Updated
4.9.0-beta.2 58 6/11/2026
4.9.0-beta.1 70 6/4/2026
4.8.0 2,406 5/6/2026
4.7.0 4,777 3/4/2026
4.6.0 64,326 6/18/2025
4.6.0-beta.1 862 4/9/2025
4.5.0 199,199 10/15/2024
4.4.0 212,472 2/15/2024
4.4.0-beta.2 1,096 11/13/2023
4.4.0-beta.1 38,089 11/10/2023
4.3.0 134,457 3/14/2023
4.3.0-beta.1 1,149 11/9/2022
4.2.0 16,447 9/20/2022
4.1.0 35,513 3/26/2022
4.1.0-beta.3 1,157 2/9/2022
4.1.0-beta.2 588 10/14/2021
4.1.0-beta.1 496 8/11/2021
4.0.0 75,565 6/16/2021
4.0.0-beta.5 470 5/12/2021
4.0.0-beta.4 1,166 2/11/2021
Loading failed