← Back to Article List         
Variable Groups vs Azure Key Vault and Secret Security

Variable Groups vs Azure Key Vault and Secret Security

Published on 08 Oct 2026     5 min read Azure DevOps
Variables, Secrets

1. What is the difference between Variable Groups and Azure Key Vault?

Both are used to manage configuration values and secrets, but their purposes are different.

Variable Groups

A Variable Group is an Azure DevOps feature that stores configuration variables centrally and shares them across multiple pipelines.

Example:

Variable Group: PROD-Configuration

AppName          = EmployeeAPI
Environment      = Production
DatabaseName     = Employee_Prod
DbPassword       = ******** (Secret)

Variable Groups can contain both normal and secret variables.

Azure Key Vault

Azure Key Vault is a dedicated Azure service for securely storing and managing secrets, encryption keys, and certificates.

Example:

Azure Key Vault: kv-employee-prod

DbPassword       = ********
ApiKey           = ********
JwtSigningKey    = ********

It provides dedicated access controls, auditing, and secret-version management.

Key Differences

Feature

Variable Groups

Azure Key Vault

Service

Azure DevOps

Microsoft Azure

Main purpose

Share pipeline configuration

Securely manage secrets, keys, certificates

Normal variables

Yes

Not intended for general configuration

Secret storage

Yes

Yes

Share across pipelines

Yes

Yes, with authorized access

Secret versioning

No dedicated versioning

Yes

Access control

Azure DevOps permissions

Azure RBAC/access policies

Application access

Primarily through pipelines

Applications can access directly

Best use

Environment configuration

Sensitive credentials

How do they work together?

Azure Key Vault
   |
   | Stores sensitive secrets
   v
Key Vault-linked Variable Group
   |
   | Makes selected secrets available
   v
Azure DevOps Pipeline
   |
   v
Deploy ASP.NET Core Application

Example YAML:

variables:
- group: PROD-Secrets

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Write-Host "Production secrets loaded"
  env:
    DB_PASSWORD: $(DbPassword)

Here, PROD-Secrets is linked to Azure Key Vault.

Interview point: Variable Groups are primarily for centralized pipeline configuration, whereas Azure Key Vault is designed for secure secret management. They can be integrated.

 

2. Why should secrets never be stored directly in YAML?

YAML pipeline files are generally stored in Git repositories.

If passwords, API keys, or connection strings are hardcoded in YAML, anyone with sufficient repository access may be able to view them.

Incorrect approach

variables:
  dbUser: 'admin'
  dbPassword: 'MyPassword123'
  apiKey: 'abc123xyz'

Security Risks

  1. Source code exposure: Developers or unauthorized users may access credentials.

  2. Git history: Even after removing a password, it may remain in previous commits.

  3. Pipeline logs: Scripts may accidentally print secret values.

  4. Credential misuse: Exposed secrets may allow unauthorized database or API access.

  5. Compliance risks: Hardcoded credentials can violate organizational security policies.

Correct approach

Store secrets in Azure Key Vault and retrieve them securely.

steps:
- task: AzureKeyVault@2
  inputs:
    azureSubscription: 'Production-ServiceConnection'
    KeyVaultName: 'kv-employee-prod'
    SecretsFilter: 'DbPassword,ApiKey'
    RunAsPreJob: false

The secrets are retrieved during pipeline execution without storing their values in YAML.

 

3. How do you prevent secrets from appearing in pipeline logs?

A. Never print secrets

Incorrect:

steps:
- script: echo $(DbPassword)

Even though Azure DevOps attempts to mask secret values, deliberately printing them is unsafe.

Correct:

steps:
- script: echo "Database configuration loaded"

B. Use environment variables

Instead of passing secrets directly as command-line arguments, map them to task environment variables.

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Write-Host "Running application task"

      # Use $env:DB_PASSWORD securely
      # Do not print its value
  env:
    DB_PASSWORD: $(DbPassword)

This avoids embedding the secret directly in the script or command-line arguments.

C. Use Azure DevOps secret masking

Azure DevOps automatically attempts to replace registered secret values in pipeline logs with ***.

For example:

Actual Secret: MySecurePassword123

Pipeline Log: ***

Important: Masking is not guaranteed for every situation. Azure DevOps does not reliably mask substrings of secrets or transformed values.

D. Restrict access

  • Restrict Variable Group permissions.

  • Grant minimum required Key Vault permissions.

  • Authorize only trusted pipelines to use service connections.

  • Avoid enabling verbose or debug logging for sensitive operations.

  • Do not publish files containing secrets as build artifacts.

 

4. Real Project Example

Suppose your ASP.NET Core Web API uses SQL Server.

Azure Key Vault
   |
   | DbPassword
   | SqlConnectionString
   v
AzureKeyVault@2 Task
   |
   v
Azure Pipeline
   |
   | Retrieves secrets
   v
Deployment Task
   |
   v
Azure App Service
   |
   | Secure application settings
   v
ASP.NET Core Web API
   |
   v
SQL Server Database

The pipeline should pass the connection string securely to the application configuration rather than exposing it in YAML, logs, or build artifacts.

For Azure App Service, you can also configure a Key Vault reference so the application resolves the secret using its Managed Identity.

 

5. Important Interview Questions

Q1. Can Variable Groups store secrets?

Yes. Variable Groups support secret variables, but Azure Key Vault provides dedicated secret-management capabilities.

Q2. Why is Azure Key Vault preferred for Production?

It provides centralized secret storage, fine-grained access control, auditing, secret versioning, and integration with Managed Identity.

Q3. Does Azure DevOps automatically hide passwords in logs?

Azure DevOps attempts to mask registered secret values, but masking is not a complete security boundary. Never deliberately print secrets.

Q4. What happens if a password is accidentally committed to Git?

Immediately revoke or rotate the password, investigate possible exposure, update the secure secret store, and remove the credential from Git history where appropriate.

 

6. Interview-ready Answer

Question 1: Variable Groups vs Azure Key Vault

"Variable Groups are used to centrally manage configuration values across multiple Azure DevOps pipelines. They can contain both normal and secret variables.

Azure Key Vault is a dedicated Azure service used to securely manage passwords, connection strings, API keys, certificates, and encryption keys.

For Production environments, we prefer Azure Key Vault and integrate it with Azure Pipelines through service connections or Key Vault-linked Variable Groups."

Question 2: Why should secrets never be stored in YAML?

"We should never hardcode secrets in YAML because pipeline files are stored in source control, and credentials may be exposed through repository access, Git history, or pipeline logs.

Instead, we store sensitive values in Azure Key Vault or Azure DevOps secret variables.

We prevent secret exposure by avoiding echo commands, mapping secrets securely to environment variables, restricting pipeline permissions, and relying on Azure DevOps secret masking as an additional protection."

Key takeaway: Use Variable Groups for shared configuration, Azure Key Vault for sensitive secrets, and secure pipeline practices to prevent credential exposure.