Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 8 of 39
❮Prev Next❯

Secure Foundry: Managed Identity, Keyless Auth and Private Networking

Module 1: Plan & Manage ⏱ 10 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    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.

    Simulate it » No Azure account needed

    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.

    Azure portal: Keyless auth, roles and private networking for Foundry Assign Foundry User, turn off keys and add a private endpoint.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    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
    1. Open the Foundry resource ➜ Identity. A system-assigned managed identity lets Foundry reach Storage, AI Search and Key Vault with Entra tokens.
    2. 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.
    3. Keys grant full access with no RBAC. Once every app uses Entra ID, set disableLocalAuth to true and keys stop working.
    4. In Networking, set Public network access to Disabled. Only private endpoints can reach it now.
    5. 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.
    6. 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.

    😟 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
    🛠️ Solved with: Managed identity, RBAC and private endpoints

    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

    1. 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.
    2. Assign a role on the Foundry resource or project, at the narrowest scope.
    3. 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 ManagerCreating projects and managing them, with the right to assign User.
    Foundry Account Owner / OwnerManaging the resource. Not for apps.
    Cognitive Services OpenAI UserCalling 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

    1. Resource Management → Networking → Public network access: Disabled (or Selected networks with a few allowed IPs).
    2. Create a private endpoint with target sub-resource account in a subnet of your VNet.
    3. 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.
    4. 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

    Banking

    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.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    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.

    Question 1

    Question 1 of 5

    A web app must call a Foundry model deployment without any stored secret. What should you do?

    Question 2

    Question 2 of 5

    You must make leaked API keys useless for a Foundry resource. What should you configure?

    Question 3

    Question 3 of 5

    A private endpoint for a Foundry resource exists, but an application inside the VNet still resolves the public IP address of the resource.

    What is the most likely missing configuration?

    Question 4

    Question 4 of 5

    Which role assignment gives an application least-privilege data-plane access to call models and agents in a Foundry project?

    Question 5

    Question 5 of 5

    A policy states that Foundry resources must never accept traffic from the public internet. Which setting meets it?

    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. 1.Which setting turns off API keys on a Foundry resource?Show

      disableLocalAuth set to true.

    2. 2.Which class gets tokens in Python without a stored secret?Show

      DefaultAzureCredential.

    3. 3.What does a private endpoint give the resource inside your VNet?Show

      A private IP address.

    4. 4.What makes the normal resource name resolve to that private IP?Show

      A linked private DNS zone.

    5. 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

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.