Azure: Create and Manage Key Vault

Azure: Create and Manage Key Vault

Login

1
2
3
az login \
-u [email protected] \
-p password

or login interactively

1
az login

Set Variables

Set RG name

1
ResourceGroup="DenimResourceGroup"

Set location

1
Location="westeurope"

Set KeyVault variable

1
KeyVault="DenimKeyVault"

Set KeyName

1
KeyName="DenimKey"

Create Resources and Keys

Create a new resource group

1
2
3
az group create \
-n $ResourceGroup \
-l $Location

Register the Key Vault Resource Provider

1
2
az provider register \
-n Microsoft.KeyVault

Check status of provider, if Registered

1
2
3
az provider show\
 -n Microsoft.KeyVault \
 -o table

Create a Key Vault

1
2
3
4
az keyvault create \
--name $KeyVault \
--resource-group $ResourceGroup \
--location $Location

List KeyVaults

1
az keyvault list -o table

Show info on KeyVault

1
az keyvault show -n $KeyVault

Get value of vaultUri

1
2
az keyvault show \
-n $KeyVault | grep vaultUri

Add a key or secret to the key vault

1
2
3
4
az keyvault key create \
--vault-name $KeyVault \
--vault-name $KeyVault \
--protection software

OR import a .pem key

1
2
3
4
5
6
az keyvault key import \
--vault-name $KeyVault \
--vault-name $KeyVault \
--pem-file './softkey.pem' \
--pem-password 'PaSSWORD' \
--protection software

Add a secret to the Vault

1
2
3
4
az keyvault secret set \
--vault-name $KeyVault \
--name 'SQLPassword' \
--value 'Pa$$w0rd'

To view your key, type:

1
2
az keyvault key list \
--vault-name $KeyVault

To view your secret, type:

1
2
az keyvault secret list \
--vault-name 'ContosoKeyVault'