Azure Key Vault Security Domain Client Library

1.0.0b1 · active · verified Thu Apr 09

The Azure Key Vault Security Domain client library for Python allows developers to securely manage the security domain of an Azure Key Vault Managed HSM. This includes operations to download and restore a Managed HSM's security domain, which is crucial for establishing ownership, setting cryptographic boundaries, and enabling disaster recovery. The library is currently in a beta release, version `1.0.0b1`, as part of the broader Azure SDK for Python, which follows a regular release cadence with preview versions often preceding stable releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate the `SecurityDomainClient` using `DefaultAzureCredential` for authentication. It highlights the prerequisites for performing actual security domain operations like downloading, which include an Azure Key Vault Managed HSM and specific key management for encryption.

import os
from azure.identity import DefaultAzureCredential
from azure.keyvault.securitydomain import SecurityDomainClient

# Set your Managed HSM URL as an environment variable
# Example: 'https://my-managed-hsm.managedhsm.azure.net/'
VAULT_URL = os.environ.get("AZURE_MANAGEDHSM_URL", "<your-managed-hsm-url>")

# --- Prerequisites for actual operations ---
# For actual download/upload, you would need:
# 1. An active Azure subscription.
# 2. An existing Azure Key Vault Managed HSM (not a standard Key Vault).
# 3. RSA key pairs (public keys for 'sd_wrapping_keys') and a specified quorum.
# 4. Proper RBAC permissions for your identity to perform security domain operations.
#    (e.g., 'Managed HSM Security Domain Contributor' role).

if VAULT_URL == '<your-managed-hsm-url>':
    print("Please set the AZURE_MANAGEDHSM_URL environment variable or replace the placeholder.")
    exit(1)

try:
    # Authenticate using DefaultAzureCredential
    # This will try various methods: environment variables, managed identity, Azure CLI, etc.
    credential = DefaultAzureCredential()
    
    # Create a SecurityDomainClient
    client = SecurityDomainClient(vault_url=VAULT_URL, credential=credential)
    print(f"Successfully created SecurityDomainClient for: {VAULT_URL}")

    # --- Example: (Conceptual) Download a security domain ---
    # This operation requires 'certificate_info' (public keys) and 'quorum'.
    # It's a long-running operation, so 'begin_download' returns a poller.
    # For a real scenario, 'certs_object' would be a list of SecurityDomainJsonWebKey objects
    # and 'quorum' would be an integer.
    # Example: certs_object = [SecurityDomainJsonWebKey(...), ...]
    #          quorum = 2
    # poller = client.begin_download(certificate_info=certs_object, quorum=quorum)
    # security_domain = poller.result()
    # print("Security Domain downloaded.")

    # For demonstration, we'll just show client creation and a dummy print.
    print("Client created. Actual security domain operations require a Managed HSM and specific certificate setup.")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →