Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How Microsoft Entra Keeps AI Agents Under Control

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Microsoft Entra (formerly Azure Active Directory) gives you a set of built-in guardrails to stop AI agents from taking unauthorized actions, leaking data, or spiraling out of control. The short answer: you use Entra's identity, conditional access, and governance features to limit what an agent can access, what it can do, and how it authenticates. This guide walks you through the practical steps to configure those controls.

What You'll Need

  • An Azure subscription with Microsoft Entra ID (your organization's tenant).
  • Global Administrator or Privileged Role Administrator permissions in Entra.
  • An AI agent that you've built (for example, using Azure AI Foundry, Copilot Studio, or a custom bot) that you want to secure.
  • Access to the Microsoft Entra admin center (entra.microsoft.com).

Step-by-Step

  1. Create a dedicated identity for your AI agent. In the Entra admin center, go to Identity > Applications > App registrations and select New registration. Name it something like “AI-Agent-Prod” and choose the appropriate account type (usually “Accounts in this organizational directory only”). This gives the agent its own identity, separate from any user.
  2. Assign a service principal and restrict permissions. After registration, the app gets a service principal. Under API permissions, remove any default permissions and add only the minimum permissions the agent needs (for example, Microsoft Graph User.Read if it needs to read user profiles). Avoid granting Directory.ReadWrite.All or other broad scopes unless absolutely necessary.
  3. Use managed identity instead of secrets where possible. For agents running in Azure (like on Azure App Service or Azure Functions), enable a system-assigned managed identity. This avoids storing credentials in code. In the app registration, go to Certificates & secrets and add a client secret only if managed identity isn't feasible; then store that secret in Azure Key Vault, never in source code.
  4. Set up Conditional Access policies for the agent. In Entra, go to Protection > Conditional Access and create a new policy. Target the app registration you created. Add conditions like: require device compliance (if the agent runs on a managed device), block access from unexpected geographic regions, and require multifactor authentication (MFA) for any human who can manage the agent. These policies apply to the agent's sign-ins, not just users.
  5. Define token lifetime and session controls. In the same Conditional Access policy, under Session, set a sign-in frequency (e.g., re-authenticate every hour) and use “App enforced restrictions” if your agent supports it. This limits how long a token remains valid, reducing the blast radius if a token leaks.
  6. Restrict the agent's data access with scoped permissions. If your agent calls Microsoft Graph, use delegated permissions instead of application permissions, and always request the least-privileged scopes. For example, instead of Files.Read.All, use Files.Read.Selected if your agent only reads specific files. Test with a minimal set and expand only as needed.
  7. Enable Entra ID Protection for anomaly detection. Go to Protection > Identity Protection and enable risk-based policies. Configure a policy to require MFA or block sign-ins when the agent's account shows risky behavior (e.g., impossible travel). This applies to the agent's service principal, not just users.
  8. Set up access reviews for the agent's permissions. Under Identity Governance > Access reviews, create a review for the agent's role assignments. Schedule it quarterly, and have a human reviewer confirm that the agent still needs each permission. This prevents permission creep over time.
  9. Monitor agent activity with audit logs. In the Entra admin center, go to Identity > Monitoring & health > Sign-in logs and Audit logs. Filter by the agent's app name to see what it accessed and when. Set up alerts (via Azure Monitor) for failed sign-ins or unusual activity, such as a sudden spike in token requests.
  10. Use Privileged Identity Management (PIM) for elevated roles. If your agent occasionally needs admin roles, enable PIM for those roles and assign the agent as eligible, not active. This requires a human to approve each elevation, and it expires automatically after a set time (e.g., 1 hour).

Common Mistakes

  • Giving the agent the same permissions as a user. Users often have broad access; agents should have a narrowly scoped identity. Never reuse a user's credentials for an agent.
  • Using application permissions when delegated would work. Application permissions allow the agent to act without a signed-in user, which is powerful but dangerous. Prefer delegated permissions that require a user context.
  • Forgetting to expire or rotate secrets. Client secrets don't expire by default unless you set an expiration date. Always set a short expiration (e.g., 6 months) and rotate them regularly.
  • Skipping Conditional Access for the agent. Many people only apply policies to users, leaving the agent's service principal unprotected. Always target the agent's app in a policy.
  • Not reviewing permissions after changes. When you update the agent's code, you might add new API permissions. Review them periodically to remove stale ones.

Tips

  • Start with read-only permissions and test thoroughly before adding write or delete actions.
  • Use separate app registrations for development, staging, and production so you can isolate issues.
  • Leverage Entra's “Terms of use” feature to require that users who interact with the agent accept a usage policy.
  • For agents that use large language models, consider integrating Azure AI Content Safety to filter outputs, but that's separate from Entra.
  • Document the agent's permissions in a central place so that reviewers know why each scope exists.

Troubleshooting

If your agent fails to authenticate or is blocked unexpectedly, follow these steps in order:

  1. Check the sign-in logs. Go to Identity > Monitoring & health > Sign-in logs and look for the agent's app name. The error code will tell you if it's a Conditional Access block, a permissions issue, or a bad secret.
  2. Verify the service principal is enabled. In the app registration, go to Manage > Service principal and ensure the account isn't disabled. Also check that the “Enabled for sign-in” toggle is set to Yes.
  3. Test the token manually. Use a tool like Microsoft Graph Explorer or a simple PowerShell script to obtain a token with the agent's credentials. If you get an “invalid_client” error, the secret is wrong or expired.
  4. Review Conditional Access policies. Temporarily disable a policy (if you have permission) to see if it's blocking. Re-enable it immediately after testing. Remember that policies can take a few minutes to propagate.
  5. Check for IP restrictions. If you've set named locations, ensure the agent's outbound IP is included. For Azure-hosted agents, use the service tag for the region.
  6. If all else fails, reset the secret. In Certificates & secrets, create a new secret and update your agent's configuration. This is safe and doesn't delete any data, but it will invalidate the old secret.

Frequently Asked Questions

Can I use a user account for my AI agent instead of a service principal?

Technically yes, but it's a bad practice. User accounts have many default permissions and are subject to human-centric policies. A service principal is designed for non-human identities and gives you finer control.

How do I stop an agent from accessing data it shouldn't?

Use least-privilege permissions, Conditional Access policies that require device compliance and block risky sign-ins, and access reviews to periodically remove unused permissions.

What happens if an agent's token is leaked?

Conditional Access policies and short token lifetimes limit the damage. You can also revoke the token immediately by resetting the client secret or disabling the service principal.

Does Entra work with any AI agent, or only Microsoft's?

Entra provides identity and access management for any application that supports OAuth 2.0 and OpenID Connect. So you can secure custom agents or third-party agents that integrate with Entra.

Can I set up alerts for when my agent does something unusual?

Yes. Use Azure Monitor to create alerts on sign-in logs, e.g., when the agent authenticates from an unexpected location or when there are multiple failed attempts.

Is MFA required for AI agents?

MFA is designed for humans, not service principals. For agents, you rely on Conditional Access policies and strong secrets or managed identities. If a human interacts with the agent, MFA can be required for that human.