

# 配置 AWS Glue Data Quality的 IAM 权限
<a name="data-quality-authorization"></a>

本主题提供的信息可帮助您了解 IAM 管理员了解可以在 AWS Glue Data Quality 的 AWS Identity and Access Management（IAM）policy中使用的操作和资源。它还包括 IAM policy 示例，其中包含在 AWS Glue Data Catalog 中使用 AWS Glue 数据质量所需的最低权限。

有关 AWS Glue 的其他安全信息，请参阅 [AWS Glue 中的安全性](security.md)。

## AWS Glue 数据质量的 IAM 权限
<a name="data-quality-authorization-permissions"></a>

下表列出了用户执行特定 AWS Glue Data Quality 操作所需的权限。要为 AWS Glue Data Quality 设置精细授权，您可以在 IAM policy 语句的 `Action` 元素中指定这些操作。


**AWS Glue Data Quality 操作**  

| Action | 说明 | 资源类型 | 
| --- | --- | --- | 
| glue:CreateDataQualityRuleset | 授予权限以创建数据质量规则集。 | ::dataQualityRuleset/<name> | 
| glue:DeleteDataQualityRuleset | 授予权限以删除数据质量规则集。 | ::dataQualityRuleset/<name> | 
| glue:GetDataQualityRuleset | 授予权限以检索数据质量规则集。 | ::dataQualityRuleset/<name> | 
| glue:ListDataQualityRulesets | 授予权限以检索所有数据质量规则集。 | ::dataQualityRuleset/\$1 | 
| glue:UpdateDataQualityRuleset | 授予权限以更新数据质量规则集。 | ::dataQualityRuleset/<name> | 
| glue:GetDataQualityResult |  授予权限以检索数据质量任务运行结果。此 IAM 操作提供了以下 API 的权限：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/data-quality-authorization.html)  | ::dataQualityRuleset/<name> | 
| glue:ListDataQualityResults | 授予权限以检索所有数据质量任务运行结果。 | ::dataQualityRuleset/\$1 | 
| glue:CancelDataQualityRuleRecommendationRun | 授予权限以停止正在运行的数据质量建议任务运行。 | ::dataQualityRuleset/\$1 | 
| glue:GetDataQualityRuleRecommendationRun | 授予权限以检索数据质量建议任务运行。 | ::dataQualityRuleset/\$1 | 
| glue:ListDataQualityRuleRecommendationRuns | 授予权限以检索所有数据质量建议任务运行。 | ::dataQualityRuleset/\$1 | 
| glue:StartDataQualityRuleRecommendationRun | 授予权限以开始数据质量规则建议任务运行。 | ::dataQualityRuleset/\$1 | 
| glue:CancelDataQualityRulesetEvaluationRun | 授予权限以停止正在运行的数据质量任务运行。 | ::dataQualityRuleset/\$1 | 
| glue:GetDataQualityRulesetEvaluationRun | 授予权限以检索数据质量任务运行结果。 | ::dataQualityRuleset/\$1 | 
| glue:ListDataQualityRulesetEvaluationRuns | 授予权限以检索所有数据质量任务运行。 | ::dataQualityRuleset/\$1 | 
| glue:StartDataQualityRulesetEvaluationRun | 授予权限以开始数据质量规则任务运行。 | ::dataQualityRuleset/<name> | 
| glue:PublishDataQuality | 授予发布数据质量结果的权限。 | ::dataQualityRuleset/<name> | 
| glue:GetDataQualityModel | 授予检索数据质量模型的权限。 | ::dataQualityRuleset/<name>, ::job/<name>  | 
| glue:GetDataQualityModelResult | 授予检索数据质量模型结果的权限。 | ::dataQualityRuleset/<name>, ::job/<name>  | 
| glue:PutDataQualityStatisticAnnotation |  授予为统计数据添加注释的权限。此 IAM 操作提供了以下 API 的权限：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/data-quality-authorization.html)  | ::dataQualityRuleset/<name>, ::job/<name>  | 
| glue:PutDataQualityProfileAnnotation | 授予在配置文件中为所有统计数据添加注释的权限。 | ::dataQualityRuleset/<name>, ::job/<name>  | 

## 计划评估运行需要 IAM 设置
<a name="data-quality-iam-setup-evaluation-runs"></a>

### IAM 权限
<a name="data-quality-iam-setup-evaluation-runs-permissions"></a>

要运行计划的数据质量评估运行，必须将 `IAM:PassRole` 操作添加到权限策略中。


**AWS EventBridge 调度器所需的权限**  

| Action | 说明 | 资源类型 | 
| --- | --- | --- | 
| iam:PassRole | 向 IAM 授予权限，允许用户传递已批准的角色。 | 用于调用 StartDataQualityRulesetEvaluationRun 的角色的 ARN | 

如果没有这些权限，则会发生以下错误：

```
"errorCode": "AccessDenied"
"errorMessage": "User: arn:aws:sts::account_id:assumed-role/AWSGlueServiceRole is not 
authorized to perform: iam:PassRole on resource: arn:aws:iam::account_id:role/service-role/AWSGlueServiceRole 
because no identity-based policy allows the iam:PassRole action"
```

### IAM 可信实体
<a name="data-quality-iam-setup-evaluation-runs-trusted-entities"></a>

AWS Glue and AWS EventBridge 调度器服务需要在可信实体中列出，才能创建和运行计划的 `StartDataQualityEvaluationRun`。

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

****  

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

------

## 示例 IAM policies
<a name="data-quality-authorization-example-policy"></a>

AWS Glue 数据质量的 IAM 角色需要以下类型的权限：
+ AWS Glue Data Quality 操作权限，以便您获得推荐的数据质量规则，并针对 AWS Glue Data Catalog 中的表运行数据质量任务。本节中的 IAM policy 示例包括 AWS Glue 数据质量操作所需的最低权限。
+ 授予访问 Data Catalog 表和基础数据的权限。这些权限因使用案例而异。例如，对于在 Amazon S3 中编录的数据，权限应包括对 Amazon S3 的访问。
**注意**  
除了本节中描述的权限之外，还必须配置 Amazon S3 权限。

### 获取推荐数据质量规则的最低权限
<a name="example-policy-get-dq-rule-recommendations"></a>

此示例策略包括生成推荐的数据质量规则所需的权限。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "AllowGlueRuleRecommendationRunActions",
      "Effect": "Allow",
      "Action": [
        "glue:GetDataQualityRuleRecommendationRun",
        "glue:PublishDataQuality",
        "glue:CreateDataQualityRuleset"
      ],
      "Resource": "arn:aws:glue:us-east-1:111122223333:dataQualityRuleset/*"
    },
	{
     "Sid": "AllowCatalogPermissions",
     "Effect": "Allow",
     "Action": [
        "glue:GetPartitions",
        "glue:GetTable"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Sid": "AllowS3GetObjectToRunRuleRecommendationTask",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject"
      ],
      "Resource": "arn:aws:s3:::aws-glue-*"
    },
		{
			"Sid": "AllowPublishingCloudwatchLogs",
			"Effect": "Allow",
			"Action": [
			  "logs:CreateLogStream",
			  "logs:CreateLogGroup",
			  "logs:PutLogEvents"
			],
			"Resource": "*"
    }
  ]
}
```

------

### 运行数据质量任务所需的最低权限。
<a name="example-policy-run-dq-task"></a>

此示例策略包括运行数据质量评估任务所需的权限。

根据使用案例可选择以下策略声明：
+ `AllowCloudWatchPutMetricDataToPublishTaskMetrics`：如果要将数据质量运行指标发布到 Amazon CloudWatch，必须选择此项。
+ `AllowS3PutObjectToWriteTaskResults`：如果要将数据质量运行结果写入 Amazon S3，必须选择此项。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "AllowGlueGetDataQualityRuleset",
      "Effect": "Allow",
      "Action": [
        "glue:GetDataQualityRuleset"
      ],
      "Resource": "arn:aws:glue:us-east-1:111122223333:dataQualityRuleset/YOUR-RULESET-NAME"
    },
    {
      "Sid": "AllowGlueRulesetEvaluationRunActions",
      "Effect": "Allow",
      "Action": [
        "glue:GetDataQualityRulesetEvaluationRun",
        "glue:PublishDataQuality"
      ],
      "Resource": "arn:aws:glue:us-east-1:111122223333:dataQualityRuleset/*"
    },
    {
      "Sid": "AllowCatalogPermissions",
      "Effect": "Allow",
      "Action": [
        "glue:GetPartitions",
        "glue:GetTable"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Sid": "AllowS3GetObjectForRulesetEvaluationRun",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject"
      ],
      "Resource": "arn:aws:s3:::aws-glue-*"
    },
    {
      "Sid": "AllowCloudWatchPutMetricDataToPublishTaskMetrics",
      "Effect": "Allow",
      "Action": [
        "cloudwatch:PutMetricData"
      ],
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "cloudwatch:namespace": "Glue Data Quality"
        }
      }
    },
    {
      "Sid": "AllowS3PutObjectToWriteTaskResults",
      "Effect": "Allow",
      "Action": [
        "s3:PutObject*"
      ],
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*"
    }
  ]
}
```

------

### 运行数据质量 ETL 作业所需的最低权限
<a name="example-policy-run-dq-etl-job"></a>

 此示例策略包括运行数据质量 ETL 作业所需的权限。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "AllowGluePublishDataQualityResult",
      "Effect": "Allow",
      "Action": [
        "glue:PublishDataQuality"
      ],
      "Resource": "arn:aws:glue:us-east-1:111122223333:dataQualityRuleset/*"
    },
    {
      "Sid": "AllowGlueGetDataQualityResult",
      "Effect": "Allow",
      "Action": [
        "glue:GetDataQualityResult"
      ],
      "Resource": "arn:aws:glue:us-east-1:111122223333:dataQualityRuleset/*"
    },
    {
      "Sid": "AllowGlueDataQualityStatisticAnnotation",
      "Effect": "Allow",
      "Action": [
        "glue:PutDataQualityStatisticAnnotation"
      ],
      "Resource": [
        "arn:aws:glue:us-east-1:111122223333:dataQualityRuleset/*",
        "arn:aws:glue:us-east-1:111122223333::job/{JobName}"
      ]
    },
    {
      "Sid": "AllowGlueDataQualityProfileAnnotation",
      "Effect": "Allow",
      "Action": [
        "glue:PutDataQualityProfileAnnotation"
      ],
      "Resource": [
        "arn:aws:glue:us-east-1:111122223333:dataQualityRuleset/*",
        "arn:aws:glue:us-east-1:111122223333::job/{JobName}"
      ]
    }
	]
}
```

------