If you come across migrating secrets from one keyvault to another keyvault, then you have a solution in this article.
Migrating all the secrets manually from one keyvault to the other one will be time consuming process. Also the manual process may end up with errors also.
I am sharing an automated approach using a python program to copy all the secrets from the source keyvault and write it to the target keyvault.
The program requires two dependent packages. The details are given below.
In this approach, we need an Azure Service Principle which has access to the source and target keyvaults. The SP needs atleast List & Read access in the source keyvault and List, Read & Write access in the target keyvault.
The program is given below.
Note:Update the keyA, keyB etc with the list of keys to be migrated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you don’t have a single Service principle that has access to both the keyvaults, we can do this by using two service principles also. The program with two service principles are given below. In this way, we can migrate secrets present in keyvault across Azure tenants.
Note:Update the keyA, keyB etc with the list of keys to be migrated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters