在 AgentCore VPC 设置中使用 IAM 条件密钥
使用 Amazon Bedrock AgentCore-specific 条件键进行 VPC 设置,可以更精确地控制 AgentCore 资源的权限。例如,要求组织中的所有运行时都连接到 VPC,或者强制将网关目标部署到批准的子网中。指定用户可以和不能使用的子网和安全组。
AgentCore 在 IAM 策略中支持以下条件键:
-
bedrock-agentcore: subnets — 允许或拒绝一个或多个子网。
-
bedrock-agentCore: SecurityGroups — 允许或拒绝一个或多个安全组。
以下 Cont AgentCore rol Plane API 操作支持这些条件键:
-
AgentCore 运行时和内置工具 —
CreateAgentRuntimeUpdateAgentRuntime、CreateCodeInterpreter、和CreateBrowser -
AgentCore 网关 —
CreateGatewayTarget和UpdateGatewayTarget(为目标配置托管 VPC 资源时)
有关在 IAM 策略中使用条件键的更多信息,请参阅 IAM 用户指南中的 IAM JSON 策略元素:条件。有关网关条件密钥的更多信息,请参阅在 A mazon Bedrock Gate AgentCore way 中使用 IAM 条件密钥。
带有用于 VPC 设置的条件键的策略示例
以下示例演示如何将条件键用于 VPC 设置。创建具有所需限制的策略声明,然后将该策略声明附加到目标用户或角色。
要求用户仅部署 VPC-connected 运行时和工具
要要求所有用户仅部署 VPC-connected AgentCore 运行时和内置工具,请拒绝不包含有效子网和安全组的运行时以及工具创建和更新操作。
{ "Sid": "EnforceVPCRuntime", "Action": [ "bedrock-agentcore:CreateAgentRuntime", "bedrock-agentcore:UpdateAgentRuntime", "bedrock-agentcore:CreateCodeInterpreter", "bedrock-agentcore:CreateBrowser" ], "Effect": "Deny", "Resource": "*", "Condition": { "Null": { "bedrock-agentcore:subnets": "true", "bedrock-agentcore:securityGroups": "true" } } }
强制用户仅使用特定的子网和安全组
要强制用户仅使用经批准的特定子网和安全组,请使用带StringNotEquals的 s ForAnyValue et 运算符。如果请求中的任何一个上下文键值与策略中的上下文键值不匹配,则拒绝包含任何未经批准的值的请求,则条件将返回 true。以下示例强制用户只能对子网使用subnet-0123456789abcdef0和,subnet-0123456789abcdef1sg-0123456789abcdef1对安全组只能使用sg-0123456789abcdef0和。
[ { "Sid": "DenyIfNotSpecificSubnets", "Effect": "Deny", "Action": [ "bedrock-agentcore:CreateAgentRuntime", "bedrock-agentcore:UpdateAgentRuntime", "bedrock-agentcore:CreateCodeInterpreter", "bedrock-agentcore:CreateBrowser" ], "Resource": "*", "Condition": { "ForAnyValue:StringNotEquals": { "bedrock-agentcore:subnets": ["subnet-0123456789abcdef0", "subnet-0123456789abcdef1"] } } }, { "Sid": "DenyIfNotSpecificSecurityGroups", "Effect": "Deny", "Action": [ "bedrock-agentcore:CreateAgentRuntime", "bedrock-agentcore:UpdateAgentRuntime", "bedrock-agentcore:CreateCodeInterpreter", "bedrock-agentcore:CreateBrowser" ], "Resource": "*", "Condition": { "ForAnyValue:StringNotEquals": { "bedrock-agentcore:securityGroups": ["sg-0123456789abcdef0", "sg-0123456789abcdef1"] } } } ]
拒绝用户访问特定子网或安全组
要拒绝用户访问特定子网和安全组,请使用带StringEquals的 s ForAnyValue et 运算符。如果请求中的任何一个上下文键值与策略中的任何一个上下文键值匹配,则条件返回 true。以下示例拒绝用户访问subnet-0123456789abcdef0子网、子网访问sg-0123456789abcdef0和sg-0123456789abcdef1访问安全组。subnet-0123456789abcdef1
[ { "Sid": "EnforceOutOfSubnet", "Action": [ "bedrock-agentcore:CreateAgentRuntime", "bedrock-agentcore:UpdateAgentRuntime", "bedrock-agentcore:CreateCodeInterpreter", "bedrock-agentcore:CreateBrowser" ], "Effect": "Deny", "Resource": "*", "Condition": { "ForAnyValue:StringEquals": { "bedrock-agentcore:subnets": ["subnet-0123456789abcdef0", "subnet-0123456789abcdef1"] } } }, { "Sid": "EnforceOutOfSecurityGroups", "Action": [ "bedrock-agentcore:CreateAgentRuntime", "bedrock-agentcore:UpdateAgentRuntime", "bedrock-agentcore:CreateCodeInterpreter", "bedrock-agentcore:CreateBrowser" ], "Effect": "Deny", "Resource": "*", "Condition": { "ForAnyValue:StringEquals": { "bedrock-agentcore:securityGroups": ["sg-0123456789abcdef0", "sg-0123456789abcdef1"] } } } ]