

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 授予 Amazon OpenSearch Ingestion 管道访问集合的权限
<a name="pipeline-collection-access"></a>

Amazon OpenSearch Ingestion 管道可以写入 OpenSearch 无服务器公共集合或 VPC 集合。要提供对集合的访问权限，您需要为一个 AWS Identity and Access Management (IAM) 管道角色配置权限策略，以授予对集合的访问权限。管道扮演此角色是为了签署对 OpenSearch Serverless 集合接收器的请求。

**重要**  
您可以选择手动创建管道角色，也可以让 OpenSearch Ingestion 在创建管道期间为您创建该角色。如果您选择自动创建角色， OpenSearch Ingestion 会根据您选择的来源和接收器将所有必需的权限添加到管道角色访问策略中。OpenSearch Ingestion 会使用您输入的前缀 `OpenSearchIngestion-` 和后缀，在 IAM 中创建管道角色。有关更多信息，请参阅 [管道角色](pipeline-security-overview.md#pipeline-security-sink)。  
如果您让 OpenSearch Ingestion 为您创建管道角色，则在创建管道之前或之后，您仍然需要将该角色包含在集合的数据访问策略中。有关说明，请参阅步骤 2。

在创建管道期间， OpenSearch Ingestion 会在管道和 OpenSearch Serverless 集合之间创建 AWS PrivateLink 连接。来自管道的所有流量都将通过此 VPC 端点并路由到集合。要连接到集合，必须通过网络访问策略向端点授予访问该集合的权限。

![\[OpenSearch Ingestion pipeline connecting to OpenSearch Serverless collection via PrivateLink VPC endpoint.\]](http://docs.aws.amazon.com/zh_cn/opensearch-service/latest/developerguide/images/osis-aoss-permissions.png)


**Topics**
+ [步骤 1：创建管道角色](#pipeline-collection-access-configure)
+ [步骤 2：为集合配置数据和网络访问权限](#pipeline-access-collection)

## 步骤 1：创建管道角色
<a name="pipeline-collection-access-configure"></a>

管道角色必须具有允许其向集合接收器发送数据的附加权限策略。它还必须具有允许 OpenSearch Ingestion担任该角色的信任关系。有关如何附加角色策略的说明，请参阅 *IAM 用户指南*中的[添加 IAM 身份权限](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html#add-policies-console)。

以下示例策略演示您可以在管道角色访问策略中设置的[最低权限](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege)，使其能够向集合写入数据：

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "Statement1",
            "Effect": "Allow",
            "Action": [
                "aoss:APIAccessAll",
                "aoss:BatchGetCollection",
                "aoss:CreateSecurityPolicy",
                "aoss:GetSecurityPolicy",
                "aoss:UpdateSecurityPolicy"
            ],
            "Resource": "*"
        }
    ]
}
```

------

该角色必须具有以下[信任关系](https://docs.aws.amazon.com/IAM/latest/UserGuide/roles-managingrole-editing-console.html#roles-managingrole_edit-trust-policy)，这允许 OpenSearch Ingestion 担任该角色：

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "osis-pipelines.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}
```

------

## 步骤 2：为集合配置数据和网络访问权限
<a name="pipeline-access-collection"></a>

使用以下设置创建 OpenSearch 无服务器集合。有关创建集合的说明，请参阅[创建集合](serverless-create.md)。

### 数据访问策略
<a name="pipeline-data-access"></a>

为集合创建一个向管道角色授予所需权限的[数据访问策略](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-data-access.html)。例如：

```
[
  {
    "Rules": [
      {
        "Resource": [
          "index/collection-name/*"
        ],
        "Permission": [
          "aoss:CreateIndex",
          "aoss:UpdateIndex",
          "aoss:DescribeIndex",
          "aoss:WriteDocument"
        ],
        "ResourceType": "index"
      }
    ],
    "Principal": [
      "arn:aws:iam::account-id:role/pipeline-role"
    ],
    "Description": "Pipeline role access"
  }
]
```

**注意**  
在 `Principal` 元素中，指定管道角色的 Amazon 资源名称（ARN）。

### 网络访问策略
<a name="pipeline-network-access"></a>

您在 OpenSearch Serverless 中创建的每个集合都至少有一个与之关联的网络访问策略。网络访问策略决定了是否可以通过互联网从公共网络访问该集合，还是必须以私有方式访问该集合。更多有关网络策略的信息，请参阅[Amazon OpenSearch Serverless 的网络访问](serverless-network.md)。

在网络访问策略中，您只能指定 OpenSearch 无服务器托管的 VPC 终端节点。有关更多信息，请参阅 [通过以下方式访问数据平面 AWS PrivateLink](serverless-vpc.md)。但是，为了使管道能够写入集合，该策略还必须授予对 OpenSearch Ingestion 在管道和集合之间自动创建的 VPC 终端节点的访问权限。因此，如果您选择 OpenSearch Serverless 集合作为管道的目标接收器，则必须在 “网络策略名称” 字段中输入关联的**网络策略的名称**。

在创建管道期间， OpenSearch Ingestion 会检查指定的网络策略是否存在。如果它不存在，则 OpenSearch Ingestion 会创建它。如果确实存在， OpenSearch Ingestion 会通过向其添加新规则来对其进行更新。添加的规则会授予对连接管道和集合的 VPC 端点的访问权限。

例如：

```
{
   "Rules":[
      {
         "Resource":[
            "collection/my-collection"
         ],
         "ResourceType":"collection"
      }
   ],
   "SourceVPCEs":[
      "vpce-0c510712627e27269" # The ID of the VPC endpoint that OpenSearch Ingestion creates between the pipeline and collection
   ],
   "Description":"Created by Data Prepper"
}
```

在控制台中， OpenSearch Ingestion 添加到您的网络策略中的所有规则都命名为 Create b **y Data Prepper**：

![\[Configuration details for OpenSearch endpoint access, including VPC endpoint and resources.\]](http://docs.aws.amazon.com/zh_cn/opensearch-service/latest/developerguide/images/osis-aoss-network.png)


**注意**  
通常，为集合指定公有访问权限的规则将会覆盖指定私有访问权限的规则。因此，如果策略已经配置了*公共*访问权限，那么 OpenSearch Ingestion 添加的这条新规则实际上并不会改变策略的行为。有关更多信息，请参阅 [策略优先顺序](serverless-network.md#serverless-network-precedence)。

如果您停止或删除管道， OpenSearch Ingestion 会删除管道和集合之间的 VPC 终端节点。此外还会修改网络策略，将 VPC 端点从允许的端点列表中移除。如果您重启管道，则会重新创建 VPC 端点，并使用端点 ID 重新更新网络策略。