๐Ÿ”
Module 8 of 9 20โ€“25% 2 sub-modules ยท 16 units Domain 4: Secure, Monitor, and Troubleshoot Azure Solutions

Manage Application Secrets and Configuration for AI Solutions

Secure secrets by using Azure Key Vault, including rotation and retrieval. Store and retrieve app configuration using Azure App Configuration. Use Key Vault references and feature flags.

Azure Key VaultAzure App Configuration

Last updated: ยท Aligned with Course AI-200T00-A

Module

Manage Secrets with Azure Key Vault

units
๐ŸŽฌ Unit 1

Introduction

3 min

Azure Key Vault centralizes storage of secrets, cryptographic keys, and TLS certificates for AI applications. Instead of hardcoding API keys for OpenAI, Cosmos DB, or Redis in source code or environment files, applications retrieve them at runtime using managed identity โ€” no credentials stored anywhere in code or config files.

๐Ÿ’ก Exam Tip
Exam pillars: 1) Object types (Secrets vs Keys vs Certificates) 2) RBAC roles per object type 3) SDK pattern (get_secret with caching) 4) Secret versioning + soft delete 5) App Service Key Vault References (@Microsoft.KeyVault syntax).
๐Ÿ“˜ Unit 2

Key Vault Object Types

7 min

Key Vault Auth Flow: App MI โ†’ Entra ID RBAC check โ†’ Key Vault secret โ†’ App (cached)

RAG PipelineManaged Identityโ‘  Auth requestEntra IDRBAC checkโ‘ก tokenโ‘ข get_secret()Key VaultSecrets ยท Keys ยท Certsopenai-api-keycosmosdb-conn-stringโ‘ฃ secret.value (cached locally)RBAC RolesSecrets User โ†’ readSecrets Officer โ†’ manageContributor โ†’ NO dataSoft delete: always onNo credentials stored in code โ€” Managed Identity handles auth end-to-end

1. Secrets โ€” Arbitrary String Values

Store any opaque string value: API keys, connection strings, passwords, JWT signing secrets.

  • Unique identifier format: https://myvault.vault.azure.net/secrets/secret-name
  • Versioned: each update creates a new version. Old versions still retrievable.
  • Activatable/deactivatable with date-based access control.

2. Keys โ€” Cryptographic Keys

RSA and EC keys for encryption, signing, and unwrapping. The private key material never leaves Key Vault โ€” your app sends data TO Key Vault for signing/decryption operations, never receives the raw key.

  • HSM-backed keys (Premium tier) โ€” hardware security module protection. Highest compliance.
  • Operations: sign, verify, encrypt, decrypt, wrapKey, unwrapKey.

3. Certificates โ€” TLS/X.509

Full certificate lifecycle management: create, import, auto-renew (via DigiCert or Let's Encrypt integration). Private key stays in Key Vault. Integrates with App Service for custom domain TLS, API Management, and Application Gateway.

4. Object Type Summary

#TypeContentsUse For
1SecretString valueAPI keys, passwords, connection strings
2KeyCryptographic keySigning JWTs, encrypting data, key wrapping
3CertificateX.509 + private keyTLS certs for domains, mTLS
๐Ÿ“˜ Unit 3

Key Vault RBAC Roles

8 min

1. Data Plane Roles โ€” Control What Objects Can Be Read/Written

  1. Key Vault Secrets User โ€” read secret values. Assign to managed identity of your AI app. Read-only access to secrets.
  2. Key Vault Secrets Officer โ€” full CRUD on secrets (create, update, delete, read, list). Assign to developers and CI/CD pipelines that manage secrets.
  3. Key Vault Crypto User โ€” perform crypto operations with keys (sign, decrypt). Does NOT allow reading the raw key material.
  4. Key Vault Crypto Officer โ€” manage keys (create, update, delete) + perform operations.
  5. Key Vault Certificate User โ€” read certificate values.
  6. Key Vault Administrator โ€” full access to ALL data plane operations (secrets + keys + certificates). Use sparingly.
โš ๏ธ Common Gotcha
The Contributor or Owner Azure RBAC management-plane roles do NOT grant data access to secrets. A Contributor can see the vault exists but cannot read secrets. You MUST assign a data plane role (Secrets User/Officer etc.) for data access.

2. Role Assignment Pattern

# Grant AI app read-only access to secrets
az role assignment create \\
  --role "Key Vault Secrets User" \\
  --assignee-object-id $(az containerapp identity show -n ai-api -g rg --query principalId -o tsv) \\
  --scope $(az keyvault show -n myvault --query id -o tsv)

3. Scope Levels

  1. Vault level โ€” access to ALL secrets/keys/certs in the vault.
  2. Individual secret level โ€” access to only one secret: /subscriptions/.../secrets/secret-name.
๐Ÿ“˜ Unit 4

Implement Key Vault with the SDK

10 min

1. Basic SDK Pattern

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

credential = DefaultAzureCredential()   # Managed identity in prod, az CLI locally
client = SecretClient(
    vault_url="https://myvault.vault.azure.net",
    credential=credential
)

# Get latest version of a secret
secret = client.get_secret("openai-api-key")
api_key = secret.value

# Get a specific version
specific = client.get_secret("openai-api-key", version="abc123...")

2. Create, Update, and Delete Secrets

client.set_secret("openai-api-key", "sk-abc123")             # Create/update
client.set_secret("openai-api-key", "sk-abc123",             # Set properties
    enabled=True, expires_on=datetime(2026, 12, 31, tzinfo=timezone.utc))

# Disable (deactivate) without deleting
client.update_secret_properties("openai-api-key", enabled=False)

# Delete (soft delete โ€” goes to deleted state, not permanently gone)
client.begin_delete_secret("openai-api-key").result()

# Purge permanently (only after deletion, if purge protection disabled)
client.purge_deleted_secret("openai-api-key")

3. Secret Versioning

Every set_secret() call creates a new version. Old versions remain accessible forever until explicitly deleted. The "latest" version is what get_secret(name) without a version returns.

# List all versions of a secret
versions = list(client.list_properties_of_secret_versions("openai-api-key"))
for v in versions:
    print(v.version, v.enabled, v.expires_on)
๐Ÿ’ก Exam Tip
Key Vault references in App Service always use the "latest" version unless you pin a specific version URI. Pinning a version prevents automatic rotation โ€” use the versionless URI for auto-rotation.

4. Implement Caching (Avoid Throttling)

Key Vault has soft rate limits (2,000 secret reads/10 seconds per vault). Fetching secrets on every request causes throttling. Cache secrets locally with expiry:

import time

class SecretCache:
    _cache = {}
    _ttl_seconds = 300  # 5 minutes

    def get(self, name: str) -> str:
        cached = self._cache.get(name)
        if cached and time.time() - cached["fetched_at"] < self._ttl_seconds:
            return cached["value"]
        value = secret_client.get_secret(name).value
        self._cache[name] = {"value": value, "fetched_at": time.time()}
        return value
๐Ÿ“˜ Unit 5

App Service Key Vault References

7 min

1. Reference Syntax

# Always-latest version (recommended โ€” auto-rotates)
@Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/openai-api-key/)

# Pinned to specific version (does NOT auto-rotate)
@Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/openai-api-key/abc123)

2. Setup Steps (Both Required)

  1. Assign system-assigned managed identity to App Service
  2. Assign Key Vault Secrets User role to the MI on the vault
  3. Set app setting value to the @Microsoft.KeyVault(...) reference string
  4. App Service resolves the reference and injects the secret value as the env var
โš ๏ธ Common Gotcha
If the reference string appears literally in the app (not the secret value), the managed identity is missing the Key Vault Secrets User role assignment โ€” most common failure mode.

3. Soft Delete and Purge Protection

  1. Soft delete โ€” always enabled on new vaults. Deleted secrets move to deleted state for 7โ€“90 days before permanent removal. Prevents accidental deletion.
  2. Purge protection โ€” prevents permanent deletion during the soft-delete retention period, even by vault owners. Required for compliance (CMEK scenarios).

โšก Key Vault Master Cheatsheet

Object typesSecrets (strings) | Keys (crypto) | Certificates (TLS)
App read secretsKey Vault Secrets User role (data plane)
Manage secrets (CI/CD)Key Vault Secrets Officer role
Contributor role โ†’ secretsNO โ€” management plane โ‰  data plane
Auto-rotating referenceVersionless URI in App Service reference
Cache secrets locally5-min TTL in-process cache (avoid KV throttling)
Reference appears literallyMI missing Secrets User role
Prevent accidental deleteSoft delete (7โ€“90 days) + purge protection
HSM-backed keysPremium tier Key Vault
Private key never exportedCrypto keys โ€” Key Vault performs operations
๐Ÿงช Unit 6

Exercise โ€” Centralize AI App Secrets

30 min
  1. Create a Key Vault and store openai-api-key, cosmos-db-connection as secrets
  2. Assign Secrets User role to a Container App's managed identity
  3. Use SecretClient with DefaultAzureCredential to retrieve secrets in code
  4. Implement the local caching class to avoid throttling
  5. Configure App Service Key Vault Reference (versionless URI) and verify secret resolves
  6. Update secret value and confirm App Service picks up new value without redeployment
โœ… Unit 7

Knowledge Check

5 min
  1. Q: AI app needs to read the OpenAI API key at startup. Minimum required role? A: Key Vault Secrets User
  2. Q: A developer is Contributor on the subscription but can't read secrets. Why? A: Contributor is a management-plane role; secrets require a data-plane role (Secrets User/Officer)
  3. Q: App Service Key Vault reference shows the literal reference string, not the secret value. Fix? A: Assign Key Vault Secrets User role to the App Service's managed identity
  4. Q: Secret was deleted but needs to be recovered. How? A: Soft delete โ€” recover from deleted state within retention window
  5. Q: App makes 5,000 Key Vault calls/minute hitting rate limits. Fix? A: Implement local in-process secret cache with 5-minute TTL
๐Ÿ Unit 8

Summary

2 min

Key Vault is the central secret store for AI applications. Assign Secrets User role (not Contributor) to managed identities. Use versionless URIs in App Service references for auto-rotation. Cache secrets locally to avoid throttling. Soft delete is always on โ€” recover within the retention window. Never put private key material in env vars โ€” use Key Vault Crypto operations.

๐Ÿง  Memory Tricks

Three object types (SKC): Secrets (strings), Keys (crypto), Certificates (TLS)

Role ladder: Secrets User (read) โ†’ Secrets Officer (CRUD) โ†’ Administrator (everything)

"Contributor โ‰  secret access" โ€” management plane and data plane are completely separate in Key Vault

๐Ÿ Unit 9

Exam Summary Card

2 min
ScenarioAnswer
App reads secretsKey Vault Secrets User role on managed identity
CI/CD creates/updates secretsKey Vault Secrets Officer role
Contributor can't read secretsAdd Key Vault Secrets User role (data plane)
Auto-rotating secret in App ServiceVersionless URI reference
Rate limiting (too many KV calls)Local cache with short TTL (5 min)
Reference string appears literallyMI missing Secrets User role
Prevent permanent deletionPurge protection enabled
Compliance-grade key storageHSM-backed keys (Premium tier)
๐Ÿ”‘
Module Cheatsheet

Azure Key Vault

25โ€“30% PDF

๐Ÿ”‘ Key Facts

  • Object types (SKC) โ€” Secrets (strings) | Keys (crypto) | Certificates (TLS)
  • Secrets User role โ€” Read-only secret values โ€” assign to app managed identity
  • Secrets Officer role โ€” Full CRUD on secrets โ€” CI/CD pipelines, developers
  • Contributor โ‰  data โ€” Management-plane role CANNOT read secrets (common trap)
  • Versionless URI โ€” Auto-rotates โ€” always resolves to latest version
  • Local cache 5 min โ€” In-process TTL avoids KV throttling (2,000 ops/10s)
  • Soft delete โ€” Always on โ€” 7โ€“90 day recovery window. Prevents accidental delete.
  • HSM keys โ€” Premium tier โ€” FIPS 140-2 Level 3, private key never leaves vault

๐Ÿ’ป Commands & Patterns

from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
client = SecretClient(
  vault_url="https://myvault.vault.azure.net",
  credential=DefaultAzureCredential())
# Get latest version
api_key = client.get_secret("openai-api-key").value
# Cache to avoid throttling
import time; _cache = &#123;&#125;
def get_secret(name):
  c = _cache.get(name)
  if c and time.time() - c["t"] < 300: return c["v"]
  v = client.get_secret(name).value
  _cache[name] = &#123;"v": v, "t": time.time()&#125;; return v
# Role assignment
az role assignment create   --role "Key Vault Secrets User"   --assignee $MI_PRINCIPAL_ID   --scope $VAULT_RESOURCE_ID
# App Service KV Reference (versionless = auto-rotates)
# @Microsoft.KeyVault(SecretUri=https://vault.../secrets/key/)
Module

Manage App Configuration and Feature Flags

units
๐ŸŽฌ Unit 1

Introduction to Azure App Configuration

3 min

Azure App Configuration is a managed service for centralizing application settings and feature flags. Instead of environment variables scattered across deployments, all config lives in one place โ€” updatable without redeployment, with dynamic refresh and audit history.

๐Ÿ’ก Exam Tip
App Config exam pillars: 1) Sentinel key pattern for dynamic refresh 2) Feature flags โ€” enable/disable without redeployment 3) Key Vault references โ€” App Config stores the URI, not the secret 4) App Data Reader role for access 5) refresh_interval and WatchKey.
๐Ÿ“˜ Unit 2

Read Configuration with the Provider SDK

8 min

Load and Read Config

from azure.appconfiguration.provider import load
from azure.identity import DefaultAzureCredential

config = load(
    endpoint="https://mystore.azconfig.io",
    credential=DefaultAzureCredential(),
    refresh_on=[WatchKey("sentinel")],
    refresh_interval=30
)

# Read values like a dict
model = config["OpenAI:Model"]
endpoint = config["OpenAI:Endpoint"]
# Key Vault reference โ€” SDK resolves automatically
api_key = config["OpenAI:ApiKey"]  # stored as KV ref
๐Ÿ’ก Exam Tip
The provider SDK automatically resolves Key Vault references โ€” you never see the URI in your code, just the secret value. Authentication uses the same DefaultAzureCredential.
๐Ÿ“˜ Unit 3

Feature Flags

7 min

Enable and Check Feature Flags

from azure.appconfiguration.provider import load

config = load(
    endpoint="https://mystore.azconfig.io",
    credential=DefaultAzureCredential()
)

# Feature flag key format: .appconfig.featureflag/FlagName
semantic_cache_enabled = config.get(
    ".appconfig.featureflag/EnableSemanticCache", False
)

if semantic_cache_enabled:
    result = semantic_cache_get(prompt)
    if result:
        return result

return call_llm(prompt)
โš ๏ธ Common Gotcha
Feature flag keys follow .appconfig.featureflag/{name} pattern. Toggle in the Azure portal โ€” changes propagate within the refresh interval without any redeployment.
๐Ÿ“˜ Unit 4

Sentinel Key Dynamic Refresh

6 min

Sentinel Pattern

Instead of polling every key, watch one sentinel key. Update all config values first, then update the sentinel last โ€” this triggers a refresh in all running instances atomically.

# Update all settings, then sentinel last
az appconfig kv set -n mystore --key "OpenAI:Model" --value "gpt-4o"
az appconfig kv set -n mystore --key "sentinel" --value "v2"

# SDK watches sentinel, refreshes all config on change
config = load(
    endpoint="https://mystore.azconfig.io",
    credential=DefaultAzureCredential(),
    refresh_on=[WatchKey("sentinel")],
    refresh_interval=30
)
๐Ÿ’ก Exam Tip
Sentinel key = "config version bump". Update sentinel last = atomic config rollout across all instances. refresh_interval=30 means at most 30s lag before new config is picked up.
๐Ÿ Unit 5

Summary

2 min

Azure App Configuration: centralized settings + feature flags, updated without redeployment. Sentinel key pattern for atomic dynamic refresh. Feature flags at .appconfig.featureflag/Name โ€” toggle in portal. Key Vault references: App Config stores URI, SDK resolves to secret value. App Data Reader RBAC role required. refresh_interval controls max lag for config updates.

๐Ÿง 

Quick Quiz

5 questions โ€” test your understanding before moving on

Finished reading this module? Mark it complete to track your progress.

Related Modules โ€” Secure, Monitor, and Troubleshoot Azure Solutions

Frequently Asked Questions

What percentage of the AI-200 exam covers Secure, Monitor, and Troubleshoot Azure Solutions? +

Domain 4 (Secure, Monitor, and Troubleshoot Azure Solutions) accounts for 20โ€“25% of the AI-200 exam. Manage Application Secrets and Configuration for AI Solutions topics like Azure Key Vault and Azure App Configuration are actively tested. Study all official skill objectives listed in the module header above.

Is Key Vault & App Configuration on the AI-200 exam? +

Yes. Manage Application Secrets and Configuration for AI Solutions is part of Domain 4 in the official AI-200 skill outline, weighted at 20โ€“25%. The key services tested are Azure Key Vault, Azure App Configuration. Review the code examples and exam tips in this module for targeted prep.

How do I practice Key Vault & App Configuration hands-on? +

The best approach is to create a free Azure account and follow the code examples in this module step-by-step. The official Microsoft Learn sandbox for Course AI-200T00-A also provides free lab environments for Azure Key Vault and related services.