

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

# 使用 IAM 控制对回收站的访问
<a name="recycle-bin-perms"></a>

默认情况下，用户没有权限使用回收站、保留规则或回收站中的资源。要允许用户使用这些资源，您必须创建 IAM policy，以授予使用特定资源和 API 操作的权限。创建策略后，必须向您的用户、组或角色添加权限。

**Topics**
+ [

## 使用回收站和保留规则的权限
](#rule-perms)
+ [

## 使用回收站中的资源的权限
](#resource-perms)
+ [

## 回收站的条件键
](#rbin-condition-keys)

## 使用回收站和保留规则的权限
<a name="rule-perms"></a>

要使用回收站和保留规则，用户需要以下权限。
+ `rbin:CreateRule`
+ `rbin:UpdateRule`
+ `rbin:GetRule`
+ `rbin:ListRules`
+ `rbin:DeleteRule`
+ `rbin:TagResource`
+ `rbin:UntagResource`
+ `rbin:ListTagsForResource`
+ `rbin:LockRule`
+ `rbin:UnlockRule`

要使用回收站控制台，用户需要 `tag:GetResources` 权限。

以下是包含控制台用户 `tag:GetResources` 权限的示例 IAM policy。如果不需要某些上述权限，您可以从策略中将其删除。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "rbin:CreateRule",
                "rbin:UpdateRule",
                "rbin:GetRule",
                "rbin:ListRules",
                "rbin:DeleteRule",
                "rbin:TagResource",
                "rbin:UntagResource",
                "rbin:ListTagsForResource",
                "rbin:LockRule",
                "rbin:UnlockRule",
                "tag:GetResources"
            ],
            "Resource": "*"
        }
    ]
}
```

------

要提供访问权限，请为您的用户、组或角色添加权限：
+ 中的用户和群组 AWS IAM Identity Center：

  创建权限集合。按照《AWS IAM Identity Center 用户指南》**中[创建权限集](https://docs.aws.amazon.com//singlesignon/latest/userguide/howtocreatepermissionset.html)的说明进行操作。
+ 通过身份提供者在 IAM 中托管的用户：

  创建适用于身份联合验证的角色。按照《IAM 用户指南》**中[针对第三方身份提供者创建角色（联合身份验证）](https://docs.aws.amazon.com//IAM/latest/UserGuide/id_roles_create_for-idp.html)的说明进行操作。
+ IAM 用户：
  + 创建您的用户可以担任的角色。按照《IAM 用户指南》**中[为 IAM 用户创建角色](https://docs.aws.amazon.com//IAM/latest/UserGuide/id_roles_create_for-user.html)的说明进行操作。
  + （不推荐使用）将策略直接附加到用户或将用户添加到用户组。按照《IAM 用户指南》**中[向用户添加权限（控制台）](https://docs.aws.amazon.com//IAM/latest/UserGuide/id_users_change-permissions.html#users_change_permissions-add-console)中的说明进行操作。

## 使用回收站中的资源的权限
<a name="resource-perms"></a>

有关使用回收站中的资源所需的 IAM 权限的更多信息，请参阅以下内容：
+ [处理回收站中卷的权限](recycle-bin-working-with-volumes.md#volume-perms)
+ [使用回收站中的快照的权限](recycle-bin-working-with-snaps.md#snap-perms)
+ [在回收站 AMIs 中使用的权限](recycle-bin-working-with-amis.md#ami-perms)

## 回收站的条件键
<a name="rbin-condition-keys"></a>

回收站定义以下条件键，您可在 IAM policy 的 `Condition` 元素中将其用于控制适用策略语句的条件。有关更多信息，请参阅《IAM 用户指南》中的 [IAM JSON 策略元素：条件](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html)。

**Topics**
+ [

### `rbin:Request/ResourceType` 条件键
](#resource-type-parameter)
+ [

### `rbin:Attribute/ResourceType` 条件键
](#resource-type-attribute)

### `rbin:Request/ResourceType` 条件键
<a name="resource-type-parameter"></a>

`rbin:Request/ResourceType`条件键可用于根据为[ListRules](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_ListRules.html)请求参数指定的值筛选访问权限[CreateRule](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_CreateRule.html)和`ResourceType`请求。

**示例 1- CreateRule**  
以下示例 IAM 策略允许 IAM 委托人仅在为`ResourceType`请求参数指定的值为`EBS_SNAPSHOT`或`EC2_IMAGE`时发出请求。**CreateRule**这允许委托人 AMIs 仅为快照创建新的保留规则。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement" : [
        {
            "Effect" : "Allow",
            "Action" :[
                "rbin:CreateRule"
            ],
            "Resource" : "*",
            "Condition" : {
                "StringEquals" : {
                    "rbin:Request/ResourceType" : ["EBS_SNAPSHOT", "EC2_IMAGE"]
                }
            }
        }
    ]
}
```

------

**示例 2- ListRules**  
以下示例 IAM 策略允许 IAM 委托人仅在为`ResourceType`请求参数指定的值为时发出请求。**ListRules**`EBS_SNAPSHOT`这使主体仅列出快照的保留规则，并防止它们列出任何其他资源类型的保留规则。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement" : [
        {
            "Effect" : "Allow",
            "Action" :[
                "rbin:ListRules"
            ],
            "Resource" : "*",
            "Condition" : {
                "StringEquals" : {
                    "rbin:Request/ResourceType" : "EBS_SNAPSHOT"
                }
            }
        }
    ]
}
```

------

### `rbin:Attribute/ResourceType` 条件键
<a name="resource-type-attribute"></a>

`rbin:Attribute/ResourceType`条件键可用于根据保留规则`ResourceType`属性的值筛选对[DeleteRule[GetRule[UpdateRule[LockRule[UnlockRule[TagResource](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_TagResource.html)](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_UnlockRule.html)](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_LockRule.html)](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_UpdateRule.html)](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_GetRule.html)](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_DeleteRule.html)、[UntagResource](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_UntagResource.html)、、、、、和[ListTagsForResource](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_ListTagsForResource.html)请求的访问权限。

**示例 1- UpdateRule**  
以下示例 IAM 策略仅在**UpdateRule**请求的保留规则的`ResourceType`属性为`EBS_SNAPSHOT`或`EC2_IMAGE`时允许 IAM 委托人发出请求。这允许委托人 AMIs 仅更新快照的保留规则。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement" : [
        {
            "Effect" : "Allow",
            "Action" :[
                "rbin:UpdateRule"
            ],
            "Resource" : "*",
            "Condition" : {
                "StringEquals" : {
                    "rbin:Attribute/ResourceType" : ["EBS_SNAPSHOT", "EC2_IMAGE"]
                }
            }
        }
    ]
}
```

------

**示例 2- DeleteRule**  
以下示例 IAM 策略允许 IAM 委托人仅在**DeleteRule**请求的保留规则的`ResourceType`属性为`EBS_SNAPSHOT`时发出请求。这使主体能够仅为快照删除保留规则。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement" : [
        {
            "Effect" : "Allow",
            "Action" :[
                "rbin:DeleteRule"
            ],
            "Resource" : "*",
            "Condition" : {
                "StringEquals" : {
                    "rbin:Attribute/ResourceType" : "EBS_SNAPSHOT"
                }
            }
        }
    ]
}
```

------