Step-by-Step Guide to Using Azure Key Vault Secrets as Variables in Release Pipeline

Written By
Categories

Step-by-Step Guide to Using Azure Key Vault Secrets as Variables in Release Pipeline

Written By
Categories
Share:

Azure Key Vault is a powerful service provided by Microsoft Azure that allows you to securely store and manage sensitive information such as API keys, passwords, and connection strings. Azure Pipelines, on the other hand, is a versatile CD platform offered by Azure. By integrating Azure Key Vault secrets into Azure Release Pipelines, you can enhance the security of your CD processes and ensure that sensitive information is protected.

In this blog post, we will guide you through the process of leveraging Azure Key Vault secrets in Azure Release Pipelines, enabling you to securely retrieve and use them in your CD workflows.

Prerequisites

  1. Azure Subscription.
  2. Azure DevOps Organization

Table of Contents

  1. Setting up Azure Key Vault
    • Create an azure key vault in Azure Portal
    • Add Secret in the key vault
  2. Create Azure Service Connection in DevOps
    • Setting up Service Connection in Azure Pipeline
    • Linking Service Connection to key vault
  3. Retrieve key vault value in Azure Release Pipeline Variable
    • Create Variable Group In Library and Add Variables from Key Vault.

Setting up Azure Key Vault

Create an azure key vault in Azure Portal

a. From azure portal in search Box type Key Vault

Screenshot of Azure portal showing search results for "Key vaults" under Services, with additional resource categories displayed.

b. On the Key Vault Section Click on Create.

c. Now Create Key Vault Resource by filling all required fields.

d. After complete creation process click on Key vault resource which one create recently and it’s look like as below screenshot

Screenshot of Azure Key Vault overview page showing details like location, subscription, vault URI, and directory settings.

Add Secret in the key vault

a. Open key vault resource created in above step

b. Click on Secrets option in left side menu panel
Screenshot of Azure Key Vault navigation panel showing options like overview, keys, secrets, certificates, and access control.

c. Click on the Generate button at top left to generate new secret and provide necessary information.

Azure Key Vault Secrets blade showing a list of stored secrets with options to generate, import, refresh, and manage backup settings.

Create Azure Service Connection in DevOps

Setting up Service Connection in Azure Pipeline

a. Open DevOps Organization in which you want to grab secrets.

b. Now open Project Settings > Pipelines > Service Connections.

Screenshot of Azure DevOps Project Settings menu showing options for boards, pipelines, service connections, and project configuration.

c. Click on New service connection at top right side of page

d. Select Azure Resource Manager > Next

e. Provide the following parameters and create connections.

  • Subscription
  • Resource Group
  • Connection Name

Linking Service Connection to key vault (give security Permission)

a. Open Azure Portal and move towards your Key Vault

b. At left menu click on Access Policies

Azure Key Vault access policies page showing a list of configured identities with options to create, refresh, or edit permissions.
c. click on Create to create Access Policy
d. In Configuration from template select Secret Management
e. Grant Permission for Get & List from Permission section click next button
Azure Key Vault interface showing the first step of access policy creation with selected secret permissions like Get and List.

f. Now select Application for your Azure DevOps Subscription and complete process.

g. Retrieve key vault value in Azure Release Pipeline Variable (see the next section)

Retrieve key vault value in Azure Release Pipeline Variable

Create Variable Group In Library and Add Variables from Key Vault.

a. Go to project in DevOps > Pipelines > Library

Azure DevOps project interface showing the Pipelines menu expanded with options like Environments, Releases, and Deployment groups.

b. Create Variable Group

  • Provide Variable Group Name & description
  • Turn on Radio button of “Link secrets from an Azure key vault as variable” (bubble point 1 in below image)

c. Provide necessary information about Azure Subscription & Key Vault Name

Azure DevOps interface showing a new variable group linking secrets from Azure Key Vault, including subscription and key vault selection.

d. Click on Add at bottom to add secrets as variables (bubble point 2 in the above image).

e. Now you can use this variable in your release pipeline to replace value in config or appsetting file during deployment.

Azure DevOps pipeline variable group showing linked secrets like usernames, instances, and credentials used securely in a release pipeline.

Conclusion

Integrating Azure Key Vault secrets into Azure Release Pipelines provides a secure and convenient way to manage sensitive information during your CD processes. By following the step-by-step instructions outlined in this blog post, you can leverage the capabilities of Azure Key Vault to safeguard your secrets and avoid exposing them in your pipeline configurations or source code. With this approach, you can enhance the overall security posture of your applications and ensure the confidentiality of critical information.

Get the expert advice to grow your business digitally

    ×

    Table Of Content