Secure Foundry: Managed Identity, Keyless Auth and Private Networking
30-second answer
Use Microsoft Entra ID instead of keys. Give the app a managed identity and assign it the Foundry User role on the resource or project (least privilege), then disable local (key) authentication so a leaked key is useless. Close the front door with public network access: Disabled and add a private endpoint in your virtual network, backed by a private DNS zone. Use role policies (RBAC and Azure Policy) to keep it that way. In code, use DefaultAzureCredential and a token provider, not an API key.
Exam objective: 1.3.4 Configure security, including managed identity, private networking, keyless credentials and role policies. (Skills measured as of April 16, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Open the Foundry resource ➜ <strong>Identity</strong>. A <strong>system-assigned managed identity</strong> lets Foundry reach Storage, AI Search and Key Vault with Entra tokens.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Open the Foundry resource ➜ Identity. A system-assigned managed identity lets Foundry reach Storage, AI Search and Key Vault with Entra tokens.
- Now let the app in. Add role assignment: Foundry User on this resource, assigned to the app's managed identity. Agent-only callers can get Foundry Agent Consumer instead.
- Keys grant full access with no RBAC. Once every app uses Entra ID, set disableLocalAuth to true and keys stop working.
- In Networking, set Public network access to Disabled. Only private endpoints can reach it now.
- Add a private endpoint with target subresource account. Azure links private DNS zones so the normal host name resolves to a private IP inside the VNet.
- In the app, use DefaultAzureCredential: it picks up the managed identity in Azure and your az login on a laptop. No key, no connection string with a secret.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
Keyless and private
The app uses a managed identity and Microsoft Entra ID tokens, with the Foundry User role on the resource. Local (key) auth is turned off. Public network access is disabled and a private endpoint in your VNet is the only way in.
🤔 What happens if…
Read this tour as text
- Pick the right model or tool. A router in your app sends each job to the cheapest thing that does it well: a reasoning model for multistep problems, a small language model for high-volume labelling, a multimodal model for photos, and a Foundry Tool such as Content Understanding for invoices.
- Where an agent gets its facts. Curated company content lives in a Foundry IQ knowledge base on Azure AI Search. Files a user drops into the chat go to file search. What the agent learns about the user across sessions goes to memory (user profile, chat summary).
- Resource, projects and deployment types. One Foundry resource holds deployments, networking and keys. Projects inside it isolate teams. Global deployments may process anywhere, Data Zone stays in the EU or US zone, Standard stays in one region. The standard agent setup keeps threads, files and vectors in your own Cosmos DB, Storage and AI Search.
- Configure deployments and agent versions. A deployment pins a model, a model version, a deployment type, capacity (TPM) and a guardrail. An agent gets a new version every time you change it; the endpoint serves the version you choose, so you can roll back.
- CI/CD with an evaluation gate. The agent definition, prompts and Bicep live in Git. The pipeline signs in with workload identity federation (no secret), runs an evaluation on a test set, and only then promotes from dev to test to prod projects.
- Quotas, 429s, spillover and budgets. Quota is tokens per minute per model, per region, per deployment type. Each deployment gets a slice; RPM comes with it. Go over and you get HTTP 429 with a retry-after header. Provisioned throughput can spill over to a standard deployment, and a cost control can stop a project at its token budget.
- Monitor models, agents and search. Azure Monitor metrics show requests, tokens, latency and errors. Application Insights holds traces, and continuous evaluation scores a sample of live answers for groundedness and safety. For Azure AI Search, watch indexer runs, document counts, search latency and throttled queries.
- Keyless and private. The app uses a managed identity and Microsoft Entra ID tokens, with the Foundry User role on the resource. Local (key) auth is turned off. Public network access is disabled and a private endpoint in your VNet is the only way in.
- Guardrails at four intervention points. A guardrail is a set of controls: a risk (hate, violence, prompt attacks, indirect attacks, protected material, PII), the intervention point (user input, tool call, tool response, output) and the action (annotate, or annotate and block).
- Evaluate, red team and trace. Evaluators score answers: groundedness, relevance, coherence, safety, and agent ones like tool call accuracy and task adherence. The AI red teaming agent attacks before launch. Traces in Application Insights record every model call, tool call and approval for audit.
- Govern what the agent may do. Give the agent only the tools it needs (allowed tools), make risky tools require approval from a human, let the tool call guardrail check what it sends, and limit where a hosted agent can connect with network egress controls.
Security wants no keys and no public endpoint on Contoso's Foundry resource. Give the app's managed identity the right role, turn off key authentication, disable public access and add a private endpoint.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
An API key for the AI service was pasted into a public repo.
😊 THE SOLUTION
Turn keys off, use managed identities with Foundry roles, and close public access.
- Keys leak and grant everything✓ disableLocalAuth and Entra ID tokens
- Who can do what?✓ Foundry User, Foundry Agent Consumer
- Reachable from the internet✓ Public access disabled, private endpoint
Start with a question
What happens if the API key is pasted into a public repository?
A developer at Fabrikam commits .env by accident. Within minutes, bots find the key and start sending requests to the company’s model deployment. The bill climbs, and every call looks like the real app.
Rotating the key fixes today’s leak. It doesn’t fix the design. As long as a key can call the service, a key can leak. The design fix is to remove the key, and to close the door the key was using.
Explain it like I’m 10
The technical explanation
Identity: roles, not keys
- Give the app an identity. Turn on system-assigned (or create a user-assigned) managed identity for the web app, function, container app or VM.
- Assign a role on the Foundry resource or project, at the narrowest scope.
- Call with Entra ID in code.
| Role (scope) | Use it for |
|---|---|
| Foundry User (Azure AI User in older docs) | An app or developer that calls models and agents. Data-plane only. |
| Foundry Project Manager / Azure AI Project Manager | Creating projects and managing them, with the right to assign User. |
| Foundry Account Owner / Owner | Managing the resource. Not for apps. |
| Cognitive Services OpenAI User | Calling OpenAI models only |
az role assignment create --assignee <managed-identity-principal-id> --role "Foundry User" --scope <foundry-resource-id>
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from openai import OpenAI
token = get_bearer_token_provider(DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default")
client = OpenAI(base_url="https://contoso-ai.services.ai.azure.com/openai/v1/", api_key=token)
Turn keys off
After every caller uses Entra ID, disable local authentication. Portal: Foundry resource → Resource Management → Keys and Endpoint (or the resource’s properties) → disable key access. CLI:
az resource update --ids <foundry-resource-id> --set properties.disableLocalAuth=true
A request signed with a key now fails with 403. You can enforce this for every new resource with the built-in Azure Policy for disabling local authentication.
Close the public door, open a private one
- Resource Management → Networking → Public network access: Disabled (or Selected networks with a few allowed IPs).
- Create a private endpoint with target sub-resource
accountin a subnet of your VNet. - Link the private DNS zones (
privatelink.cognitiveservices.azure.com,privatelink.openai.azure.com,privatelink.services.ai.azure.com) to the VNet, so the normal name resolves to the private IP. - For the standard agent setup, give the dependent resources (Cosmos DB, Storage, AI Search) private endpoints too, and use a delegated subnet for the agent’s own traffic.
az network private-endpoint create -g rg-agents -n pe-foundry --vnet-name vnet-agents --subnet snet-pe \
--private-connection-resource-id <foundry-resource-id> --group-id account --connection-name pe-foundry-conn
Keep the setup from drifting with Azure Policy (deny public access, require private endpoints) and role policies such as deny assignments and PIM for admin roles.
Architect level Why Contributor doesn't let you call a model
Azure roles split the control plane (create, delete, configure resources) from the data plane (call models, run agents). Contributor is a control-plane role, so it can change the resource but the data actions need a data role. That’s why a developer with Owner can still get 401 from the model until Foundry User is assigned. It also means an app identity should never need Contributor to do its job.
Real-world business scenario
Fabrikam Bank (fictional)
- The problem
- An API key for the loan assistant was found in a repository, and auditors wanted proof that model traffic never crossed the public internet.
- What they used
- Managed identity on the app with the Foundry User role, local authentication disabled, public network access disabled, private endpoints with linked private DNS zones, and an Azure Policy that denies new Foundry resources with keys or public access.
- Why that choice
- With no key and no public path, the leaked key was worthless, and the endpoint was only reachable from the bank's VNet.
- The result
- The audit passed, and the team stopped rotating keys every quarter.
When to use it and when not to
✓ Use it when…
- The app runs in Azure and can use a managed identity.
- Data is regulated or the company bans public endpoints.
- Auditors need to know which identity called what.
✕ Think twice when…
- You disable keys before switching every caller to Entra ID.
- You give apps Owner or Contributor to make errors go away.
- You add a private endpoint and skip the DNS zone link.
↔ Alternatives to consider
- Selected networks with IP rules for a few trusted addresses, when private endpoints are too much.
- Service principal with a certificate for callers outside Azure that can't use managed identity.
- Azure API Management in front, with its own identity, when many clients need one controlled door.
Test yourself with exercises
5 original practice questions in the AI-103 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner Why is keyless authentication better than an API key?
Model answer
A key is a secret that can leak, be shared and never expire. An Entra ID token is short-lived, tied to an identity I can audit, and access comes from a role I can remove. With a managed identity there's no secret in code or config at all.
Intermediate What do you do to a Foundry resource so keys no longer work?
Model answer
Set disableLocalAuth to true, from the portal's resource settings or with az resource update. After that, only Entra ID tokens are accepted. I'd first make sure every caller is using DefaultAzureCredential with the right role, or they'll start getting 401 and 403 errors.
Experienced developer A private endpoint is created, but the app in the VNet still resolves the public IP. Why?
Model answer
The private DNS zone isn't linked to the VNet, or the zone group isn't attached to the endpoint, so the name still resolves to the public address. I'd create the privatelink zones for the Foundry resource (cognitiveservices and openai and services.ai domains), link them to the VNet and check the A records.
Scenario An app runs in a web app and needs to call a model and read a blob. How do you give it access?
Model answer
Turn on the web app's managed identity, give it Foundry User on the resource and Storage Blob Data Reader on the storage account, and let the code use DefaultAzureCredential. No keys, and each permission is scoped to what the app needs.
Quick revision
Key points
- Use Entra ID tokens through DefaultAzureCredential. Managed identities remove stored secrets.
- Assign Foundry User at the narrowest scope that works. Owner and Contributor aren't for app access.
- disableLocalAuth true makes keys useless. Public network access Disabled closes the internet door.
- A private endpoint needs private DNS to work. Link the zones to the VNet.
- Enforce the setup with Azure Policy so a new resource can't be created with keys or public access.
Important terminology
- Managed identity
- An identity that Azure creates and manages for a resource, such as a web app or Foundry resource, so it can get Entra tokens without any stored secret.
- Keyless authentication
- Calling a service with a Microsoft Entra ID token instead of an API key. Access is controlled by roles and can be audited per identity.
- Foundry User role
- A built-in role that lets an identity use a Foundry project's agents, models and tools through the data plane without managing the resource. Earlier docs called it Azure AI User.
- Local authentication
- Access with the resource's API keys. The disableLocalAuth setting turns it off so only Entra ID tokens work.
- Private endpoint
- A network interface with a private IP address in your virtual network that connects to one Azure resource over Azure Private Link.
- Private DNS zone
- A DNS zone that makes the resource's normal name resolve to the private endpoint's IP inside your network.
Common mistakes
- Disabling keys before the app is switched to Entra ID.
- Creating a private endpoint but forgetting the DNS zone link.
- Giving the app Contributor on the resource when a data-plane role is enough.
Exam tips
- "No secrets in code" = managed identity with DefaultAzureCredential.
- "Prevent use of API keys" = disable local authentication.
- "Only reachable from our VNet" = private endpoint and public access disabled.
- "Least privilege to call a model" = a data-plane role such as Foundry User.
Five quick revision questions
-
1.Which setting turns off API keys on a Foundry resource?Show
disableLocalAuth set to true.
-
2.Which class gets tokens in Python without a stored secret?Show
DefaultAzureCredential.
-
3.What does a private endpoint give the resource inside your VNet?Show
A private IP address.
-
4.What makes the normal resource name resolve to that private IP?Show
A linked private DNS zone.
-
5.Which role lets an app use agents and models without managing the resource?Show
Foundry User.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Content Filters, Guardrails and Risk Detection
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.