為 Amazon Bedrock 知識庫建立服務角色
若要使用知識庫的自訂角色,而不是 Amazon Bedrock 自動建立的角色,請按照建立角色以委派許可給 AWS 服務中的步驟建立 IAM 角色,並連接以下許可。僅包含您自己的安全所需的許可。
-
信任關係
-
Amazon Bedrock 基本模型的存取
-
存取您用來存放資料的資料來源
-
(如果您在 Amazon OpenSearch Service 中建立向量資料庫) 存取您的 OpenSearch Service 集合
-
(如果您在 Amazon Aurora 中建立向量資料庫) 存取您的 Aurora 叢集
-
(如果您在 Pinecone 或 Redis Enterprise Cloud 中建立向量資料庫) 讓 AWS Secrets Manager 驗證您的 Pinecone 或 Redis Enterprise Cloud 帳戶的許可
-
(選用) 如果您使用 KMS 金鑰加密下列任何資源,則需要解密金鑰的權限 (請參閱 知識庫資源的加密)。
信任關係
下列政策允許 Amazon Bedrock 擔任此角色,並建立和管理知識庫。以下顯示您可使用的範例政策。您可以使用一或多個全域條件內容索引鍵來限制權限範圍。如需詳細資訊,請參閱 AWS 全域條件內容索引鍵。將 aws:SourceAccount 值設定為您的帳戶 ID。使用 ArnEquals 或 ArnLike 條件將範圍限制為特定的知識庫。
作為安全目的的最佳實務,請在建立特定知識庫 ID 之後,將 * 取代為特定知識庫 ID。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "bedrock.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "123456789012"
},
"ArnLike": {
"AWS:SourceArn": "arn:aws:bedrock:us-east-1:123456789012:knowledge-base/*"
}
}
}
]
}
存取 Amazon Bedrock 模型的權限
連接以下政策,為角色提供使用 Amazon Bedrock 模型以嵌入來源資料的許可。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:ListFoundationModels",
"bedrock:ListCustomModels"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel"
],
"Resource": [
"arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v1",
"arn:aws:bedrock:us-east-1::foundation-model/cohere.embed-english-v3",
"arn:aws:bedrock:us-east-1::foundation-model/cohere.embed-multilingual-v3"
]
}
]
}
存取您的資料來源的許可
從下列資料來源中選取,以連接角色的必要許可。
存取您的 Amazon S3 資料來源的許可
如果您的資料來源是 Amazon S3,請連接下列政策,為角色提供存取您將連線作為資料來源之 S3 儲存貯體的許可。
如果您使用 AWS KMS 金鑰加密資料來源,請依照 可在 Amazon S3 中為資料來源將 AWS KMS 金鑰解密的許可權 的步驟連接許可,以解密角色的金鑰。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Sid": "S3ListBucketStatement",
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::amzn-s3-demo-bucket"
],
"Condition": {
"StringEquals": {
"aws:ResourceAccount": "123456789012"
}
}
},
{
"Sid": "S3GetObjectStatement",
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::amzn-s3-demo-bucket/*"
],
"Condition": {
"StringEquals": {
"aws:ResourceAccount": "123456789012"
}
}
}
]
}
存取 Confluence 資料來源的許可
Confluence 資料來源連接器目前為預覽版本,並可能會有所變更。
連接下列政策,以提供讓角色存取 Confluence 的許可。
secretsmanager:PutSecretValue 只有在您使用 OAuth 2.0 身分驗證搭配重新整理字符時才需要。
Confluence OAuth2.0 存取字符的預設到期時間為 60 分鐘。如果此字符在資料來源同步 (同步任務) 時過期,Amazon Bedrock 將使用提供的重新整理字符來重新產生此字符。此重新產生會同時重新整理存取和重新整理字符。為了讓字符從目前同步任務更新到下一個同步任務,Amazon Bedrock 需要金鑰憑證的寫入/放置許可。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue",
"secretsmanager:PutSecretValue"
],
"Resource": [
"arn:aws:secretsmanager:us-east-1:123456789012:secret:SecretId"
]
},
{
"Effect": "Allow",
"Action": [
"kms:Decrypt"
],
"Resource": [
"arn:aws:kms:us-east-1:123456789012:key/KeyId"
],
"Condition": {
"StringLike": {
"kms:ViaService": [
"secretsmanager.us-east-1.amazonaws.com"
]
}
}
}
]
}
存取 Microsoft SharePoint 資料來源的許可
SharePoint 資料來源連接器目前為預覽版本,並可能會有所變更。
連接下列政策,以提供讓角色存取 SharePoint 的許可。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue"
],
"Resource": [
"arn:aws:secretsmanager:us-east-1:123456789012:secret:SecretId"
]
},
{
"Effect": "Allow",
"Action": [
"kms:Decrypt"
],
"Resource": [
"arn:aws:kms:us-east-1:123456789012:key/KeyId"
],
"Condition": {
"StringLike": {
"kms:ViaService": [
"secretsmanager.us-east-1.amazonaws.com"
]
}
}
}
]
}
存取 Salesforce 資料來源的許可
Salesforce 資料來源連接器目前為預覽版本,並可能會有所變更。
連接下列政策,以提供讓角色存取 Salesforce 的許可。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue"
],
"Resource": [
"arn:aws:secretsmanager:us-east-1:123456789012:secret:SecretId"
]
},
{
"Effect": "Allow",
"Action": [
"kms:Decrypt"
],
"Resource": [
"arn:aws:kms:us-east-1:123456789012:key/KeyId"
],
"Condition": {
"StringLike": {
"kms:ViaService": [
"secretsmanager.us-east-1.amazonaws.com"
]
}
}
}
]
}
與您的文件聊天的許可
連接以下政策,為角色提供使用 Amazon Bedrock 模型以與文件聊天的許可。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:RetrieveAndGenerate"
],
"Resource": "*"
}
]
}
如果您只想授予使用者與您文件聊天的存取權 (而不是所有知識庫上的 RetrieveAndGenerate),請使用下列政策:
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:RetrieveAndGenerate"
],
"Resource": "*"
},
{
"Effect": "Deny",
"Action": [
"bedrock:Retrieve"
],
"Resource": "*"
}
]
}
如果您想要與文件聊天並在特定知識庫上使用 RetrieveAndGenerate,請提供 ${KnowledgeBaseArn},並使用下列政策:
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:RetrieveAndGenerate"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"bedrock:Retrieve"
],
"Resource": "arn:aws:bedrock:us-east-1:123456789012:knowledge-base/$KnowledgeBaseId"
}
]
}
存取 Amazon Kendra GenAI 指數的許可
如果您為您的知識庫建立 Amazon Kendra GenAI 指數,請將下列政策連接至您的 Amazon Bedrock 知識庫服務角色,以允許存取指數。在政策中,將 ${Partition}、${Region}、${AccountId} 和 ${IndexId} 取代為您指數的值。將指數新增至 Resource 清單,即可允許存取多個指數。若要允許存取 AWS 帳戶 中的每個指數,請以萬用字元 (*) 取代 ${IndexId}。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kendra:Retrieve",
"kendra:DescribeIndex"
],
"Resource": "arn:aws:kendra:us-east-1:123456789012:index/${IndexId}"
}
]
}
在 Amazon OpenSearch Serverless 中存取向量資料庫的許可
如果您在 OpenSearch Serverless 中為您的知識庫建立向量資料庫,請將下列政策連接至您的 Amazon Bedrock 知識庫服務角色,以允許存取集合。將 ${Region} 和 ${AccountId} 取代為資料庫所屬的區域和帳戶 ID。在 ${CollectionId} 中輸入您的 Amazon OpenSearch Service 集合的 ID。將集合新增至 Resource 清單,即可允許存取多個集合。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"aoss:APIAccessAll"
],
"Resource": [
"arn:aws:aoss:us-east-1:123456789012:collection/${CollectionId}"
]
}
]
}
在 OpenSearch 受管叢集中存取向量資料庫的許可
如果您在 OpenSearch 受管叢集中為您的知識庫建立向量資料庫,請將下列政策連接至您的 Amazon Bedrock 知識庫服務角色,以允許存取網域。將 <region> 和 <accountId> 取代為資料庫所屬的區域和帳戶 ID。將網域新增至 Resource 清單,即可允許存取多個網域。如需有關設定許可的詳細資訊,請參閱 搭配 Amazon Bedrock 知識庫使用 OpenSearch 受管叢集所需的先決條件和許可。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"es:ESHttpGet",
"es:ESHttpPost",
"es:ESHttpPut",
"es:ESHttpDelete"
],
"Resource": [
"arn:aws:es:us-east-1:123456789012:domain/domainName/indexName"
]
},
{
"Effect": "Allow",
"Action": [
"es:DescribeDomain"
],
"Resource": [
"arn:aws:es:us-east-1:123456789012:domain/domainName"
]
}
]
}
存取您的 Amazon Aurora 資料庫叢集所需的權限
Amazon Aurora 叢集必須與為 Amazon Bedrock 建立知識庫位於相同的 AWS 帳戶 中。
如果您在 Amazon Aurora 中為知識庫建立了資料庫 (DB) 叢集,請將以下政策連接至 Amazon Bedrock 知識庫服務角色,以允許存取資料庫叢集,並提供讀取和寫入許可。將 ${Region} 和 ${AccountId} 取代為資料庫叢集所屬的區域和帳戶 ID。在 ${DbClusterId} 中輸入 Amazon Aurora 資料庫叢集的 ID。將資料庫叢集新增至 Resource 清單,即可允許存取多個資料庫叢集。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Sid": "RdsDescribeStatementID",
"Effect": "Allow",
"Action": [
"rds:DescribeDBClusters"
],
"Resource": [
"arn:aws:rds:us-east-1:123456789012:cluster:${DbClusterId}"
]
},
{
"Sid": "DataAPIStatementID",
"Effect": "Allow",
"Action": [
"rds-data:BatchExecuteStatement",
"rds-data:ExecuteStatement"
],
"Resource": [
"arn:aws:rds:us-east-1:123456789012:cluster:${DbClusterId}"
]
}
]
}
在 Amazon Neptune Analytics 中存取向量資料庫的許可
如果您為您的知識庫建立 Amazon Neptune Analytics 圖形,請將下列政策連接至您的 Amazon Bedrock 知識庫服務角色,以允許存取圖形。在政策中,將 ${Region} 和 ${AccountId} 取代為資料庫所屬的區域和帳戶 ID。將 ${GraphId} 取代為圖形資料庫的值。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Sid": "NeptuneAnalyticsAccess",
"Effect": "Allow",
"Action": [
"neptune-graph:GetGraph",
"neptune-graph:ReadDataViaQuery",
"neptune-graph:WriteDataViaQuery",
"neptune-graph:DeleteDataViaQuery"
],
"Resource": [
"arn:aws:neptune-graph:us-east-1:123456789012:graph/${GraphId}"
]
}
]
}
在 Amazon S3 Vectors 中存取向量存放區的許可
如果您選擇為您的知識庫使用 Amazon S3 Vectors,請將下列政策連接至您的 Amazon Bedrock 知識庫服務角色,以允許存取向量索引。
Amazon S3 Vectors 與 Amazon Bedrock 知識庫的整合目前為預覽版本,並可能會有所變更。
在政策中,將 ${Region} 和 ${AccountId} 取代為向量索引所屬的區域和帳戶 ID。以 S3 向量儲存貯體的名稱取代 ${BucketName},並以向量索引的名稱取代 ${IndexName}。如需 Amazon S3 Vectors 的詳細資訊,請參閱設定以使用 Amazon S3 Vectors。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Sid": "S3VectorBucketReadAndWritePermission",
"Effect": "Allow",
"Action": [
"s3vectors:PutVectors",
"s3vectors:GetVectors",
"s3vectors:DeleteVectors",
"s3vectors:QueryVectors",
"s3vectors:GetIndex"
],
"Resource": "arn:aws:s3vectors:us-east-1:123456789012:bucket/${BucketName}/index/${IndexName}"
}
]
}
存取使用 AWS Secrets Manager 秘密設定之向量資料庫所需的權限
如果您以 AWS Secrets Manager 秘密設定您的向量資料庫,請將以下政策連接至您的 Amazon Bedrock 知識庫服務角色,以允許 AWS Secrets Manager 驗證您的帳戶存取資料庫的身分資格。將 ${Region} 和 ${AccountId} 取代為資料庫所屬的區域和帳戶 ID。將 ${SecretId} 取代為您秘密的 ID。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue"
],
"Resource": [
"arn:aws:secretsmanager:us-east-1:123456789012:secret:${SecretId}"
]
}
]
}
如果您使用 AWS KMS 金鑰加密您的私密,請依照 針對向量存放區將 AWS Secrets Manager 秘密解密的許可權涵蓋您的知識庫 的步驟連接許可以將角色的金鑰解密。
AWS 在資料擷取期間管理暫時性資料儲存 AWS KMS 金鑰的許可
若要允許在擷取資料來源的過程中建立暫時性資料儲存的 AWS KMS 金鑰,請將以下政策連接到 Amazon Bedrock 知識庫服務角色。以適當的值取代 ${Region}、${AccountId} 和 ${KeyId}。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kms:GenerateDataKey",
"kms:Decrypt"
],
"Resource": [
"arn:aws:kms:us-east-1:123456789012:key/${KeyId}"
]
}
]
}
AWS 管理來自其他使用者的 AWS 帳戶之資料來源的許可。
若要允許存取另一個使用者的 AWS 帳戶,您必須建立角色,允許對另一個使用者帳戶中 Amazon S3 儲存貯體的跨帳戶存取權。以適當的值取代 ${BucketName}、${BucketOwnerAccountId} 和 ${BucketNameAndPrefix}。
知識庫角色所需的許可
在知識庫建立 createKnowledgeBase 期間提供的知識庫角色,需要下列 Amazon S3 許可。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Sid": "S3ListBucketStatement",
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::amzn-s3-demo-bucket"
],
"Condition": {
"StringEquals": {
"aws:ResourceAccount": "123456789012"
}
}
},
{
"Sid": "S3GetObjectStatement",
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::amzn-s3-demo-bucket/*"
],
"Condition": {
"StringEquals": {
"aws:ResourceAccount": "123456789012"
}
}
}
]
}
如果 Amazon S3 儲存貯體使用 AWS KMS 金鑰加密,則還需要將下列項目新增至知識庫角色。以適當的值取代 ${BucketOwnerAccountId} 和 ${Region}。
{
"Sid": "KmsDecryptStatement",
"Effect": "Allow",
"Action": [
"kms:Decrypt"
],
"Resource": [
"arn:aws:kms:${Region}:${BucketOwnerAccountId}:key/${KeyId}"
],
"Condition": {
"StringEquals": {
"kms:ViaService": [
"s3.${Region}.amazonaws.com"
]
}
}
}
跨帳戶 Amazon S3 儲存貯體政策所需的許可
其他帳戶中的儲存貯體需要下列 Amazon S3 儲存貯體政策。以適當的值取代 ${KbRoleArn}、${BucketName} 和 ${BucketNameAndPrefix}。
- JSON
-
-
{
"Version":"2012-10-17",
"Statement": [
{
"Sid": "ListBucket",
"Effect": "Allow",
"Principal": {
"AWS": "123456789012"
},
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::amzn-s3-demo-bucket"
]
},
{
"Sid": "GetObject",
"Effect": "Allow",
"Principal": {
"AWS": "123456789012"
},
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::amzn-s3-demo-bucket/*"
]
}
]
}
跨帳戶 AWS KMS 金鑰政策所需的許可
如果跨帳戶 Amazon S3 儲存貯體使用該帳戶中的 AWS KMS 金鑰加密,則 AWS KMS 金鑰的政策需要下列政策。以適當的值取代 ${KbRoleArn} 和 ${KmsKeyArn}。
{
"Sid": "Example policy",
"Effect": "Allow",
"Principal": {
"AWS": [
"${KbRoleArn}"
]
},
"Action": [
"kms:Decrypt"
],
"Resource": "${KmsKeyArn}"
}