View a markdown version of this page

依工作負載身分縮小對憑證提供者的存取範圍 - Amazon Bedrock AgentCore

依工作負載身分縮小對憑證提供者的存取範圍

您可以使用 IAM 政策來控制哪些工作負載身分可存取特定的登入資料提供者。這可啟用精細存取控制,確保只有授權的代理程式才能擷取特定服務的登入資料。

注意

您指派給客服人員的 IAM 角色會控制客服人員可以呼叫的登入資料提供者。此服務不會在相同帳戶中的工作負載身分和登入資料提供者之間強制執行額外的繫結。若要遵循最低權限實務,請將 IAM 政策Resource區塊範圍限定為特定工作負載身分和憑證提供者 ARNs,而不是使用 *

成功呼叫登入資料提供者並不表示會自動傳回登入資料。工作負載擷取的登入資料在其工作負載存取字符中範圍限定於使用者身分。對於 OAuth2 (3LO) 提供者,最終使用者必須先完成授權,才能為該工作負載身分和使用者組合擷取任何登入資料。

存取控制機制

  • 工作負載身分型限制 – 限制登入資料提供者對特定工作負載身分的存取

  • 資源層級許可 – 使用 ARN 型政策控制對個別憑證提供者的存取

  • 目錄層級控制 – 在工作負載身分目錄層級管理存取權

  • 登入資料提供者範圍 – 透過在政策Resource區塊中包含登入資料提供者 ARNs 來限制工作負載身分可存取的登入資料提供者

IAM 政策範例

下列範例示範如何建立 IAM 政策,根據工作負載身分和憑證提供者來限制憑證提供者存取。

限制對特定 API 金鑰登入資料提供者的存取

此政策允許工作負載身分僅從特定登入資料提供者擷取 API 金鑰。Resource 區塊中的登入資料提供者 ARN 會限制對該提供者的存取。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "GetResourceApiKey", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetResourceApiKey" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default/workload-identity/<workload-identity-name>", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default/api-key/<provider-name>" ] } ] }

限制對特定 OAuth2 憑證提供者的存取

此政策允許工作負載身分僅從特定 OAuth2 憑證提供者擷取 OAuth2 字符。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "GetResourceOauth2Token", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetResourceOauth2Token" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default/workload-identity/<workload-identity-name>", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default/oauth2-credential-provider/<provider-name>" ] } ] }

允許多個工作負載身分存取登入資料提供者

此政策允許多個工作負載身分從相同的登入資料提供者擷取 API 金鑰。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "GetResourceApiKeyMultipleIdentities", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetResourceApiKey" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default/workload-identity/agent-1", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default/workload-identity/agent-2", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default/workload-identity/agent-3", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default/api-key/<provider-name>" ] } ] }

拒絕存取特定登入資料提供者

您可以使用 Deny陳述式明確拒絕工作負載身分存取特定登入資料提供者。拒絕陳述式優先於允許陳述式,這使得它們適用於建立護欄。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "DenyAccessToSensitiveProvider", "Effect": "Deny", "Action": [ "bedrock-agentcore:GetResourceApiKey", "bedrock-agentcore:GetResourceOauth2Token" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default/api-key/<sensitive-provider-name>", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default/oauth2-credential-provider/<sensitive-provider-name>" ] } ] }

針對不同的登入資料提供者使用不同的工作負載身分

如果您需要不同的代理程式存取不同的登入資料提供者,請使用不同的 IAM 角色建立不同的工作負載身分。每個 IAM 角色的範圍僅限於代理程式所需的登入資料提供者。

例如,如果客服人員 A 應僅存取提供者 X,而客服人員 B 應僅存取提供者 Y:

  1. 建立工作負載身分agent-a和工作負載身分 agent-b

  2. AgentARole 使用僅允許存取提供者 X 的政策建立 IAM 角色

  3. AgentBRole 使用僅允許存取提供者 Y 的政策建立 IAM 角色

  4. 將每個工作負載身分與其對應的 IAM 角色建立關聯

代理程式 A 的 IAM 政策 (僅限存取提供者 X)

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AgentAAccessProviderX", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetResourceApiKey" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default/workload-identity/agent-a", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default/api-key/provider-x" ] } ] }

代理程式 B 的 IAM 政策 (僅限存取提供者 Y)

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AgentBAccessProviderY", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetResourceApiKey" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:workload-identity-directory/default/workload-identity/agent-b", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default", "arn:aws:bedrock-agentcore:us-east-1:<account_id>:token-vault/default/api-key/provider-y" ] } ] }

實作步驟

若要實作登入資料提供者的工作負載身分型存取控制:

  1. 識別您的工作負載身分aws bedrock-agentcore-control list-workload-identities用來列出您帳戶中的所有工作負載身分。如需有關建立和管理工作負載身分的資訊,請參閱使用 AgentCore Identity 管理工作負載身分

  2. 判斷登入資料提供者 ARNs – 識別您要控制存取的特定登入資料提供者。登入資料提供者 ARNs遵循下列格式:

    • arn:aws:bedrock-agentcore:<region>:<account_id>:token-vault/default/api-key/<provider-name>

    • arn:aws:bedrock-agentcore:<region>:<account_id>:token-vault/default/oauth2-credential-provider/<provider-name>

  3. 建立 IAM 政策 – 撰寫 IAM 政策,指定哪些工作負載身分可存取哪些登入資料提供者

  4. 將政策連接至角色 – 將政策連接至代理程式或應用程式所使用的 IAM 角色

  5. 測試存取控制 – 確認只有授權的工作負載身分可以存取指定的憑證提供者

最佳實務

  • 使用工作負載身分的描述性名稱,讓政策管理更容易

  • Resource區塊中包含登入資料提供者 ARNs,以限制對特定提供者的存取,而不是授予對帳戶中所有提供者的存取

  • 當不同的客服人員需要存取不同的登入資料提供者時,請使用不同的工作負載身分和 IAM 角色

  • 使用明確Deny陳述式來建立護欄,以防止存取敏感登入資料提供者,無論其他政策為何

  • 定期稽核和檢閱存取政策,以確保它們符合您的安全需求

  • 考慮根據時間、IP 地址或其他因素,使用 IAM 政策條件進行其他存取控制

  • 在開發環境中測試政策,然後再將其套用至生產工作負載