-ダニエル・ベース
/ダニエル・ベース
AIエージェントの使用を通じてアプリケーションのパフォーマンスを向上させることは、業界全体のハイプや実際の有用な使用事例のせいで非常に一般的な実践となっています。
These AI agents, however, often require access to highly sensitive data, introducing significant security risks. Without standardized access control solutions, development teams often build security measures from scratch—leading to cases where AI assistants expose sensitive patient information and several AI agents being compromised through sophisticated prompt injection attacks.
AI assistants expose sensitive patient informationsophisticated prompt injection attacks
この文脈におけるAIエージェントの保護は、AIエージェント自身の能力と同じくらい重要になってきています。
To address this problem, we at Permit.io have been working for a while on a structured security approach I wish to introduce to you today:
Permit.ioThe Four-Perimeter FrameworkThe Four-Perimeter Framework
This method provides a comprehensive strategy for protecting AI agents by implementing fine-grained access control, ensuring compliance, and mitigating potential attack vectors. Before I go into the solution, let’s talk more about the problem space.
fine-grained access controlThe Problem: AI Security Risks in Sensitive Domains
Traditional application security measures and access control mechanisms fall short when it comes to handling AI agents. While conventional access control systems like role-based access control (RBAC) excel at managing static permissions, they struggle with the dynamic nature of AI responses. Unlike traditional applications where inputs map to predictable outputs and access patterns are well-defined, AI generates unique responses for each query. This means the access control and input validation techniques we’re used to can’t anticipate all possible outputs.
role-based access control (RBAC)
The way AI systems access data also doesn’t fit security standards. To provide accurate and helpful responses, AI agents need broad access to various data sources and knowledge bases. Classic RBAC proves too rigid for this need - you can’t simply assign static permissions when the data requirements change based on context. This calls for a more sophisticated, attribute-based approach that can make dynamic access decisions.
attribute-based
もう一つの懸念は、AIシステムが導入する新たな攻撃ベクターです。従来のセキュリティ対策は、迅速な注入攻撃、モデル抽出の試み、またはデータ中毒攻撃に対処するように設計されていませんでした。
このソリューションは、4つの基本的な周囲に構築された包括的なセキュリティフレームワークの形で提供されています -
The Solution: The Four-Perimeter Framework
AIアプリケーションは、入力を処理し、データを取得し、アクションを実行し、出力を生成する方法で標準のソフトウェアと異なるため、これらの課題に対処するためには、AI相互作用のあらゆる段階にアクセス制御を適用する構造化されたセキュリティアプローチが必要です。
The Four-Perimeter Framework is designed to enforce identity-aware, fine-grained authorization throughout the AI lifecycle. It introduces security boundaries that govern what data AI models can access, what operations they can perform, and how their responses are validated.
Four-Perimeter Frameworkfine-grained authorization throughout the AI lifecycle
このフレームワークは4つの部分から構成されています:
- Prompt Filtering - 検証済み、安全な入力のみがAIモデルに到達することを保証する。
- RAG Data Protection - 外部情報源へのAIアクセスを制御する。
- Secure External Access - 外部ツールと相互作用する際にAIエージェントの許可を定義する。
- Response Enforcement - コンプライアンスチェックを適用し、AI生成出力のフィルタリング。
- Prompt Filtering - 検証済みで安全な入力のみがAIモデルに到達することを保証します。スピードフィルタリング
- RAG Data Protection - 外部情報源へのAIアクセスを制御する。RAGデータ保護
- Secure External Access - 外部ツールと相互作用する際にAIエージェントの権限を定義する。セキュアな外部アクセス
- Response Enforcement - Applying compliance checks and filtering AI-generated outputs. 応答実施
- ABAC for Prompt Filtering AI モデルは非構造化された入力を処理し、従来のセキュリティ規則の適用を困難にする。
- ABAC for Prompt Filtering AI モデルは非構造化された入力を処理し、従来のセキュリティルールを適用することが困難になります。ABAC for Prompt Filtering
- ReBAC for RAG Data Protection Retrieval-augmented generation (RAG) allows AI models to draw information from vector databases. ReBAC provides a natural way to enforce security in this setup by defining relationships between users, data sources, and AI agents. Instead of allocating static permissions, ReBAC dynamically grants or denies access based on how data objects relate to each other — enabling context-aware retrieval permissions. ReBAC は、データオブジェクトが互いにどのように関連しているかによって、静的な許可を割り当てる代わりに、データオブジェクトがどのように関連しているかによってアクセスを許可する自然な方法を提供します。
- ReBAC for RAG Data Protection Retrieval-augmented generation (RAG) により、AI モデルはベクトルデータベースから情報を抽出できます。ReBAC は、ユーザー、データソース、AI エージェント間の関係を定義することによって、この設定でセキュリティを強化する自然な方法を提供します。REBAC for RAG Data Protection
How Does a Step-by-Step Implementation Look Like?
Let's walk through a practical implementation to see the Four-Perimeter Framework in action. This example secures an AI agent by validating prompts, enforcing data protection, restricting external access, and moderating responses—leveraging Permit.io AI Access Control integrations at each step.
Four-Perimeter Framework in Actionvalidating prompts, enforcing data protection, restricting external access, and moderating responses コマンドの確認、データ保護の強化、外部アクセスの制限、および反応の制限Permit.io AI Access ControlPermit.io1
1 Implement Prompt Filtering
第1のセキュリティ・ペリメーターは、AI 入力がモデルに到達する前に検証し、浄化することに焦点を当てています。
- 認証チェックは、即時認証パイプラインに組み込まれており、不正なデータがAI出力に影響を与えないようにします。
- Role、attribute、 and relationship-based access control are enforced, ensuring only approved parameters pass to the AI.
- Any policy violations are logged and blocked in real time, preserving an auditable trail of access decisions.
- Authorization checks are embedded into the prompt validation pipeline, preventing unauthorized data from influencing AI outputs.
ライセンスチェックは即時検証パイプラインに組み込まれ、不正なデータがAI出力に影響を与えるのを防ぐ。- Role、attribute、 and relationship-based access control are enforced, ensuring only approved parameters pass to the AI.
- ポリシー違反はリアルタイムで記録され、アクセス決定の監査可能なトラックを保持します。
ここでは、プロンプトをフィルタする3つの方法 - 最も簡単から最も高度なまで:
- Token validation - プロンプトの長さやシステム内の実行入力の一般許可などの単純なチェックのための効率的な方法。この方法の許可チェック機能はテキストプロンプトの構造属性を調べます。
- パターンマッチング - この方法では、許可チェックはプロンプトテキストのパターンを調べます。 たとえば、パターンがSQLクエリまたはコード例に合致するかどうかを調べます。
- AI分類 - このリストで最も先進的な方法は、AI分類は、専用のシステムプロンプトを使用してプロンプトを分析し、許可チェックで正確に解析できる構造
- Token validation - プロンプトの長さやシステム内の実行入力の一般許容などの単純なチェックのための効率的な方法。トークン認証
- Pattern Matching - this method, the permission check examines patterns in the prompt text. Checking, for example, if the pattern matches an SQL query or code example. この方法では、許可チェックは、プロンプトテキスト内のパターンを検証します。パターンマッチング
- AI分類 - このリストで最も先進的な方法は、AI分類は、専用のシステムのプロンプトを使用してプロンプトを分析するためにAIを使用し、それを許可チェックで正確に分析できる構造化された入力に分類します。AI分類
Prompt フィルタリング with PydanticAI
Prompt Filtering with PydanticAI効率的なプロンプトフィルタリングの実装を最適に示すために、ここでは、PydanticAIツールを使用してAIエージェントへのユーザー入力をフィルタリングする例です。
The following GitHub repository contains a full implementation of the framework for PydanticAI: github.com/permitio/permit-pydanticai
github.com/permitio/permit-pydanticai
Security
@financial_agent.tool async def validate_financial_query( ctx: RunContext[PermitDeps], query: FinancialQuery, ) -> bool: ""Key checks: - ユーザがAIアドバイスに明示的にオプションをオプションした場合 - 同意が正しく記録され、検証されている場合 - アドバイスを要求している場合の分類Args: ctx: Context containing Permit client and user ID query: The financial query to validate Returns: bool: True if user has consented to AI advice, False otherwise "" try: #Classify if the prompt is requesting advice_seeking_advice = classify_promptfor
@financial_agent.tool async def validate_financial_query( ctx: RunContext[PermitDeps], query: FinancialQuery, ) -> bool: """Key checks: - User has explicitly opted in to AI financial advice - Consent is properly recorded and verified - Classifies if the prompt is requesting advice Args: ctx: Context containing Permit client and user ID query: The financial query to validate Returns: bool: True if user has consented to AI advice, False otherwise """ try: # Classify if the prompt is requesting advice is_seeking_advice = classify_prompt_for_advice(query.question) permitted = await ctx.deps.permit.check( # The user object with their attributes { "key": ctx.deps.user_id, }, # The action being performed "receive", # The resource being accessed { "type": "financial_advice", "attributes": {"is_ai_generated": is_seeking_advice}, }, ) if not permitted: if is_seeking_advice: return "User has not opted in to receive AI-generated financial advice" else: return "User does not have permission to access this information" return True except PermitApiError as e: raise SecurityError(f"Permission check failed: {str(e)}")
2 Enforce Data Protection –
2 データ保護を強化する -Next, we secure recovery-augmented generation (RAG) queries by ensuring AI models can only access authorized knowledge sources. This can be achieved through fine-grained filtration of the AI agent data on behalf of the user within the AI workflow:
retrieval-augmented generation (RAG)authorized knowledge sources 情報源
- The fine-grained policy uses advanced data filtering models, such as relationship-based access control, to allow advanced query filtering to the policy engine.
- AI エージェントに接続されたベクトルおよびグラフソースには、エンジンが非構造化クエリを操作し、それを許可されたデータのみを含めるようにフィルタリングするのに役立つメタデータが含まれています。
- The fine-grained policy uses advanced data filtering models, such as relationship-based access control, to allow advanced query filtering to the policy engine.
- ポリシーは、ポリシーエンジンに高度なクエリフィルタを許可するために、関係ベースのアクセス制御などの高度なデータフィルタリングモデルを使用します。
- AIエージェントに接続されたベクトルおよびグラフソースには、エンジンが非構造的なクエリを操作し、許可されたデータのみを含めるようにフィルタリングするのに役立つメタデータがあります。
- エージェントが RAG 知識ベースからデータを取得するたびに、ユーザーの許可に応じて結果をフィルタリングします。
エージェントアプリケーションが RAG フィルタリングを実行するときは、以下の方法のいずれかを使用します:
FilterObjects
―この方法では、グラフアプリケーションは RAG から関連するすべてのデータを取得し、その後ユーザー権限ごとにそれらをフィルタします。この機能の利点は、ポリシー エンジンが RAG データを無状態で知らないように保つことです。GetUserPermissions
- この方法では、エージェントは RAG に非構造化されたクエリを提供します。FilterObjects
- この方法では、グラフアプリケーションは RAG からすべての関連データを取得し、その後、ユーザーの許可に応じてそれらをフィルタします。FilterObjects
GetUserPermissions
- この方法では、エージェントは RAG に非構造化されたクエリを提供します。 RAG はGetUserPermissions
関数を呼び出し、非構造化された RAG クエリにフィルタークエリを付加します。GetUserPermissions
GetUserPermissions
RAG Data Protection with Langchain
RAG Data Protection with LangchainLangchainは、有名なAIアプリケーションフレームワークで、あらゆる種類のデータソースと組み合わせることができるカスタマイズされたリトリバーの素晴らしいサポートを提供するリトリバーコンポーネントで知られています。例えば、
SelfQueryRetriever
を使用すると、通常のRAGをGetUserPermissions
機能で巻き込むことができます。SelfQueryRetriever
GetUserPermissions
# 1. メモリ内の小さなベクトルストアの埋め込みを構築する = OpenAIEmbeddings()ベクトルストア = FAISS.from_documents(docs, embedding=embeddings) # 2. PermitSelfQueryRetriever retriever = PermitSelfQueryRetriever( api_key=os.getenv("PERMIT_API_KEY", ""), pdp_url=os.getenv("PERMIT_PDP_URL"), user=USER, resource_type=RESOURCE_TYPE, action=ACTION, llm=embeddings, vectorstore=vectorstore, enable_limit=False,
# 1. Build a small in-memory vector store embeddings = OpenAIEmbeddings() vectorstore = FAISS.from_documents(docs, embedding=embeddings) # 2. Initialize the PermitSelfQueryRetriever retriever = PermitSelfQueryRetriever( api_key=os.getenv("PERMIT_API_KEY", ""), pdp_url=os.getenv("PERMIT_PDP_URL"), user=USER, resource_type=RESOURCE_TYPE, action=ACTION, llm=embeddings, vectorstore=vectorstore, enable_limit=False, )
The following repository contains the full implementation of the framework for Langchain: https://github.com/permitio/langchain-permit
https://github.com/permitio/langchain-permit3 Secure External Access –
3 セキュアな外部アクセス -AIエージェントはしばしば外部のAPI、サービス、および自動化ツールと相互作用します。適切なアクセス制御がなければ、許可されていないアクションを実行するリスクがあります。
- Using models like MCP, which defines a server-client model where AI agents interact with external services, is a great step in enabling security for AI external access (e.g., databases, APIs, payment systems).
- The AI action infrastructure can use a service like Permit.io to perform authorization checks at the action level, checking who’s making a request and what action they want to perform.
- Developers are able to assign machine identities to AI agents, limiting their capabilities to pre-approved functions only.
- AIエージェントが外部サービスと相互作用するサーバークライアントモデルを定義するMCPのようなモデルを使用することは、AI外部アクセス(データベース、API、支払いシステムなど)のセキュリティを可能にする大きなステップです。
- The AI action infrastructure can use a service like Permit.io to perform authorization checks at the action level, checking who’s making a request and what action they want to perform. Permit.io
- 開発者はAIエージェントにマシンアイデンティティを割り当てることができ、その機能は事前に承認された機能に限られます。
GPTと自然言語インターフェイスは新しいものではありませんが、ユーザーの名義でアクションを実行させることは、多くのエンジニアが直面している新しい課題です。
- Direct access security - 最も単純なレベルです。ユーザーはAIエージェントにHTTP呼び出しなどの操作を実行するように依頼します。AIエージェントは、現在の文脈とユーザーを考慮して、操作が許可されているかどうかをチェックすることを知っています。
- Agent-to-agent コミュニケーション - この次のレベルでは、AIエージェントが最小の特権の原則に基づいて行動を行うことを可能にするアイデンティティと許可のキャスティングフローを必要とします。このレベルでは、人と非人間のアイデンティの間の関係を使用して、許可の異なるレベルをカスケードしたいと思います。
- Direct access security - the simplest level. A user asks an AI agent to perform an operation, such as a HTTP call. The AI agent knows to check if the operation is allowed, considering the current context and user.
- Direct Access セキュリティ
- エージェント対エージェントコミュニケーション - この次のレベルでは、エージェント自身が最小特権の原則に基づいて行動を行うことを可能にするアイデンティティと許可のキャスティングフローを必要とします。エージェント対エージェントコミュニケーション
- Access request flows - 外部アクセスの最もエキサイティングなレベルは、AIエージェントが操作を実行したいときに、人間のユーザーから直接アクセスを要求する必要性を理解するときです。アクセスリクエストフロー
MCP、Human-in-the-Loop、および外部アクセス
MCP、Human-in-the-Loop、およびExternal AccessModel Context Protocol は Anthropic が導入した新しいプロトコルで、AI エージェントが積極的なアクションを実行できるようにする問題を解決し、外部アクセスを確保するための最大の可能な手段として機能します。
次の例では、アクセスリクエストフローを管理する方法を知っているMCPサーバを示し、人間をループに導入し、Permit.ioのAPIを使用して許可を要求します。
You can see the full code example for the MCP access request server here: https://github.com/permitio/permit-mcp
https://github.com/permitio/permit-mcp
@mcp.tool() async def request_access(ユーザ名: str, resource_name: str) -> dict: ""システム内の特定のリソースへのアクセスリクエスト呼び出しArgs:ユーザ名:アクセスリソースをリクエストする人のユーザ名:ユーザのリソースタイプは、リソース_nameのためのアクセスリクエストをリクエストするレストランの名前を返す """ = wait permit.elements.login_as({ "userId": slugify(ユーザ名)、 "tenant: "default"}のユーザ名(ログイン) url ="https://pay.permit.io/v2/facts/{PROJECT_ID}/
@mcp.tool() async def request_access(username: str, resource: str, resource_name: str) -> dict: """ Initiate access request call to a specific resource in the system Args: username: The username of the person requesting access resource: The resource type the user is request access for resource_name: The name of the restaurant to request access for """ login = await permit.elements.login_as({ "userId": slugify(username), "tenant": "default"}) print(login) url = f"https://api.permit.io/v2/facts/{PROJECT_ID}/{ENV_ID}/access_requests/{ELEMENTS_CONFIG_ID}/user/{slugify(username)}/tenant/default" payload = { "access_request_details": { "tenant": "default", "resource": resource, "resource_instance": resource_name['id'], "role": "viewer", }, "reason": f"User {username} requests role 'viewer' for {resource_name}" } headers = { "authorization": "Bearer YOUR_API_SECRET_KEY", "Content-Type": "application/json", } async with httpx.AsyncClient() as client: await client.post(url, json=payload, headers=headers) return "Your request has been sent. Please check back later."
4
4 認証 AI 応答 -
The final perimeter enforces content moderation and compliance on AI-generated responses. This can be done by creating a workflow that applies policy-based filtration before delivering AI outputs:
- A permission check can be added to the agent application, enabling policy enforcement at each step of the chain before the user actually gets a response.
- Combined data validation and authorization workflows ensure that only validated and permitted data can move forward.
- ユーザーに返される応答は、事前定義された制限に基づいて編集することができ、データのマスクや使用制限についてユーザーに通知することを可能にします。
- A permission check can be added to the agent application, enabling policy enforcement at each step of the chain before the user actually gets a response.
- ユーザーが実際に回答を得る前に、チェーンの各段階でポリシーの執行を可能にします。
- データ検証と認証ワークフローの組み合わせにより、検証済みおよび許可済みのデータのみが前進できるようにします。
- ユーザーに返される応答は、事前定義された制限に基づいて編集することができ、データのマッキングまたは使用制限についてユーザーに通知することができる。
Langflowによる応答フィルタリング
Langflowによる応答フィルタリングIn the following example, we use Langflow, a visual no-code AI applications editor, to create a permissions check component that’s positioned before any chat response to the user. Using LangFlow's friendly flow modeling capabilities, you can easily append another component that masks unwanted details in returned responses. This repository contains all the access control components required for secured Langflow applications.
This repository
結論
AIシステムは各業界のアプリケーションに急速に統合されていますが、従来のソフトウェアと比較してセキュリティフレームワークは未開発です。 適切なアイデンティティー認識のアクセス制御がなければ、AIエージェントは機密データを暴露し、許可されていない操作を実行し、コンプライアンスガイドラインに該当しない反応を生成するリスクがあります。
The Four-Perimeter Framework offers a structured way to secure AI workflows at every stage—from validating prompts and protecting retrieval-augmented generation (RAG) data to controlling AI-driven external actions and enforcing response compliance. By leveraging fine-grained authorization (FGA) with ABAC and ReBAC, developers can ensure AI agents remain both functional and secure, adapting dynamically to real-world security scenarios.
Instead of building access control from scratch, Permit.io’s AI Access Control integrations with PydanticAI, LangChain, MCP, and LangFlow allow teams to embed security directly into their AI applications—without disrupting development workflows. Try it yourself here.
Try it yourself here
しかし、この分野はまだ比較的新しいものであり、AIエージェントを保護するための最良の実践はまだ進化している。The Four-Perimeter Framework is an experimental approach, and while it provides a strong foundation, I recognize that real-world deployments always require further refinement and adaptation.
I’d love to hear your feedback, thoughts, and ideas on how to improve this framework to make it even better for production-ready AI systems - comment here, or hit me up in our Slack community.
Slack community
Fine-grained access control (FGA) 原則をこれらの周辺に適用することで、AI エージェントは、柔軟性と機能性を犠牲にすることなく、 安全、監査可能、およびコンプライアンスを維持します。Fine-grained Access Control (FGA)セキュア、監査可能、およびコンプライアンス 前述したように、RBACのような伝統的なアクセス制御方法は、AIのダイナミックで文脈依存的な行動を処理できなくなります。これは、特性ベースのアクセス制御(ABAC)と関係ベースのアクセス制御(ReBAC)を通じて、フィン・グレイド・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・オブ・ Where Does FGA Come In?