搭配 AgentCore VPC 設定使用 IAM 條件金鑰
針對 VPC 設定使用 Amazon Bedrock AgentCore 特定條件金鑰,以更精確地控制 AgentCore 資源的許可。例如, 要求組織中的所有執行時間都連接到 VPC,或強制執行閘道目標部署到核准的子網路。指定使用者可和不可使用的子網路和安全群組。
AgentCore 在 IAM 政策中支援下列條件金鑰:
-
bedrock-agentcore:subnets – 允許或拒絕一或多個子網路。
-
bedrock-agentcore:securityGroups – 允許或拒絕一或多個安全群組。
下列 AgentCore 控制平面 API 操作支援這些條件金鑰:
-
AgentCore 執行期和內建工具 –
CreateAgentRuntime、CreateCodeInterpreter、UpdateAgentRuntime和CreateBrowser -
AgentCore Gateway –
CreateGatewayTarget和UpdateGatewayTarget(設定目標的受管 VPC 資源時)
如需在 IAM 政策中使用條件金鑰的詳細資訊,請參閱《IAM 使用者指南》中的 IAM JSON 政策元素:條件。如需閘道條件金鑰的詳細資訊,請參閱搭配 Amazon Bedrock AgentCore Gateway 使用 IAM 條件金鑰。
具有 VPC 設定條件金鑰的範例政策
下列範例示範如何使用條件金鑰進行 VPC 設定。建立具有所需限制的政策陳述式,然後將政策陳述式連接至目標使用者或角色。
要求使用者僅部署 VPC 連線的執行時間和工具
若要要求所有使用者僅部署 VPC 連線的 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" } } }
強制使用者僅使用特定的子網路和安全群組
若要強制使用者僅使用特定核准的子網路和安全群組,請使用ForAnyValue集合運算子搭配 StringNotEquals 。如果請求中的任一內容索引鍵值不符合政策中的內容索引鍵值,則條件會傳回 true,拒絕包含任何未核准值的請求。下列範例強制使用者只能將 subnet-0123456789abcdef0和 subnet-0123456789abcdef1用於子網路,以及將 sg-0123456789abcdef0和 sg-0123456789abcdef1 用於安全群組。
[ { "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"] } } } ]
拒絕使用者存取特定子網路或安全群組
若要拒絕使用者存取特定子網路和安全群組,請使用ForAnyValue集合運算子搭配 StringEquals 。如果請求中的任何一個內容索引鍵值符合政策中的任何一個內容索引鍵值,則條件會傳回 true。下列範例會拒絕使用者存取子網路subnet-0123456789abcdef1的 subnet-0123456789abcdef0和 ,以及拒絕安全群組sg-0123456789abcdef1的 sg-0123456789abcdef0 和 。
[ { "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"] } } } ]