Lesson 3 of 4 Securing Multi-Agent Solutions

Managing Secrets with Azure Key Vault

This lesson covers how multi-agent solutions store, retrieve, rotate and protect the secrets that remain in keyless designs, such as third-party API keys, certificates and connection strings, with Azure Key Vault.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish the secrets, keys and certificates Key Vault stores.
  • Retrieve secrets with a managed identity and Key Vault references.
  • Rotate secrets and keys without redeployment.

What Key Vault stores

Key Vault holds three object types. Secrets are arbitrary values such as API keys and passwords, versioned and with optional expiry. Keys are cryptographic keys for encryption and signing, protected by software or hardware security modules (HSM), and used for customer-managed key (CMK) encryption of other services. Certificates combine a key and an X.509 certificate with lifecycle management, including automatic renewal from integrated certificate authorities. Azure Key Vault Managed HSM serves the strictest key-protection requirements.

Sort into groups

Secret, key or certificate?

Exam skills 4.1.3

Decide which Key Vault object type each item should be.

Log in to try this activity Interactive activities are free with an account.

Retrieval and role-based access

Applications retrieve secrets at run time with their managed identity, so no bootstrap credential is needed. App Service, Functions and Container Apps also support Key Vault references, which resolve app settings from the vault so that code reads an ordinary environment variable. Foundry connections can store credentials for tools so that agent definitions never contain them.

from azure.identity import ManagedIdentityCredential
from azure.keyvault.secrets import SecretClient

secrets = SecretClient(vault_url="https://kv-agents-prod.vault.azure.net", credential=ManagedIdentityCredential())
weather_key = secrets.get_secret("weather-api-key").value          # cached briefly, never logged

Access uses the Azure RBAC permission model (recommended over legacy access policies). Key Vault Secrets User reads secret values; Key Vault Secrets Officer manages them; Key Vault Crypto User uses keys; Key Vault Administrator manages everything. Roles can be scoped to a single secret, so each agent's identity reads only its own secrets. Separate vaults per environment and per application limit the impact of mistakes.

Match the pairs

Key Vault roles

Exam skills 4.1.3

Match each Key Vault role with what it allows.

Log in to try this activity Interactive activities are free with an account.

Rotation and encryption

Rotation limits the value of a leaked secret. Keys support rotation policies that create new versions automatically. For secrets, Key Vault publishes Event Grid events such as SecretNearExpiry, which trigger an Azure Function that generates a new credential at the provider and stores it as a new version; applications that read the latest version pick it up without redeployment. Dual-credential rotation (two valid keys, rotated alternately) avoids downtime.

Encryption with customer-managed keys protects data at rest in Foundry, Storage, Cosmos DB and AI Search with keys the organization controls and can revoke. CMK requires soft delete and purge protection on the vault, so that a deleted key cannot make data permanently unreadable. Diagnostic logs of vault access go to Log Analytics for auditing.

True or false

Rotation and customer-managed keys

Exam skills 4.1.3

Check how secrets are rotated and how CMK encryption is protected.

Log in to try this activity Interactive activities are free with an account.
Worked example

A leaked key

A third-party data provider's API key was found in an agent's prompt template in a public repository. Several agents use the key, and rotating it previously required redeploying each agent.

Revoke the key at the provider, store the new key in Key Vault, grant each tool identity Key Vault Secrets User on that secret, and read it at run time or through Key Vault references. Automate rotation with near-expiry events and a rotation function. Moving the key to an environment variable in each deployment would still require redeployments and spread copies.

Check yourself

How should a tool read a secret from Key Vault?

Show answer

At run time with a managed identity that has the Key Vault Secrets User role on only the secrets it needs.

Exam Tips

Remember for the exam

  • Read secrets at run time with a managed identity, or via Key Vault references.
  • Use the RBAC model; scope Key Vault Secrets User to the secrets each identity needs.
  • CMK requires soft delete and purge protection; automate rotation with Event Grid.