策略生成:按策略验证
使用策略创作服务根据自然语言生成策略时,会在生成过程中对每个策略进行验证和分析。
工作原理
-
自然语言已转换为 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" } ] }
每项策略的验证结果
生成的每个保单资产都包含一个Finding对象findings数组,每个对象都有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。该请求可能包含依赖于不受支持的数据或属性的条件。 |
仔细检查目标网关资源以了解工具定义。 |
|
|
警告 |
许可政策适用于所有委托人、操作和资源组合。 |
确认打算使用不受限制的访问权限。如果没有,请添加限制范围的条件。 |
|
|
警告 |
许可政策不是决定性的,因为它什么都不允许。 |
查看保单条件。该政策可能包含相互矛盾或无法达到的条件。 |
|
|
警告 |
策略拒绝所有委托人执行所有操作。 |
确认是否打算完全拒绝。由于禁止覆盖-许可语义,这会覆盖所有许可策略。 |
|
|
警告 |
禁止政策不是决定性的,因为它不否认任何内容。 |
查看保单条件。禁止政策可能包含相互矛盾或无法达到的条件。 |