How To Create Secret In Azure Key Vault

Creating a secret in Azure Key Vault is essential for securely storing and managing sensitive information. In this article, I will explain two simple approaches to performing this task efficiently.

How to create a secret in Azure Key Vault

Let us deep dive into the two simple approaches individually.

  • Approach-1: Using Azure Portal
  • Approach-2: Using PowerShell

Approach-1: Using Azure Portal

To create secret in Azure Key Vault, Follow the below steps

1. Log in to the Azure Portal.

2. On the key volt window, click the Secrets link from the left navigation and then click the + Generate/Import button.

create secret in azure key vault

3. On the Create a secret window, Provide the below details.

  • Upload options: Choose Manual.
  • Name: Provide a unique name for your secret.
  • Secret value: Enter a secret value.
  • Select the set activation date and set the expiration date based on your requirements.
  • Enabled: Select Yes.

Finally, click the Create button, as shown in the screenshot below.

how to create a secret in azure key vault

Fix the error. The operation is not allowed by RBAC in the case you are getting it after clicking on the Create button.

Now, you can see that the key vault has been created successfully. Check out the screenshot below.

how to create secret in azure key vault

Approach-2: Using PowerShell

Create an user account permissions to create secrets in the Key Vault

Execute the Azure PowerShell command below to create user account permissions to create secrets in Key Vault. Else. You will get the error “Caller is not authorized to perform an action on a resource.” like below.

Caller is not authorized to perform action on resource.

So, the first step is to create user account permissions to create secrets in Key Vault using the script below to avoid the above error.

New-AzRoleAssignment -RoleDefinitionName "Key Vault Administrator" -SignInName "fewlines4biju_hotmail.com#EXT#@fewlines4bijuhotmail.onmicrosoft.com" -Scope "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceGroups/newresgroup/providers/Microsoft.KeyVault/vaults/Azurelessonskeyvt2"

After executing the above script, I got the expected output below

create secret in azure key vault using powershell

Create a secret in your Azure key vault

Now, you can execute the below Azure PowerShell command to create the secret.

$secretvalue = ConvertTo-SecureString "Password@123" -AsPlainText -Force
$secret = Set-AzKeyVaultSecret -VaultName "Azurelessonskeyvt2" -Name "AzurelessonsPassword" -SecretValue $secretvalue

After executing the above script, I got the expected output, and the secret was created successfully, as shown in the screenshot below.

how to create secret in azure key vault using powershell

I logged in to the Azure Portal and verified that the secret was created successfully. See the screenshot below.

create secret in azure key vault powershell

You may also like following the articles below

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!