

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

# 使用 IAM 控制資源回收筒的存取
<a name="recycle-bin-perms"></a>

依預設，使用者無權使用資源回收筒、保留規則或位於資源回收筒中的資源。若要允許使用者使用這些資源，您必須建立 IAM 政策，其會授予使用特定資源和 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` 許可。

以下為一個範例 IAM 政策，該政策包含主控台使用者的 `tag:GetResources` 許可。若無需某些許可，則您可從政策中將其移除。

------
#### [ 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)
+ [使用資源回收筒中 AMI 的許可](recycle-bin-working-with-amis.md#ami-perms)

## 資源回收筒的條件索引鍵
<a name="rbin-condition-keys"></a>

資源回收筒定義下列條件索引鍵，讓您可以在 IAM 政策的 `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` 條件索引鍵可用於根據為 `ResourceType` 請求參數指定的值，來篩選 [CreateRule](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_CreateRule.html) 和 [ListRules](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_ListRules.html) 請求的存取權。

**範例 1 - CreateRule**  
以下範例 IAM 政策允許 IAM 主體僅在 `ResourceType` 請求參數指定的值為 `EBS_SNAPSHOT` 或 `EC2_IMAGE` 時，才會發出 **CreateRule** 請求。這允許主體僅為快照和 AMI 建立新的保留規則。

------
#### [ 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` 請求參數指定的值為 `EBS_SNAPSHOT` 時，才會發出 **ListRules** 請求。這允許主體僅列出快照的保留規則，並防止其列出任何其他資源類型的保留規則。

------
#### [ 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](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_DeleteRule.html)、[GetRule](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_GetRule.html)、[UpdateRule](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_UpdateRule.html)、[LockRule](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_LockRule.html)、[UnlockRule](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_UnlockRule.html)、[TagResource](https://docs.aws.amazon.com/recyclebin/latest/APIReference/API_TagResource.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 政策允許 IAM 主體僅在請求的保留規則的 `ResourceType` 屬性為 `EBS_SNAPSHOT` 或 `EC2_IMAGE` 時，才會發出 **UpdateRule** 請求。這允許主體僅為快照和 AMI 更新保留規則。

------
#### [ 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 主體僅在請求的保留規則的 `ResourceType` 屬性為 `EBS_SNAPSHOT` 時，才會發出 **DeleteRule** 請求。這允許主體僅為快照刪除保留規則。

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

****  

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

------