Managing Authentication for Resources

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 13 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Lesson: Managing Authentication for Azure AI Foundry Services

Introduction: Why Authentication Matters in AI Workflows

In the landscape of modern cloud computing, Azure AI Foundry services stand at the intersection of powerful machine learning models and sensitive data. Whether you are deploying a Large Language Model (LLM), managing fine-tuning pipelines, or building a RAG (Retrieval-Augmented Generation) application, the security of your resources is paramount. Authentication is the first line of defense; it is the process of verifying the identity of a user, service, or application before allowing them to interact with your AI assets.

When we talk about managing authentication, we are really talking about access control. If your authentication strategy is weak, your proprietary data, expensive compute resources, and model weights are at risk. In an enterprise environment, "security by obscurity" is not a viable strategy. Instead, we must rely on identity-based access, least-privilege principles, and modern protocols like OAuth 2.0 and OpenID Connect.

This lesson explores how to secure Azure AI Foundry resources. We will move beyond simple API keys—which are often prone to leakage—and dive into Microsoft Entra ID (formerly Azure Active Directory), Managed Identities, and role-based access control (RBAC). By the end of this guide, you will understand how to configure your AI infrastructure so that only authorized entities can access your models, datasets, and compute environments.


Not read yet

The Shift from API Keys to Identity-Based Security

Historically, many developers relied on static API keys to authenticate with cloud services. While these keys are easy to implement, they present significant management challenges. If a developer accidentally commits an API key to a public code repository, the resource is immediately compromised. Rotating these keys often requires manual intervention, which can cause downtime in automated production environments.

Azure AI Foundry services encourage a shift toward identity-based security. Instead of managing a secret string, you grant an identity—such as a specific user or a service principal—permission to perform actions on a resource. This is handled through Microsoft Entra ID. When your application needs to talk to an AI service, it requests a token from Entra ID. This token is short-lived, cryptographically signed, and specific to the requested scope, significantly reducing the blast radius if a token is intercepted.

Callout: Authentication vs. Authorization It is common to confuse authentication with authorization, but they are distinct processes. Authentication is the act of proving who you are (e.g., providing credentials). Authorization is the act of determining what you are allowed to do once your identity is confirmed. In Azure, Entra ID handles the authentication, while Azure RBAC handles the authorization of what that identity can access within your AI Foundry project.


Not read yet

Using Managed Identities for AI Applications

Managed Identities are perhaps the most important tool in your security toolkit when working with Azure AI. A Managed Identity provides an automatically managed identity in Microsoft Entra ID for your application or resource. This means you do not need to store credentials in your code, environment variables, or configuration files.

There are two primary types of Managed Identities:

  • System-assigned Managed Identity: This identity is tied directly to a specific Azure resource (like an Azure App Service or a Virtual Machine). If the resource is deleted, the identity is automatically deleted.
  • User-assigned Managed Identity: This is created as a standalone Azure resource. It can be assigned to one or more Azure resources, allowing you to manage the lifecycle of the identity independently from the services that use it.

How to Implement Managed Identities

To use a Managed Identity with an AI Foundry service, you follow a standard pattern:

  1. Enable the identity on your compute resource (e.g., an Azure Function or a VM).
  2. Grant the identity access to your AI Foundry resource using Azure RBAC.
  3. Use the Azure Identity SDK in your code to acquire a token.

Here is a practical example using Python. Suppose you have an Azure AI project and you want to access it from an Azure Function using a Managed Identity.

from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient

# The DefaultAzureCredential will automatically look for a Managed Identity
# if the code is running in an Azure environment.
credential = DefaultAzureCredential()

# Initialize the client using the identity
project_client = AIProjectClient.from_connection_string(
    credential=credential,
    conn_str="YOUR_CONNECTION_STRING"
)

# Now you can interact with your AI tools securely
# without ever handling a password or API key.

The DefaultAzureCredential class is incredibly powerful. It attempts to authenticate in a specific order: first looking for environment variables, then checking for a Managed Identity, and finally falling back to local credentials (like the Azure CLI). This allows you to write code that works seamlessly in development and production without changing a single line of authentication logic.


Not read yet

Role-Based Access Control (RBAC) in AI Foundry

Once you have established identity, you must define the scope of access. Azure AI Foundry uses Azure RBAC to manage permissions. Instead of giving everyone "Owner" access, you should assign granular roles that align with the principle of least privilege.

Common Roles for AI Resources

  • Azure AI Developer: Allows users to build, test, and deploy models. This is appropriate for data scientists and ML engineers working on the development lifecycle.
  • Azure AI Contributor: Grants permissions to manage the AI project, including creating compute instances and endpoints. Use this for DevOps or Platform Engineers.
  • Reader: Grants read-only access to the project. This is perfect for auditors or team members who need to view logs and metrics but should not modify the infrastructure.

Configuring Permissions via Azure CLI

You can assign these roles using the Azure CLI. This is a common task when setting up a new project environment for a team.

# Assign the 'Azure AI Developer' role to a specific user
az role assignment create \
    --assignee <user-email-or-object-id> \
    --role "Azure AI Developer" \
    --scope /subscriptions/<sub-id>/resourceGroups/<rg-name>/providers/Microsoft.MachineLearningServices/workspaces/<project-name>

Warning: Scope Matters Always assign roles at the narrowest scope possible. If a user only needs access to one specific project, do not assign them a role at the Resource Group or Subscription level. Broad permissions increase the risk of accidental configuration changes or data exposure across multiple projects.


Not read yet

Securing Data Connections and Keys

While Managed Identities are the gold standard, there are scenarios where you must deal with external data sources—such as an Azure SQL database or a storage account—that might not support token-based authentication directly. In these cases, you will likely use secrets.

Azure Key Vault is the mandatory storage mechanism for these secrets. Never hardcode credentials in your application code or configuration files. Instead, follow this workflow:

  1. Store the secret (e.g., a database connection string) in Azure Key Vault.
  2. Grant your AI application's Managed Identity "Secret Get" permissions on the Key Vault.
  3. Retrieve the secret at runtime using the Azure Key Vault SDK.

Example: Fetching a Secret Safely

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

# Authenticate using the Managed Identity
credential = DefaultAzureCredential()

# Connect to Key Vault
vault_url = "https://your-vault-name.vault.azure.net/"
client = SecretClient(vault_url=vault_url, credential=credential)

# Retrieve the secret
secret = client.get_secret("DatabaseConnectionString")
print(f"The secret value is: {secret.value}")

By separating the secret from the code, you gain the ability to rotate secrets without redeploying your application. You simply update the value in Key Vault, and your application will fetch the new version upon the next request.


Not read yet

Industry Best Practices for Authentication

Managing security in AI is an ongoing process, not a one-time configuration. As your project grows, your security posture must evolve. Here are the industry-standard practices for Azure AI Foundry services:

1. Enforce Multi-Factor Authentication (MFA)

Ensure that all human access to the Azure portal and CLI is protected by MFA. Even if a password is compromised, the attacker will be unable to access the environment without the second factor. This is the single most effective way to prevent unauthorized account access.

2. Regularly Audit Access

Use Azure Monitor and Microsoft Entra logs to review who has accessed what resources. If you notice an identity that has not been used in 90 days, remove its permissions. This "access hygiene" prevents the accumulation of stale credentials that could be exploited.

3. Use Conditional Access Policies

Microsoft Entra Conditional Access allows you to define policies based on context. For example, you can require that access to your AI Foundry resources only originate from your corporate network or require that the device be compliant with company security policies.

4. Rotate Secrets Frequently

If you must use secrets (like API keys for third-party tools), automate their rotation. Many services allow you to rotate keys programmatically. Using Azure Key Vault’s integration with Event Grid can trigger a function to update your application’s secret store automatically whenever a key is rotated.

5. Network Isolation

Authentication is only half the battle. Combine your identity-based security with network-based security. Use Private Links to ensure that your AI Foundry services are not accessible via the public internet, but rather only through your private virtual network (VNet).


Not read yet

Common Pitfalls and How to Avoid Them

Even with the best intentions, it is easy to fall into traps that compromise security. Let’s look at some common mistakes and how to fix them.

Mistake 1: Using "Owner" or "Contributor" for Everything

Developers often assign the "Contributor" role to themselves or their service accounts because it removes friction. While this makes development easier, it is a significant security risk.

  • The Fix: Use the principle of least privilege. Start with a custom role or the most restrictive built-in role, and only escalate permissions when you encounter a specific "access denied" error that justifies the need for more access.

Mistake 2: Committing Keys to Source Control

It happens more often than anyone likes to admit. An API key is accidentally committed to a Git repository, and it is pushed to a remote server.

  • The Fix: Use tools like git-secrets or GitHub Secret Scanning to prevent the push of credentials. If a key is committed, assume it is compromised. Rotate the key immediately and delete the commit history if possible.

Mistake 3: Ignoring Regional Compliance

Some AI models and data processing services have regional constraints. If you authenticate from a region that is not compliant with your data residency requirements, you might violate corporate policy or legal regulations.

  • The Fix: Use Azure Policy to restrict which regions your resources can be created in and where traffic is allowed to flow.

Not read yet

Comparison of Authentication Methods

Method Security Level Management Overhead Best Use Case
API Keys Low High (Manual rotation) Simple legacy integrations
Service Principals Medium Medium Automated CI/CD pipelines
Managed Identities High Low (Automatic) Azure-hosted applications
User Identities (MFA) High Low Human interaction with resources

Note: Managed Identities are the preferred method for any code running within the Azure ecosystem. They eliminate the need for developers to manage credentials, making them the most secure and efficient option for production AI services.


Troubleshooting Authentication Issues

When things go wrong, the error messages can sometimes be vague. Here is a systematic way to troubleshoot authentication issues with Azure AI Foundry:

  1. Check the Identity: Verify which identity your code is actually using. If you are using DefaultAzureCredential, add print statements or logs to output credential.get_token() to see if it is picking up the expected identity.
  2. Verify RBAC Assignments: Use the Azure CLI command az role assignment list --assignee <id> to confirm that the identity actually has the expected role on the specific resource.
  3. Check Network Restrictions: If you have enabled a firewall or Private Link, the authentication might be succeeding, but the network request is being blocked. Ensure your client machine or the resource from which you are calling the AI service is permitted by the network configuration.
  4. Examine Entra Logs: Look at the "Sign-in logs" in Microsoft Entra ID. This will tell you if the request was denied, if MFA was missing, or if the account is locked.

Not read yet

Step-by-Step: Setting Up a Secure AI Project

Let’s walk through the process of creating a new AI Foundry project with a focus on security from the ground up.

Step 1: Create the Resource Group and Key Vault

Start by isolating your resources in a dedicated resource group. Create a Key Vault to store any necessary external credentials.

az group create --name ai-project-rg --location eastus
az keyvault create --name ai-keyvault-001 --resource-group ai-project-rg --location eastus

Step 2: Enable Managed Identity on your App

If you are deploying an Azure App Service, ensure the Managed Identity is turned on.

az webapp identity assign --name my-ai-app --resource-group ai-project-rg

Step 3: Grant the Identity Access

Get the Object ID of the Managed Identity and grant it the "Azure AI Developer" role on your AI project.

# Get the principal ID
export PRINCIPAL_ID=$(az webapp identity show --name my-ai-app --resource-group ai-project-rg --query principalId -o tsv)

# Assign role
az role assignment create --assignee $PRINCIPAL_ID --role "Azure AI Developer" --scope /subscriptions/<sub-id>/resourceGroups/ai-project-rg/providers/Microsoft.MachineLearningServices/workspaces/my-ai-project

Step 4: Configure Application Code

In your application, use the DefaultAzureCredential to initialize your clients. Because the App Service has a Managed Identity, the credential object will automatically negotiate a token whenever an API call is made.

Step 5: Final Review

Once deployed, perform a "Security Review" in the Azure portal for your AI project. Check the "Access Control (IAM)" blade to see a list of all users and identities with access. If you see an identity you don't recognize, remove it immediately.


Not read yet

Advanced Security: Private Links and Network Security

Beyond authentication, you must consider the network path. If an attacker gains valid credentials, they could still attempt to access your service from an unauthorized location. By using Azure Private Link, you map your AI Foundry service to a private IP address within your Virtual Network.

This means that even if a user has the right credentials, they cannot reach your AI service unless they are connected to the internal network (via VPN or ExpressRoute). This adds a "defense in depth" layer that is critical for enterprise AI. When configuring your project, ensure "Public network access" is disabled in the networking tab of your Azure AI resource.

Callout: Defense in Depth Defense in depth is the strategy of layering multiple security controls. If one control fails (e.g., an identity is compromised), the next control (e.g., network isolation) prevents the attacker from reaching the resource. Authentication is the first layer, but it should never be the only layer.


Not read yet

Managing Authentication for Collaborative Teams

In a team setting, managing authentication can become complex. Use these strategies to keep things organized:

  • Use Entra Groups: Instead of assigning roles to individual users, create a group in Microsoft Entra ID (e.g., "AI-Project-Data-Scientists") and assign the role to the group. When a new team member joins, you simply add them to the group, and they inherit all necessary permissions automatically.
  • Infrastructure as Code (IaC): Use Terraform or Bicep to define your RBAC assignments. This ensures that your security configuration is version-controlled and reproducible. You can review a Pull Request to see exactly who is getting access to what before it is applied.
  • Service Principals for CI/CD: For your automated pipelines (like GitHub Actions or Azure DevOps), use Service Principals with Federated Identity Credentials. This avoids the need to store long-lived client secrets in your CI/CD platform.

Not read yet

Frequently Asked Questions (FAQ)

Q: Can I use local accounts for Azure AI Foundry? A: While some services may support local authentication, it is highly discouraged. Always prefer Entra ID-based authentication to ensure your access is auditable and manageable.

Q: What do I do if I lose access to my AI resource? A: If you are the owner, you can use a higher-level administrative account (like a Subscription Owner) to reset the permissions. If you are entirely locked out, you may need to contact Microsoft support, which is why it is vital to have at least two users with owner-level access to every production environment.

Q: How often should I rotate my Managed Identity? A: You don't need to. Managed Identities are handled by the Azure platform and rotate their underlying credentials automatically. This is a major benefit over manual service principals.

Q: Does RBAC apply to the data inside the models? A: RBAC controls access to the project and the API endpoints. If you need fine-grained control over data (e.g., row-level security), that is typically handled at the data storage layer (like Azure SQL or Blob Storage) rather than the AI Foundry layer.


Not read yet

Key Takeaways

  1. Identity is the New Perimeter: Move away from static API keys and embrace identity-based authentication using Microsoft Entra ID.
  2. Managed Identities are Essential: Whenever possible, use Managed Identities for your applications. They remove the burden of credential management and significantly reduce the risk of secret leakage.
  3. Principle of Least Privilege: Always grant the minimum level of access required for a user or service to perform its job. Use custom roles if the built-in roles are too broad.
  4. Centralize Secret Management: Never store secrets in plain text or configuration files. Use Azure Key Vault to store and manage credentials, and connect to it using secure identity-based access.
  5. Layer Your Security: Authentication is only one part of the puzzle. Combine it with Network Security (Private Links), MFA, and regular auditing to create a robust security posture.
  6. Infrastructure as Code: Manage your permissions through code (Bicep/Terraform) to ensure consistency and traceability.
  7. Monitor and Audit: Regularly review access logs and remove stale permissions to maintain a clean and secure environment.

By following these practices, you ensure that your Azure AI Foundry resources remain secure, compliant, and reliable. Security in the age of AI is not about stopping progress; it is about providing the guardrails that allow your team to innovate with confidence.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.