政策產生:每個政策驗證
使用政策編寫服務從自然語言產生政策時,驗證和分析會在產生期間根據個別政策進行。
運作方式
-
自然語言會轉換為 Cedar 政策
-
每個產生的政策都會根據閘道結構描述進行驗證
-
分析會個別在每個政策上執行
-
結果可在產生回應中使用
範例:產生和驗證政策
擷取產生結果是一個兩步驟的程序:首先檢查產生狀態,然後列出產生的資產以查看政策及其驗證問題清單。
開始產生政策:
aws bedrock-agentcore-control start-policy-generation \ --policy-engine-id MyEngine-abc123 \ --name RefundPolicy \ --content '{ "rawText": "Allow customer service agents to process refunds up to 500 dollars for orders placed within the last 30 days" }' \ --resource '{ "arn": "arn:aws:bedrock-agentcore:us-east-1:123456789012:gateway/MyGateway-xyz789" }'
回應包含政策產生 ID 和狀態:
{ "policyGenerationId": "RefundPolicy-def456", "policyEngineId": "MyEngine-abc123", "status": "GENERATING" }
使用 get-policy-generation 檢查產生狀態:
aws bedrock-agentcore-control get-policy-generation \ --policy-engine-id MyEngine-abc123 \ --policy-generation-id RefundPolicy-def456
回應會顯示整體產生狀態:
{ "policyGenerationId": "RefundPolicy-def456", "status": "GENERATED", "statusReasons": [] }
一旦狀態為 GENERATED ,請列出產生的資產以擷取政策及其每個政策的驗證問題清單:
aws bedrock-agentcore-control list-policy-generation-assets \ --policy-engine-id MyEngine-abc123 \ --policy-generation-id RefundPolicy-def456
回應包含每個產生的政策及其 Cedar 定義和驗證調查結果:
{ "policyGenerationAssets": [ { "policyGenerationAssetId": "asset-1", "definition": { "cedar": { "statement": "permit(\n principal is AgentCore::OAuthUser,\n action == AgentCore::Action::\"RefundTool___process_refund\",\n resource == AgentCore::Gateway::\"arn:aws:bedrock-agentcore:us-east-1:123456789012:gateway/MyGateway-xyz789\"\n) when {\n context.input.amount <= 500\n};" } }, "findings": [ { "type": "VALID" } ], "rawTextFragment": "Allow customer service agents to process refunds up to 500 dollars" }, { "policyGenerationAssetId": "asset-2", "definition": { "cedar": { "statement": "permit(\n principal,\n action == AgentCore::Action::\"RefundTool___view_order_history\",\n resource\n);" } }, "findings": [ { "type": "ALLOW_ALL", "description": "Overly Permissive: Policy Engine will allow every request for the specified principal (AgentCore::OAuthUser), action (RefundTool___view_order_history) and resource (gateway/*) combination if the policy is added or updated" } ], "rawTextFragment": "Allow customer service agents to view order history" } ] }
每個政策的驗證問題清單
每個產生的政策資產都包含 物件findings陣列,每個Finding都有 type和 description 。下列範例顯示不同的問題清單類型:
通過驗證和分析的政策:
{ "findings": [ { "type": "VALID" } ] }
標記為過度寬鬆的政策:
{ "findings": [ { "type": "ALLOW_ALL", "description": "Overly Permissive: Policy Engine will allow every request for the specified principal (AgentCore::OAuthUser), action (RefundTool___view_order_history) and resource (gateway/*) combination if the policy is added or updated" } ] }
無法從自然語言輸入產生的政策:
{ "findings": [ { "type": "NOT_TRANSLATABLE", "description": "Unsupported Condition Error: The request includes conditions that rely on data or attributes currently not supported." } ] }
產生政策的常見調查結果
下表說明可針對產生的政策傳回的調查結果類型:
| 調查結果類型 | 嚴重性 | 說明 | 建議的動作 |
|---|---|---|---|
|
|
成功 |
政策是有效的 Cedar,沒有問題清單。此調查結果類型不會傳回任何描述。 |
不需要採取行動。政策已準備好可供使用。 |
|
|
錯誤 |
產生的 Cedar 政策包含語法錯誤或不符合閘道結構描述。 |
檢閱產生的政策是否有結構描述違規或語法問題。重述自然語言輸入並重新產生。 |
|
|
錯誤 |
自然語言無法轉換為有效的 Cedar。請求可能包含依賴不支援的資料或屬性的條件。 |
再次檢查目標閘道資源是否有工具定義。 |
|
|
警告 |
許可政策適用於所有委託人、動作和資源組合。 |
確認意圖存取不受限制。如果沒有,請新增條件來限制範圍。 |
|
|
警告 |
許可政策未確定,因為它不允許任何內容。 |
檢閱政策條件。政策可能包含矛盾或無法連線的條件。 |
|
|
警告 |
政策拒絕所有主體的所有動作。 |
確認完全拒絕是預定的。由於forbid-overrides-permit允許語意,這會覆寫所有允許政策。 |
|
|
警告 |
禁止政策未確定,因為它不拒絕任何內容。 |
檢閱政策條件。禁止政策可能包含矛盾或無法連線的條件。 |