

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 為知識庫設定安全組態
<a name="kb-create-security"></a>

建立知識庫之後，您可能需要設定下列安全組態：

**Topics**
+ [為您的知識庫設定資料存取政策](#kb-create-security-data)
+ [為您的 Amazon OpenSearch Serverless 知識庫設定網路存取政策](#kb-create-security-network)

## 為您的知識庫設定資料存取政策
<a name="kb-create-security-data"></a>

如果您使用[自訂角色](kb-permissions.md)，請為新建立的知識庫設定安全組態。如果您讓 Amazon Bedrock 為您建立服務角色，則可以略過此步驟。依照您設定之資料庫對應索引標籤中的步驟進行。

------
#### [ Amazon OpenSearch Serverless ]

若要將 Amazon OpenSearch Serverless 集合的存取權限制為知識庫服務角色，請建立資料存取政策。您可採用以下方式：
+ 請遵循《Amazon OpenSearch Service 開發人員指南》中的[建立資料存取政策 (主控台)](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-data-access.html#serverless-data-access-console) 中的步驟，使用 Amazon OpenSearch Service 主控台。
+ 透過使用 [OpenSearch Serverless 端點](https://docs.aws.amazon.com/general/latest/gr/opensearch-service.html#opensearch-service-regions)傳送 [CreateAccessPolicy](https://docs.aws.amazon.com/opensearch-service/latest/ServerlessAPIReference/API_CreateAccessPolicy.html) 請求來使用 AWSAPI。如需AWS CLI範例，請參閱[建立資料存取政策 (AWS CLI)](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-data-access.html#serverless-data-access-cli)。

使用以下資料存取政策，指定 Amazon OpenSearch Serverless 集合和服務角色：

```
[
    {
        "Description": "${data access policy description}",
        "Rules": [
          {
            "Resource": [
              "index/${collection_name}/*"
            ],
            "Permission": [
                "aoss:DescribeIndex",
                "aoss:ReadDocument",
                "aoss:WriteDocument"
            ],
            "ResourceType": "index"
          }
        ],
        "Principal": [
            "arn:aws:iam::${account-id}:role/${kb-service-role}"
        ]
    }
]
```

------
#### [ Pinecone, Redis Enterprise Cloud or MongoDB Atlas ]

若要整合 Pinecone、Redis Enterprise Cloud、MongoDB Atlas 向量索引，請將下列身分型政策連接至您的知識庫服務角色，以允許它存取向量索引的AWS Secrets Manager秘密。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [{
        "Effect": "Allow",
        "Action": [
            "bedrock:AssociateThirdPartyKnowledgeBase"
        ],
        "Resource": "*",
        "Condition": {
            "StringEquals": {
                "bedrock:ThirdPartyKnowledgeBaseCredentialsSecretArn": "arn:aws:secretsmanager:us-east-1:123456789012:secret:${secret-id}"
            }
        }
    }]
}
```

------

------

## 為您的 Amazon OpenSearch Serverless 知識庫設定網路存取政策
<a name="kb-create-security-network"></a>

如果您針對知識庫使用私有 Amazon OpenSearch Serverless 集合，則只能透過 AWS PrivateLinkVPC 端點存取。您可以在[設定 Amazon OpenSearch Serverless 向量集合](knowledge-base-setup.md)時建立私有 Amazon OpenSearch Serverless 集合，也可以在設定其網路存取政策時，將現有的 Amazon OpenSearch Serverless 集合 (包括 Amazon Bedrock 主控台為您建立的集合) 設為私有。

《Amazon OpenSearch Service 開發人員指南》中的下列資源將協助您了解私有 Amazon OpenSearch Serverless 集合所需的設定：
+ 如需為私有 Amazon OpenSearch Serverless 集合設定 VPC 端點的詳細資訊，請參閱[使用介面端點存取 Amazon OpenSearch Serverless (AWS PrivateLink)](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-vpc.html)。
+ 如需 Amazon OpenSearch Serverless 中網路存取政策的詳細資訊，請參閱 [Amazon OpenSearch Serverless 的網路存取](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-network.html)。

若要允許 Amazon Bedrock 知識庫存取私有 Amazon OpenSearch Serverless 集合，您必須編輯 Amazon OpenSearch Serverless 集合的網路存取政策，以允許 Amazon Bedrock 做為來源服務。選擇您偏好方法的索引標籤，然後遵循下列步驟：

------
#### [ Console ]

1. 開啟位於 https：//[https://console.aws.amazon.com/aos/](https://console.aws.amazon.com/aos/) 的 Amazon OpenSearch Service 主控台。

1. 從左側導覽窗格選取**集合**。然後選擇您的集合。

1. 在**網路**區段中，選取**關聯政策**。

1. 選擇**編輯**。

1. 對於**選取政策定義方法**，執行下列其中一項：
   + 將**選取政策定義方法**保留為**視覺化編輯器**，並在**規則 1** 區段中設定下列設定：

     1. (選用) 在**規則名稱**欄位中，輸入網路存取規則的名稱。

     1. 在**存取集合來源**下，選取**私有 (建議)**。

     1. 選取 **AWS 服務私有存取**。在文字方塊中輸入 **bedrock.amazonaws.com**。

     1. 取消選取**啟用對 OpenSearch Dashboards 的存取。**
   + 選擇 **JSON**，然後將下列政策貼到 **JSON 編輯器**中。

     ```
     [
         {                                        
             "AllowFromPublic": false,
             "Description":"${network access policy description}",
             "Rules":[
                 {
                     "ResourceType": "collection",
                     "Resource":[
                         "collection/${collection-id}"
                     ]
                 }
             ],
             "SourceServices":[
                 "bedrock.amazonaws.com"
             ]
         }
     ]
     ```

1. 選擇**更新**。

------
#### [ API ]

若要編輯 Amazon OpenSearch Serverless 集合的網路存取政策，請執行下列動作：

1. 使用 [OpenSearch Serverless 端點](https://docs.aws.amazon.com/general/latest/gr/opensearch-service.html#opensearch-service-regions)傳送 [GetSecurityPolicy](https://docs.aws.amazon.com/opensearch-service/latest/ServerlessAPIReference/API_GetSecurityPolicy.html) 請求。指定政策的 `name`，並將 `type` 指定為 `network`。記下回應中的 `policyVersion`。

1. 使用 [OpenSearch Serverless 端點](https://docs.aws.amazon.com/general/latest/gr/opensearch-service.html#opensearch-service-regions)傳送 [UpdateSecurityPolicy](https://docs.aws.amazon.com/opensearch-service/latest/ServerlessAPIReference/API_UpdateSecurityPolicy.html) 請求。至少指定下列欄位：  
****    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/bedrock/latest/userguide/kb-create-security.html)

   ```
   [
       {                                        
           "AllowFromPublic": false,
           "Description":"${network access policy description}",
           "Rules":[
               {
                   "ResourceType": "collection",
                   "Resource":[
                       "collection/${collection-id}"
                   ]
               }
           ],
           "SourceServices":[
               "bedrock.amazonaws.com"
           ]
       }
   ]
   ```

如需AWS CLI範例，請參閱[建立資料存取政策 (AWS CLI)](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-data-access.html#serverless-data-access-cli)。

------
+ 遵循[建立網路政策 (主控台)](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-network.html#serverless-network-console) 中的步驟，使用 Amazon OpenSearch Service 主控台。請不要建立網路政策，而是在集合詳細資訊的**網路**子區段中記下**關聯的政策**。