Azure AI Services Security Guide
π Problem
You need to secure access to Azure AI services. How do you authenticate users/applications and manage network security to protect your resources from unauthorized access?
π‘ Solution with Azure
Use a combination of authentication methods (keys, Microsoft Entra ID, managed identities) and network access controls (IP restrictions, virtual networks, private endpoints) to protect Azure AI services. Additionally, use Azure Key Vault to manage secrets securely.
π§© Required Components
- Azure AI Services
- Microsoft Entra ID (formerly Azure AD)
- Azure Key Vault
- Azure Virtual Network (VNet)
- Private Endpoints
- Firewall/IP Access Rules
- Azure CLI / PowerShell
- Managed Identity (System/User-assigned)
- Role-based Access Control (RBAC)
ποΈ Architecture / Development
π Authentication via Subscription Keys
- Default authentication method for many Azure AI services
- Two keys provided per service to allow rotation without downtime
- Regenerate keys regularly using:
- Azure Portal
az cognitiveservices account keys regenerate
(CLI)
Key rotation steps: 1. Use only one key in production 2. Regenerate the unused key 3. Switch apps to use new key 4. Regenerate the original key
π Storing Keys in Azure Key Vault
- Use Key Vault to securely store AI service keys
- Access controlled via managed identities
- Avoid hardcoding secrets in applications
π Token-Based Authentication
- Some REST APIs require token-based auth
- Subscription key exchanged for short-lived token (10 minutes)
- SDKs handle token retrieval/usage automatically
π€ Microsoft Entra ID Authentication
Used for AI Foundry and other services.
Authenticate via:
Service Principals
- Register application
- Create service principal via New-AzADServicePrincipal
- Assign role: "Cognitive Services User"
Managed Identities - System-assigned (one resource) - User-assigned (reusable across resources)
Example (system-assigned):
Then assign role: "Cognitive Services Contributor"π Network Security Configuration
π Default Behavior
Azure AI services are publicly accessible by default.
π§± Restrict Access with Network Settings
Options: - All networks (default) - Selected Networks and Private Endpoints - Disabled (most restrictive)
π Changing Default Action
Changing from "All networks" β "Selected" or "Disabled" will block all access unless exceptions are added.
π Virtual Networks & IP Access
Configure in Azure Portal β Networking: 1. Select Virtual Network 2. Add subnet 3. Enable Service Endpoint: Microsoft.CognitiveServices 4. Optionally add IP address/ranges under Firewall
π Private Endpoint Access
Create Private Endpoint connection: 1. Resource β Networking β Private endpoint connections 2. Follow wizard (Subscription, Region, Subnet, DNS) 3. Once connected, change access to "Disabled" for strict control
π‘οΈ Trusted Azure Services Exceptions
Allow access to trusted Azure services: - Azure AI Services - Azure Machine Learning / AI Foundry - Azure AI Search
Enable exception in Networking panel: - Option: Allow Azure services on the trusted services list
β Best Practices / Considerations
- π Rotate keys regularly and automate via scripts or pipelines
- π Use Key Vault + Managed Identity for all secrets
- π€ Use Microsoft Entra ID wherever possible for role-based access
- π Limit network exposure using VNets or private endpoints
- β Disable all networks and allow only necessary trusted paths
- π Test access after each configuration change
- π SDKs handle auth/token logicβprefer SDK usage in apps
π§ͺ Sample Exam Questions
π You're using a subscription key to access Azure AI services. How do you rotate it without downtime?
A. Use both keys in rotation and regenerate one at a time βοΈ
B. Regenerate both keys simultaneously
C. Delete and re-create the service
D. Restart all dependent services after key change
π You want to prevent hardcoding keys in your application. What should you use?
A. Application config file
B. Azure Key Vault with managed identity βοΈ
C. Store key in plain text in Azure Blob
D. Hardcode into source code
π How do you restrict access to an AI service to a specific subnet?
A. Use service endpoint in selected virtual network βοΈ
B. Change key value
C. Use application gateway
D. Disable Azure Firewall
π€ You need to assign access to a VM to consume Azure AI services. What do you configure?
A. User-assigned identity
B. System-assigned managed identity βοΈ
C. Anonymous access
D. Public endpoint
π What does token-based auth require?
A. Sending a long-lived key on each request
B. Getting a short-lived token using a subscription key βοΈ
C. Using SSH keys
D. Enabling HTTP only mode