@@ -65,21 +65,30 @@ client = KeyVaultAccessControlClient(vault_url=MANAGED_HSM_URL, credential=crede
6565> ** NOTE:** For an asynchronous client, import ` azure.keyvault.administration.aio ` 's ` KeyVaultAccessControlClient ` instead.
6666
6767#### Create a KeyVaultBackupClient
68- After configuring your environment for the [ DefaultAzureCredential] [ default_cred_ref ] to use a suitable method of authentication, you can do the following to create a backup client (replacing the value of ` vault_url ` with your Managed HSM's URL):
68+ After creating a user-assigned [ managed identity] [ managed_identity ] and
69+ [ granting it access to your Managed HSM] [ managed_identity_backup_setup ] , you can do the following to create a backup
70+ client (setting the value of ` CLIENT_ID ` to your managed identity's client ID):
6971
7072<!-- SNIPPET:backup_restore_operations.create_a_backup_restore_client -->
7173
7274``` python
73- from azure.identity import DefaultAzureCredential
75+ from azure.identity import ManagedIdentityCredential
7476from azure.keyvault.administration import KeyVaultBackupClient
7577
7678MANAGED_HSM_URL = os.environ[" MANAGED_HSM_URL" ]
77- credential = DefaultAzureCredential()
79+ MANAGED_IDENTITY_CLIENT_ID = os.environ[" CLIENT_ID" ]
80+ credential = ManagedIdentityCredential(client_id = MANAGED_IDENTITY_CLIENT_ID )
7881client = KeyVaultBackupClient(vault_url = MANAGED_HSM_URL , credential = credential)
7982```
8083
8184<!-- END SNIPPET -->
8285
86+ Using the ` ManagedIdentityCredential ` is preferred in order to enable authenticating backup and restore operations with
87+ Managed Identity. Any other ` azure-identity ` credential could be provided instead if SAS tokens are used in these
88+ operations.
89+
90+ See [ azure-identity] [ managed_identity_ref ] documentation for more information on Managed Identity authentication.
91+
8392> ** NOTE:** For an asynchronous client, import ` azure.keyvault.administration.aio ` 's ` KeyVaultBackupClient ` instead.
8493
8594#### Create a KeyVaultSettingsClient
@@ -265,7 +274,11 @@ client.delete_role_assignment(scope=scope, name=role_assignment.name)
265274
266275### Perform a full key backup
267276The ` KeyVaultBackupClient ` can be used to back up your entire collection of keys. The backing store for full key
268- backups is a blob storage container using Shared Access Signature (SAS) authentication.
277+ backups is a blob storage container using either Managed Identity (which is preferred) or Shared Access Signature (SAS)
278+ authentication.
279+
280+ If using Managed Identity, first make sure your user-assigned managed identity has the correct access to your Storage
281+ account and Managed HSM per [ the service's guidance] [ managed_identity_backup_setup ] .
269282
270283For more details on creating a SAS token using a ` BlobServiceClient ` from [ ` azure-storage-blob ` ] [ storage_blob ] , refer
271284to the library's [ credential documentation] [ sas_docs ] . Alternatively, it is possible to
@@ -275,9 +288,8 @@ to the library's [credential documentation][sas_docs]. Alternatively, it is poss
275288
276289``` python
277290CONTAINER_URL = os.environ[" CONTAINER_URL" ]
278- SAS_TOKEN = os.environ[" SAS_TOKEN" ]
279291
280- backup_result: KeyVaultBackupResult = client.begin_backup(CONTAINER_URL , sas_token = SAS_TOKEN ).result()
292+ backup_result: KeyVaultBackupResult = client.begin_backup(CONTAINER_URL , use_managed_identity = True ).result()
281293print (f " Azure Storage Blob URL of the backup: { backup_result.folder_url} " )
282294```
283295
@@ -289,8 +301,12 @@ the operation is complete without returning an object.
289301
290302### Perform a full key restore
291303The ` KeyVaultBackupClient ` can be used to restore your entire collection of keys from a backup. The data source for a
292- full key restore is a storage blob accessed using Shared Access Signature authentication. You will also need the URL of
293- the backup (` KeyVaultBackupResult.folder_url ` ) from the [ above snippet] ( #perform-a-full-key-backup ) .
304+ full key restore is a storage blob accessed using either Managed Identity (which is preferred) or Shared Access
305+ Signature (SAS) authentication. You will also need the URL of the backup (` KeyVaultBackupResult.folder_url ` ) from the
306+ [ above snippet] ( #perform-a-full-key-backup ) .
307+
308+ If using Managed Identity, first make sure your user-assigned managed identity has the correct access to your Storage
309+ account and Managed HSM per [ the service's guidance] [ managed_identity_backup_setup ] .
294310
295311For more details on creating a SAS token using a ` BlobServiceClient ` from [ ` azure-storage-blob ` ] [ storage_blob ] , refer
296312to the library's [ credential documentation] [ sas_docs ] . Alternatively, it is possible to
@@ -299,10 +315,8 @@ to the library's [credential documentation][sas_docs]. Alternatively, it is poss
299315<!-- SNIPPET:backup_restore_operations.begin_restore -->
300316
301317``` python
302- SAS_TOKEN = os.environ[" SAS_TOKEN" ]
303-
304318# `backup_result` is the KeyVaultBackupResult returned by `begin_backup`
305- client.begin_restore(backup_result.folder_url, sas_token = SAS_TOKEN ).wait()
319+ client.begin_restore(backup_result.folder_url, use_managed_identity = True ).wait()
306320print (" Vault restored successfully." )
307321```
308322
@@ -398,7 +412,9 @@ contact
[email protected] with any additional questions or comments.
398412
399413[ managed_hsm ] : https://docs.microsoft.com/azure/key-vault/managed-hsm/overview
400414[ managed_hsm_cli ] : https://docs.microsoft.com/azure/key-vault/managed-hsm/quick-create-cli
401- [ managed_identity ] : https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview
415+ [ managed_identity ] : https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/overview
416+ [ managed_identity_backup_setup ] : https://learn.microsoft.com/azure/key-vault/managed-hsm/backup-restore#prerequisites-if-backing-up-and-restoring-using-user-assigned-managed-identity
417+ [ managed_identity_ref ] : https://aka.ms/azsdk/python/identity/docs#azure.identity.ManagedIdentityCredential
402418
403419[ pip ] : https://pypi.org/project/pip/
404420[ pypi_package_administration ] : https://pypi.org/project/azure-keyvault-administration
0 commit comments