View a markdown version of this page

策略范围 - Amazon Bedrock AgentCore

策略范围

范围定义了政策的适用范围。每个 Cedar 政策都指定了三个组成部分:

permit( principal is AgentCore::OAuthUser, // WHO is making the request action == AgentCore::Action::"...", // WHAT they want to do resource is AgentCore::Gateway::"..." // WHICH resource they want to access )

实体和命名空间

Cedar 使用实体来表示委托人、操作和资源。 AgentCore Gateway 中的所有实体都使用 AgentCore 命名空间。

实体格式:Namespace::EntityType::"identifier"

Principal

委托人标识提出授权请求的实体。主体类型取决于您的 AgentCore 网关的身份验证配置方式。

OAuth 用户负责人

使用 OAuth 授权时,委托人是:AgentCore::OAuthUser

principal is AgentCore::OAuthUser

组件:

  • principal-提出授权请求的实体

  • AgentCore::OAuthUser-代表 OAuth-authenticated 用户的实体类型

  • is-类型检查运算符(匹配任何 OAuthUser 实体)

校长是 OAuth-authenticated 用户。每个用户都有一个来自 JWT 订阅声明的唯一 ID。

IAM 实体负责人

使用 AWS_IAM 授权时,委托人是:AgentCore::IamEntity

principal is AgentCore::IamEntity

组件:

  • principal-提出授权请求的实体

  • AgentCore::IamEntity-代表 IAM-authenticated 来电者的实体类型

  • is-类型检查运算符(匹配任何运算符 IamEntity)

IAM 委托人有一个包含调用方的 IAM ARN 的id属性。您可以对该属性使用模式匹配来实现基于帐户或基于角色的访问控制。

处理建议

该操作指定了所请求的操作:

action == AgentCore::Action::"RefundTool___process_refund"

组件:

  • action-正在请求的操作

  • AgentCore::Action::"RefundTool___process_refund"-特定操作实体

  • ==-精确匹配运算符(仅此特定操作)

操作表示 MCP AgentCore 网关中的工具调用。每个工具都有一个对应的动作实体。

按目标类型划分的操作名称

策略中的操作标识符取决于网关上配置的目标类型:

Target type 操作格式 示例

MCP

<TargetName>___<ToolName>

NotesTool___manage_notes

AgentCore 运行时间

<TargetName>___<METHOD>:/invocations

StrandsAgentTarget___POST:/invocations

代理 (HTTP)

<TargetName>___<METHOD>:<uri>

MyAPI___POST:/inference/v1/chat/completions

多个动作

Cedar 支持通配符操作。必须使用确切的操作标识符 (AgentCore::Action::"ToolName___operation") 显式引用每个操作。要将多个工具分组到一个规则下,请使用网关目标(操作组)并针对该目标编写策略。

例如,要仅允许访问名称以 Read 开头的工具,您可以创建一个名为 Gateway Target ReadToolsTarget ,其中包含每个此类工具,然后编写如下策略:

permit( principal, action in AgentCore::Action::"ReadToolsTarget", resource == AgentCore::Gateway::"<gateway-arn>" );

这将允许该目标中包含的所有工具,具体取决于政策的效果。

资源

该资源标识请求的目标:

resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/refund-gateway"

组件:

  • resource-请求的目标

  • AgentCore::Gateway-代表网关实例的实体类型

  • ==-精确匹配运算符(匹配此特定 AgentCore 网关)

AgentCore 网关是路由工具调用的 MCP 服务器。

资源特殊性要求

指定一项或多项特定操作时,必须使用特定的 AgentCore 网关 ARN:

// Required: Specific Gateway ARN for specific action(s) resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/refund-gateway"

这适用于:

  • 单一动作:action == AgentCore::Action::"ToolName"

  • 多个特定操作:action in [AgentCore::Action::"Tool1", AgentCore::Action::"Tool2"]

仅在匹配任何操作时才使用类型检查:

// For policies covering any action (not specific tools) resource is AgentCore::Gateway

示例:

// Blocks all actions forbid(principal, action, resource); // Allow any CallTool action permit(principal, action in AgentCore::Action::"CallTool", resource is AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/refund-gateway");

特定的 AgentCore 网关 ARN 提供:

  • AgentCore 网关实例之间的安全隔离

  • 生产和开发环境的分离

  • Fine-grained 每个 AgentCore 网关的访问控制