

# 管理 IAM 资源的策略示例
<a name="id_credentials_delegate-permissions_examples"></a>

以下 IAM policy 示例允许用户执行与管理 IAM 用户、组和凭证相关的任务。这包括允许用户管理自己的密码、访问密钥和多重验证 (MFA) 设备的策略。

有关允许用户执行对其他 AWS 服务（如 Amazon S3、Amazon EC2 和 DynamoDB）的任务的策略的示例，请参阅 [IAM 基于身份的策略示例](access_policies_examples.md)。

**Topics**
+ [允许用户列出账户的组、用户、策略等，以供报告之用](#iampolicy-example-userlistall)
+ [允许用户管理组的成员资格](#iampolicy-example-usermanagegroups)
+ [允许用户管理 IAM 用户](#creds-policies-users)
+ [允许用户设置账户密码策略](#creds-policies-set-password-policy)
+ [允许用户生成和检索 IAM 凭证报告](#iampolicy-generate-credential-report)
+ [允许所有 IAM 操作（管理员访问）](#creds-policies-all-iam)

## 允许用户列出账户的组、用户、策略等，以供报告之用
<a name="iampolicy-example-userlistall"></a>

以下策略允许用户调用以字符串 `Get` 或 `List` 开头的任何 IAM 操作，并生成报告。要查看示例策略，请参阅[IAM：允许对 IAM 控制台进行只读访问](reference_policies_examples_iam_read-only-console.md)。

## 允许用户管理组的成员资格
<a name="iampolicy-example-usermanagegroups"></a>

以下策略允许用户更新名为 *MarketingGroup* 的组的成员资格。要查看示例策略，请参阅[IAM：允许以编程方式和在控制台中管理组的成员资格](reference_policies_examples_iam_manage-group-membership.md)。

## 允许用户管理 IAM 用户
<a name="creds-policies-users"></a>

以下策略允许用户执行所有与管理 IAM 用户相关的任务，但是不允许对其他实体执行操作，如创建组或策略。允许的操作包括这些：
+ 创建用户（[https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateUser.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateUser.html) 操作）。
+ 删除用户。此任务需要授予执行以下所有操作的权限：[https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteSigningCertificate.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteSigningCertificate.html)、[https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteLoginProfile.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteLoginProfile.html)、[https://docs.aws.amazon.com/IAM/latest/APIReference/API_RemoveUserFromGroup.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_RemoveUserFromGroup.html) 和 [https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteUser.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteUser.html)。
+ 列出账户和组中的用户（[https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetUser.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetUser.html)、[https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListUsers.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListUsers.html) 和 [https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListGroupsForUser.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListGroupsForUser.html) 操作）。
+ 列出和删除用户的策略（[https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListUserPolicies.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListUserPolicies.html)、[https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListAttachedUserPolicies.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListAttachedUserPolicies.html)、[https://docs.aws.amazon.com/IAM/latest/APIReference/API_DetachUserPolicy.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_DetachUserPolicy.html)、[https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteUserPolicy.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteUserPolicy.html) 操作） 
+ 重命名或更改用户的路径（[https://docs.aws.amazon.com/IAM/latest/APIReference/API_UpdateUser.html](https://docs.aws.amazon.com/IAM/latest/APIReference/API_UpdateUser.html) 操作）。`Resource` 元素必须包括涉及源路径和目标路径的 ARN。有关路径的更多信息，请参阅[易记名称和路径](reference_identifiers.md#identifiers-friendly-names)。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AllowUsersToPerformUserActions",
            "Effect": "Allow",
            "Action": [
                "iam:ListPolicies",
                "iam:GetPolicy",
                "iam:UpdateUser",
                "iam:AttachUserPolicy",
                "iam:ListEntitiesForPolicy",
                "iam:DeleteUserPolicy",
                "iam:DeleteUser",
                "iam:ListUserPolicies",
                "iam:CreateUser",
                "iam:RemoveUserFromGroup",
                "iam:AddUserToGroup",
                "iam:GetUserPolicy",
                "iam:ListGroupsForUser",
                "iam:PutUserPolicy",
                "iam:ListAttachedUserPolicies",
                "iam:ListUsers",
                "iam:GetUser",
                "iam:DetachUserPolicy"
            ],
            "Resource": "*"
        },
        {
            "Sid": "AllowUsersToSeeStatsOnIAMConsoleDashboard",
            "Effect": "Allow",
            "Action": [
                "iam:GetAccount*",
                "iam:ListAccount*"
            ],
            "Resource": "*"
        }
    ]
}
```

------

上述策略中包含的很多权限允许用户在 AWS 管理控制台中执行任务。仅从 [AWS CLI](https://aws.amazon.com/cli/)、[AWS SDK](https://aws.amazon.com/tools/) 或 IAM HTTP 查询 API 执行与用户相关的任务的用户可能不需要特定权限。例如，如果用户已知道从用户分离的策略的 ARN，则不需要 `iam:ListAttachedUserPolicies` 权限。用户所需权限的确切列表取决于用户管理其他用户时必须执行的任务。

以下策略中的权限允许通过 AWS 管理控制台访问用户任务：
+ `iam:GetAccount*`
+ `iam:ListAccount*`

## 允许用户设置账户密码策略
<a name="creds-policies-set-password-policy"></a>

您可以授予某些用户获取和更新您的 AWS 账户 的[密码策略](id_credentials_passwords_account-policy.md)的权限。要查看示例策略，请参阅[IAM：允许以编程方式和在控制台中设置账户密码要求](reference_policies_examples_iam_set-account-pass-policy.md)。

## 允许用户生成和检索 IAM 凭证报告
<a name="iampolicy-generate-credential-report"></a>

您可以授予用户生成和下载报告的权限，该报告列出了您 AWS 账户 中的所有用户。该报告还列出了各种用户凭证的状态，包括密码、访问密钥、MFA 设备和签名证书。有关凭证报告的更多信息，请参阅[为您的 AWS 账户 生成凭证报告](id_credentials_getting-report.md)。要查看示例策略，请参阅[IAM：生成和检索 IAM 凭证报告](reference_policies_examples_iam-credential-report.md)。

## 允许所有 IAM 操作（管理员访问）
<a name="creds-policies-all-iam"></a>

您可以授予某些用户在 IAM 中执行所有操作的管理员权限，包括管理密码、访问密钥、MFA 设备和用户凭证。以下示例策略授予这些权限。

**警告**  
当您向用户授予对 IAM 的完全访问权时，对用户可以向自己或他人授予的权限没有限制。用户可以创建新的 IAM 实体（用户或角色）并授予这些实体对您 AWS 账户 中所有资源的完全访问权限。您向用户授予对 IAM 的完全访问权限时，实际上是向用户授予对您 AWS 账户 中所有资源的完全访问权限。其中包括删除所有资源的权限。您应该仅将这些权限授予信任的管理员，还应对这些管理员强制采用多重身份验证 (MFA)。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Effect": "Allow",
    "Action": "iam:*",
    "Resource": "*"
  }
}
```

------