Skip to content

[Bug] Published agents use project identity instead of distinct agent identity #93

@bmis

Description

@bmis

Describe the Feedback

Published agents do not use their dedicated Entra ID agent identity for tool authentication. Instead, they continue to use the shared project agent identity, which contradicts the documented behavior.

According to the official documentation, when an agent is published, it should automatically receive a distinct agent identity in Microsoft Entra ID that is bound to the agent application resource. However, in practice, published agents continue to authenticate using the shared project's agent identity (agentIdentityId from the project level) instead of their own dedicated agent identity.


Repro Steps

Steps to reproduce the behavior:

  1. Go to Microsoft Foundry Portal
  2. Create and configure an agent with MCP tools that require authentication
  3. Publish the agent
  4. Navigate to Microsoft Entra admin center (https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/AllAgents.MenuView/~/allAgentIds) and verify the distinct agent identity was created for the published agent
  5. In Foundry Portal, create an MCP connection with:
    • Authentication: Microsoft Entra
  6. In Foundry Portal, create an MCP connection with:
    • Authentication: Microsoft Entra
    • Type: Agent Identity
  7. Configure API Management with trace logging to capture authentication details from incoming requests
  8. Invoke the agent using openai_client.responses.create() with agent_reference
  9. The agent calls the MCP server (hosted on API Management) during execution
  10. Monitor the incoming requests in API Management trace logs
  11. Check the appid claim in the bearer token sent to the MCP server
  12. Observe that the appid always matches the project's shared agent identity instead of the published agent's distinct identity

Expected Behavior:
Published agents should authenticate using their distinct agent identity

Actual Behavior:
Published agents continue to use the shared project agent identity (agentIdentityId from the Project resource), even after being published.

System Information

  • Environment: Microsoft Foundry Production
  • SDK: azure-ai-projects>=2.0.0b1
  • Python: 3.x
  • Authentication: DefaultAzureCredential

Labels

Please include relevant labels such as:

  • bug
  • Feature Area: Agent Identity, Authentication, Agent Publishing
  • Issue: Runtime, Identity Management
  • Priority: High (Security & Access Control)

Additional Context

Documentation Reference

From Agent identity concepts in Microsoft Foundry:

Tool authentication

Agents access remote resources and tools by using agent identities for authentication. The authentication mechanism differs based on the agent's publication status:

  • Unpublished agents: Authenticate by using the shared project's agent identity.
  • Published agents: Authenticate by using the unique agent identity that's associated with the agent application.

When you publish an agent, you must reassign RBAC permissions to the new agent identity for any resources that the agent needs to access. This reassignment ensures that the published agent maintains appropriate access while operating under its distinct identity.

Impact

This issue has several critical implications:

  1. Security: Published agents may have broader permissions than intended since they inherit the shared project identity permissions
  2. Audit Trail: Cannot properly track which specific agent performed actions
  3. Least Privilege: Impossible to implement proper least-privilege access control per agent
  4. Governance: Cannot apply Conditional Access policies to individual published agents
  5. Lifecycle Management: RBAC changes intended for the published agent identity have no effect
    a custom MCP server hosted on Azure API Management. The MCP server returns mock data with authentication information for testing purposes. API Management trace logging was enabled to capture the authentication token details from incoming requests.

The API Management logs consistently show that the appid claim in the bearer token matches the project's shared agent identity ID, not the published agent's distinct agent identity ID. This confirms that the Foundry Agent Service runtime is not switching to the distinct identity after publication.

Test Setup:

  • MCP server endpoint hosted on Azure API Management
  • MCP tool configured with AgenticIdentityToken authentication
  • Agent configured to use the MCP tool
  • API Management trace logging enabled

Results from API Management trace:

  • Expected appid: <distinct-agent-identity-id> (from Agent Application JSON view)
  • Actual appid: <project-shared-identity-id> (from Project JSON view)

Testing Consistency:
This issue was verified using both invocation methods:

  • Python SDK (openai_client.responses.create() with agent_reference)
  • Foundry Portal (manual agent invocation through the UI)

Both methods produce identical results - the published agent consistently uses the project's shared agent identity instead of its distinct agent identity. This confirms the issue is in the Foundry Agent Service runtime, not specific to any client implementation.

Code Sample

# Before running the sample:
#    pip install --pre azure-ai-projects>=2.0.0b1
#    pip install azure-identity

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

myEndpoint = "https://<project-endpoint>.services.ai.azure.com/api/projects/<project-name>"

project_client = AIProjectClient(
    endpoint=myEndpoint,
    credential=DefaultAzureCredential(),
)

# Get the published agent
agent = project_client.agents.get(agent_name="published-agent-name")
print(f"Retrieved agent: {agent.name}")

openai_client = project_client.get_openai_client()

# Create a conversation to maintain context
conversation = openai_client.conversations.create()
print(f"Created conversation: {conversation.id}")

# Send initial request that will trigger MCP tool
response = openai_client.responses.create(
    conversation=conversation.id,
    input="Request that triggers MCP tool",
    extra_body={"agent": {"name": agent.name, "type": "agent_reference"}},
)

# Process any MCP approval requests
input_list = []
for item in response.output:
    if item.type == "mcp_approval_request" and item.id:
        print("\nMCP approval requested:")
        print(f"  Server: {item.server_label}")
        print(f"  Tool: {getattr(item, 'name', '<unknown>')}")
        print(f"  Arguments: {json.dumps(getattr(item, 'arguments', None), indent=2, default=str)}")
        
        should_approve = input("Approve this MCP tool call? (y/N): ").strip().lower() == "y"
        
        input_list.append({
            "type": "mcp_approval_response",
            "approve": should_approve,
            "approval_request_id": item.id,
        })

# If there were approval requests, send approval response
if input_list:
    print("\nSending approval response...")
    response = openai_client.responses.create(
        input=input_list,
        previous_response_id=response.id,
        extra_body={"agent": {"name": agent.name, "type": "agent_reference"}},
    )

print(f"\nResponse output: {response.output_text}")

# At this point, check API Management trace logs
# The appid claim will show the project's shared identity, not the published agent's distinct identity

Request

Please investigate why published agents are not using their distinct agent identities for tool authentication and ensure the runtime behavior matches the documented specification.

Metadata

Metadata

Assignees

Labels

BugSomething isn't workingSuggestionAn idea to improve the experience.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions