跳到正文
DEV Community· Ashwin·· 3 小時前AI 評分54

如何為 AI 智能體構建授權閘道:實用架構

Building an Authorization Gateway for AI Agents: A Practical Architecture

AI 導讀

Ashwin提出在 AI 智能體與企業 API 之間設置獨立授權閘道,由閘道驗證身份、評估政策並決定操作是否獲準。文章以 Python 展示基本政策檢查,並指出正式環境還需驗證已認證主體、委派、資源歸屬及租戶邊界。閘道亦應按政策執行人手審批並記錄授權決策,文中的簡化範例不屬正式環境級別。

正文

AI agents are increasingly capable of interacting with external APIs and enterprise systems.

But consider this scenario:

You build an AI agent that can access Gmail, update Salesforce, and interact with cloud infrastructure.

How do you prevent it from performing an action that the requesting user was never authorized to perform?

A common mistake is to give the agent a service account with broad permissions.

That makes implementation easier, but it creates a significant security risk.

Let's explore a better approach: an authorization gateway for AI agents.

*1. The architecture
*

Instead of allowing agents to communicate directly with enterprise APIs, route actions through an authorization gateway.

User Request
|
v
AI Agent
|
v
Action Request
|
v
Authorization Gateway
|
+---- Identity Validation
|
+---- Policy Evaluation
|
+---- Permission Check
|
v
Enterprise API
|
v
Audit Event

The agent proposes an action. The gateway determines whether that action is authorized.

The agent should not be responsible for granting itself permission.

*2. Define an agent identity
*

An agent needs an identity that is independent of its LLM provider.

*Example:
*

{
"agent_id": "crm-agent-001",
"owner": "sales-platform",
"environment": "production",
"allowed_actions": [
"customer.read",
"customer.update"
]
}

In a production implementation, identity records should be maintained in a trusted registry rather than accepted directly from an agent request.

*3. Define an action request
*

Every action should carry enough information for the gateway to evaluate it.

{
"agent_id": "crm-agent-001",
"principal_id": "employee-123",
"task_id": "task-987",
"resource": "customer/456",
"action": "customer.update"
}

The principal_id must be established through a trusted authentication and delegation process. It must not simply be trusted because the agent included it in JSON.

*4. Implement a basic policy check
*

A simplified Python example:

AGENT_POLICIES = {
"crm-agent-001": {
"customer.read",
"customer.update"
}
}

def authorize_action(agent_id, action):
allowed = AGENT_POLICIES.get(agent_id, set())

if action not in allowed:
    return {
        "authorized": False,
        "reason": "Action not permitted"
    }

return {
    "authorized": True,
    "reason": "Policy allows action"
}

This demonstrates the basic decision, but it is not production-grade authorization.

A real gateway must also validate the authenticated principal, delegation, resource ownership, tenant boundaries, credential scope, and applicable contextual policies.

*5. Add a human approval boundary
*

Not every action should be treated equally.

*For example:
*

  • Action
  • Suggested policy
  • Read a customer record
  • Automatic if authorized
  • Update a customer record
  • Automatic with scoped permission
  • Send an external email
  • Approval based on policy
  • Delete a customer account
  • Explicit approval
  • Modify production infrastructure
  • Strong approval controls

Human approval should be enforced by the gateway, not merely requested through an LLM prompt.

*6. Add audit logging
*

Every authorization decision should produce an event.

{
"event_type": "agent.authorization",
"agent_id": "crm-agent-001",
"task_id": "task-987",
"action": "customer.update",
"resource": "customer/456",
"decision": "ALLOW",
"timestamp": "2026-11-02T12:00:00Z"
}

Production systems should also capture the authenticated principal, policy version, correlation ID, execution result, and relevant delegation metadata.

Avoid logging access tokens, secrets, or unnecessary sensitive customer data.

*7. What should a production implementation add?
*

The simplified example is a starting point. A real enterprise authorization gateway should include:

  • OAuth 2.0 / OpenID Connect integration.
  • Short-lived, scoped credentials.
  • Token exchange or equivalent delegated authorization.
  • Centralized policy management.
  • Resource-level authorization.
  • Agent identity registration and revocation.
  • Rate limits and execution budgets.
  • Tamper-resistant audit storage.
  • Human approval workflows.
  • Multi-tenant isolation.

It should also ensure that a delegated agent cannot obtain broader permissions than the original authorization allows.

*8. Why this matters
*

Agent frameworks will continue to evolve. LLM providers will change. New orchestration technologies will emerge.

But enterprise security cannot be tightly coupled to a particular model or agent framework.

An independent authorization layer creates a consistent security boundary across different agent implementations.

*The key architectural principle is simple:
*

An AI agent may decide what action it wants to perform, but a trusted authorization layer must decide whether it is allowed to perform it.

That separation could become one of the foundational requirements for enterprise agent infrastructure.

What approach are you taking to identity and authorization in your agent implementations?

About the Author

Ashwin Giridharan writes about Cloud & Enterprise Architecture, AI Infrastructure, Generative AI, and Agentic AI.

Website: https://ashwingiridharan.com/

LinkedIn: https://www.linkedin.com/in/ashwingiridharan7/

GitHub: https://github.com/giridharan-ashwin

Medium: https://medium.com/@gashwin7

Follow me for more discussions on enterprise architecture, AI infrastructure, and building production-ready AI systems.

來源:DEV Community · dev.to