Azure.Security.KeyVault.Administration 4.1.0 The ID prefix of this package has been reserved for one of the owners of this package by Prefix Reserved

.NET Standard 2.0
Install-Package Azure.Security.KeyVault.Administration -Version 4.1.0
dotnet add package Azure.Security.KeyVault.Administration --version 4.1.0
<PackageReference Include="Azure.Security.KeyVault.Administration" Version="4.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Azure.Security.KeyVault.Administration --version 4.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Azure.Security.KeyVault.Administration, 4.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Azure.Security.KeyVault.Administration as a Cake Addin
#addin nuget:?package=Azure.Security.KeyVault.Administration&version=4.1.0

// Install Azure.Security.KeyVault.Administration as a Cake Tool
#tool nuget:?package=Azure.Security.KeyVault.Administration&version=4.1.0
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


See the final two steps in the next section for details on creating the Key Vault with the Azure CLI.

Authenticate the client

In order to control permissions to the Key Vault service, you'll need to create an instance of the KeyVaultAccessControlClient class. You need a Managed HSM URL, which you may see as "DNS Name" in the portal, and client secret credentials (client id, client secret, tenant id) to instantiate a client object.

Client secret credential authentication is being used in this getting started section but you can find more ways to authenticate with Azure identity. To use the DefaultAzureCredential provider shown below, or other credential providers provided with the Azure SDK, you should install the Azure.Identity package:

dotnet add package Azure.Identity
Create/Get credentials

Use the Azure CLI snippet below to create/get client secret credentials.

  • Create a service principal and configure its access to Azure resources:

    az ad sp create-for-rbac -n <your-application-name> --skip-assignment


        "appId": "generated-app-ID",
        "displayName": "some-app-name",
        "name": "http://some-app-name",
        "password": "random-password",
        "tenant": "tenant-ID"
  • Take note of the service principal objectId

    az ad sp show --id <appId> --query objectId


  • Use the returned credentials above to set AZURE_CLIENT_ID (appId), AZURE_CLIENT_SECRET (password), and AZURE_TENANT_ID (tenant) environment variables. The following example shows a way to do this in Powershell:

  • Create the Managed HSM and grant the above mentioned service principal authorization to perform administrative operations on the Managed HSM (replace <your-resource-group-name> and <your-managed-hsm-name> with your own, unique names and <your-service-principal-object-id> with the value from above):

    az keyvault create --hsm-name <your-managed-hsm-name> --resource-group <your-resource-group-name> --administrators <your-service-principal-object-id> --location <your-azure-location>

    This service principal is automatically added to the "Managed HSM Administrators" built-in role.

  • Use the above mentioned Azure Key Vault name to retrieve details of your Vault which also contains your Azure Key Vault URL:

    az keyvault show --hsm-name <your-managed-hsm-name> --query properties.hsmUri --output tsv
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:

  • Minimum 3 RSA key-pairs (maximum 10)
  • Specify 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 certificate.

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

Once you've populated the AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID environment variables, replace managedHsmUrl with the output of az keyvault show in the example below to create the KeyVaultAccessControlClient

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

Once you've populated the AZURE_CLIENT_ID, AZURE_CLIENT_SECRET and AZURE_TENANT_ID environment variables and replaced your-hsm-url with the above returned URI, you can create the KeyVaultBackupClient:

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

Key concepts


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.


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


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


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


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


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


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


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


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".

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

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

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 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.


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

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
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

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

Repository Stars
Microsoft Azure PowerShell
Version Downloads Last updated
4.1.0 3,634 3/26/2022
4.1.0-beta.3 350 2/9/2022
4.1.0-beta.2 313 10/14/2021
4.1.0-beta.1 203 8/11/2021
4.0.0 34,412 6/16/2021
4.0.0-beta.5 193 5/12/2021
4.0.0-beta.4 826 2/11/2021
4.0.0-beta.3 344 11/13/2020
4.0.0-beta.2 36,040 10/7/2020
4.0.0-beta.1 287 9/9/2020