Quickstart - Set and retrieve a secret from Azure Key Vault (2024)

  • Article

In this quickstart, you create a key vault in Azure Key Vault with Azure CLI. Azure Key Vault is a cloud service that works as a secure secrets store. You can securely store keys, passwords, certificates, and other secrets. For more information on Key Vault you may review the Overview. Azure CLI is used to create and manage Azure resources using commands or scripts. Once that you have completed that, you will store a secret.

If you don't have an Azure subscription, create an Azure free account before you begin.

Prerequisites

This quickstart requires version 2.0.4 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.

Create a resource group

A resource group is a logical container into which Azure resources are deployed and managed. Use the az group create command to create a resource group named myResourceGroup in the eastus location.

az group create --name "myResourceGroup" --location "EastUS"

Create a key vault

Use the Azure CLI az keyvault create command to create a Key Vault in the resource group from the previous step. You will need to provide some information:

  • Key vault name: A string of 3 to 24 characters that can contain only numbers (0-9), letters (a-z, A-Z), and hyphens (-)

    Important

    Each key vault must have a unique name. Replace <your-unique-keyvault-name> with the name of your key vault in the following examples.

  • Resource group name: myResourceGroup.

  • The location: EastUS.

az keyvault create --name "<your-unique-keyvault-name>" --resource-group "myResourceGroup"

The output of this command shows properties of the newly created key vault. Take note of these two properties:

  • Vault Name: The name you provided to the --name parameter.
  • Vault URI: In this example, the Vault URI is https://<your-unique-keyvault-name>.vault.azure.net/. Applications that use your vault through its REST API must use this URI.

Give your user account permissions to manage secrets in Key Vault

To gain permissions to your key vault through Role-Based Access Control (RBAC), assign a role to your "User Principal Name" (UPN) using the Azure CLI command az role assignment create.

az role assignment create --role "Key Vault Secrets Officer" --assignee "<upn>" --scope "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.KeyVault/vaults/<your-unique-keyvault-name>"

Replace <upn>, <subscription-id>, <resource-group-name> and <your-unique-keyvault-name> with your actual values. Your UPN will typically be in the format of an email address (e.g., username@domain.com).

Add a secret to Key Vault

To add a secret to the vault, you just need to take a couple of additional steps. This password could be used by an application. The password will be called ExamplePassword and will store the value of hVFkk965BuUv in it.

Use the Azure CLI az keyvault secret set command below to create a secret in Key Vault called ExamplePassword that will store the value hVFkk965BuUv :

az keyvault secret set --vault-name "<your-unique-keyvault-name>" --name "ExamplePassword" --value "hVFkk965BuUv"

Retrieve a secret from Key Vault

You can now reference this password that you added to Azure Key Vault by using its URI. Use https://<your-unique-keyvault-name>.vault.azure.net/secrets/ExamplePassword to get the current version.

To view the value contained in the secret as plain text, use the Azure CLI az keyvault secret show command:

az keyvault secret show --name "ExamplePassword" --vault-name "<your-unique-keyvault-name>" --query "value"

Now, you have created a Key Vault, stored a secret, and retrieved it.

Clean up resources

Other quickstarts and tutorials in this collection build upon this quickstart. If you plan to continue on to work with subsequent quickstarts and tutorials, you may wish to leave these resources in place.

When no longer needed, you can use the Azure CLI az group delete command to remove the resource group and all related resources:

az group delete --name "myResourceGroup"

Next steps

In this quickstart you created a Key Vault and stored a secret in it. To learn more about Key Vault and how to integrate it with your applications, continue on to the articles below.

  • Read an Overview of Azure Key Vault
  • Learn how to store multiline secrets in Key Vault
  • See the reference for the Azure CLI az keyvault commands
  • Review the Key Vault security overview
Quickstart - Set and retrieve a secret from Azure Key Vault (2024)
Top Articles
Windows deployment scenarios
How to Access 'Spider-Man' PS4 The Heist DLC
What Is Single Sign-on (SSO)? Meaning and How It Works? | Fortinet
Devin Mansen Obituary
Using GPT for translation: How to get the best outcomes
Ymca Sammamish Class Schedule
Craigslist Motorcycles Jacksonville Florida
Mr Tire Prince Frederick Md 20678
oklahoma city for sale "new tulsa" - craigslist
Academic Integrity
Nikki Catsouras Head Cut In Half
Atrium Shift Select
Fallout 4 Pipboy Upgrades
Natureza e Qualidade de Produtos - Gestão da Qualidade
Where's The Nearest Wendy's
3472542504
Uc Santa Cruz Events
I Touch and Day Spa II
Tamilrockers Movies 2023 Download
Who called you from +19192464227 (9192464227): 5 reviews
Nevermore: What Doesn't Kill
bode - Bode frequency response of dynamic system
Best Mechanics Near You - Brake Masters Auto Repair Shops
A Biomass Pyramid Of An Ecosystem Is Shown.Tertiary ConsumersSecondary ConsumersPrimary ConsumersProducersWhich
'Insidious: The Red Door': Release Date, Cast, Trailer, and What to Expect
Buhl Park Summer Concert Series 2023 Schedule
Summoners War Update Notes
101 Lewman Way Jeffersonville In
How rich were the McCallisters in 'Home Alone'? Family's income unveiled
Elijah Streams Videos
T&J Agnes Theaters
Imperialism Flocabulary Quiz Answers
That1Iggirl Mega
Wsbtv Fish And Game Report
Sc Pick 4 Evening Archives
Unifi Vlan Only Network
Sabrina Scharf Net Worth
Final Fantasy 7 Remake Nexus
Ferguson Employee Pipeline
Ramsey County Recordease
Tsbarbiespanishxxl
Weather Underground Corvallis
Achieving and Maintaining 10% Body Fat
Craigslist Central Il
✨ Flysheet for Alpha Wall Tent, Guy Ropes, D-Ring, Metal Runner & Stakes Included for Hunting, Family Camping & Outdoor Activities (12'x14', PE) — 🛍️ The Retail Market
Stoughton Commuter Rail Schedule
Roller Znen ZN50QT-E
Kidcheck Login
Kenmore Coldspot Model 106 Light Bulb Replacement
Strange World Showtimes Near Century Federal Way
Bumgarner Funeral Home Troy Nc Obituaries
Latest Posts
Article information

Author: Reed Wilderman

Last Updated:

Views: 6090

Rating: 4.1 / 5 (72 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Reed Wilderman

Birthday: 1992-06-14

Address: 998 Estell Village, Lake Oscarberg, SD 48713-6877

Phone: +21813267449721

Job: Technology Engineer

Hobby: Swimming, Do it yourself, Beekeeping, Lapidary, Cosplaying, Hiking, Graffiti

Introduction: My name is Reed Wilderman, I am a faithful, bright, lucky, adventurous, lively, rich, vast person who loves writing and wants to share my knowledge and understanding with you.