針對 使用身分型政策 (IAM 政策) AWS Directory Service - AWS Directory Service

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

針對 使用身分型政策 (IAM 政策) AWS Directory Service

這個主題提供身分型政策範例,在該政策中帳戶管理員可以將許可政策連接至 IAM 身分 (使用者、群組和角色)。這些範例示範 中的 IAM 政策 AWS Directory Service。您應該修改和建立自己的政策,以符合您的需求和環境。

重要

建議您先檢閱簡介主題,說明可用於管理 AWS Directory Service 資源存取的基本概念和選項。如需詳細資訊,請參閱管理 AWS Directory Service 資源存取許可的概觀

本主題中的各節涵蓋下列內容:

以下顯示許可政策範例。

JSON
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowDsEc2IamGetRole", "Effect": "Allow", "Action": [ "ds:CreateDirectory", "ec2:RevokeSecurityGroupIngress", "ec2:CreateNetworkInterface", "ec2:AuthorizeSecurityGroupEgress", "ec2:AuthorizeSecurityGroupIngress", "ec2:DescribeNetworkInterfaces", "ec2:DescribeVpcs", "ec2:CreateSecurityGroup", "ec2:RevokeSecurityGroupEgress", "ec2:DeleteSecurityGroup", "ec2:DeleteNetworkInterface", "ec2:DescribeSubnets", "iam:GetRole" ], "Resource": "*" }, { "Sid": "WarningAllowsCreatingRolesWithDirSvcPrefix", "Effect": "Allow", "Action": [ "iam:CreateRole", "iam:PutRolePolicy" ], "Resource": "arn:aws:iam::111122223333:role/DirSvc*" }, { "Sid": "AllowPassRole", "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::111122223333:role/Your-Role-Name", "Condition": { "StringEquals": { "iam:PassedToService": "cloudwatch.amazonaws.com" } } } ] }

政策中的三個陳述式會授予許可,如下所示:

  • 第一個陳述式會授予建立 AWS Directory Service 目錄的許可。由於 AWS Directory Service 不支援資源層級的許可,因此政策會指定萬用字元 (*) 做為Resource值。

  • 第二個陳述式授予存取 IAM 動作的許可,讓 AWS Directory Service 可以代表您讀取和建立 IAM 角色。Resource 值結尾的萬用字元 (*) 表示該陳述式允許對任何 IAM 角色執行動作的許可。若要限制此許可只提供給特定角色,請將資源 ARN 中的萬用字元 (*) 更換為特定角色的名稱。如需詳細資訊,請參閱 IAM 動作

  • 第三個陳述式會將許可授予 Amazon EC2 中允許 AWS Directory Service 建立、設定和銷毀其目錄所需的特定資源集。將角色 ARN 取代為您的角色。如需詳細資訊,請參閱 Amazon EC2 動作

您不會在政策中看到Principal元素,因為在身分型政策中,您不會指定取得許可的委託人。當您將該政策連接至使用者時,這名使用者是隱含委託人。當您將許可政策連接至 IAM 角色,該角色的信任政策中所識別的主體即取得許可。

如需顯示所有 AWS Directory Service API 動作及其適用的資源的資料表,請參閱 AWS Directory Service API 許可:動作、資源和條件參考

使用 AWS Directory Service 主控台所需的許可

若要讓使用者使用 AWS Directory Service 主控台,該使用者必須擁有上述政策中列出的許可,或 Directory Service 完整存取角色或 Directory Service 唯讀角色授予的許可,如中所述AWS 的 受管 (預先定義) 政策 AWS Directory Service

如果您建立比最基本必要許可更嚴格的 IAM 政策,則對於採取該 IAM 政策的使用者而言, 主控台就無法如預期運作。

AWS 的 受管 (預先定義) 政策 AWS Directory Service

AWS 提供由 建立和管理的預先定義或受管 IAM 政策,以解決許多常見的使用案例 AWS。受管政策會授予常見使用案例的必要許可,這可協助您決定所需的許可。如需詳細資訊,請參閱AWS 的 受管政策 AWS Directory Service

客戶受管政策範例

在本節中,您可以找到授予各種 AWS Directory Service 動作許可的使用者政策範例。

注意

所有範例皆使用美國西部 (奧勒岡) 區域 (us-west-2) 及虛構帳戶 ID。

範例 1:允許使用者對任何 AWS Directory Service 資源執行任何描述動作

下列許可政策會將許可授予使用者,以執行 AWS Managed Microsoft AD Describe中開頭為 且目錄 ID d-1234567890為 AWS 帳戶 的所有動作111122223333。這些動作會顯示 AWS Directory Service 資源 (如目錄或快照) 的相關資訊。請務必將 AWS 區域 和 帳號變更為您要使用的區域和您的帳號。

JSON
{ "Version":"2012-10-17", "Statement":[ { "Effect":"Allow", "Action":"ds:Describe*", "Resource": "arn:aws:ds:us-west-2:111122223333:directory/d-1234567890" } ] }

範例 2:允許使用者建立目錄

下列許可政策會授予允許使用者建立目錄和所有其他相關資源 (如快照和信任) 的許可。若要授予該許可,還需要特定 Amazon EC2 服務的許可。

JSON
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ec2:AuthorizeSecurityGroupEgress", "ec2:AuthorizeSecurityGroupIngress", "ec2:CreateNetworkInterface", "ec2:CreateSecurityGroup", "ec2:DeleteNetworkInterface", "ec2:DeleteSecurityGroup", "ec2:DescribeNetworkInterfaces", "ec2:DescribeSubnets", "ec2:DescribeVpcs", "ec2:RevokeSecurityGroupEgress", "ec2:RevokeSecurityGroupIngress", "ec2:CreateTags" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "ds:CreateDirectory", "ds:DescribeDirectories" ], "Resource": "arn:aws:ds:*:111122223333:*" } ] }

搭配 IAM 政策使用標籤

您可以在用於大多數 AWS Directory Service API 動作的 IAM 政策中套用標籤型資源層級許可。這可讓您更有效地控制使用者可以建立、修改或使用哪些資源。您可以使用 Condition 元素 (也稱為 Condition 區塊),以及 IAM 政策中的以下條件內容金鑰和值,來根據資源標籤控制使用者存取 (許可):

  • 使用 aws:ResourceTag/tag-key: tag-value 以允許或拒絕資源上具有特定標籤的使用者動作。

  • 使用 aws:ResourceTag/tag-key: tag-value 以在提出 API 請求時,要求使用 (或不使用) 特定標籤,以建立或修改允許標籤的資源。

  • 使用 aws:TagKeys: [tag-key, ...] 以在提出 API 請求時,要求使用 (或不使用) 特定標籤金鑰集,以建立或修改允許標籤的資源。

注意

IAM 政策中的條件內容金鑰和值,只會套用到資源識別符可標記為必要參數的那些 AWS Directory Service 動作。

《IAM 使用者指南》中的使用標籤控制存取有如何使用標籤的其他資訊。該指南的 IAM JSON 政策參考章節有詳細的語法、說明,還有元素、變數範例,以及在 IAM 中的 JSON 政策評估邏輯。

下列標籤政策允許建立 AWS Directory Service 目錄,只要使用下列標籤:

  • 環境:生產

  • 擁有者:基礎設施團隊

  • 成本中心:1234

JSON
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ds:CreateDirectory" ], "Resource": "*", "Condition": { "StringEquals": { "aws:RequestTag/Environment": "Production", "aws:RequestTag/Owner": "Infrastructure-Team", "aws:RequestTag/CostCenter": "12345" } } } ] }

下列標籤政策允許更新和刪除 AWS Directory Service 目錄,只要使用下列標籤:

  • 專案:Atlas

  • 部門:工程

  • 環境:預備

JSON
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ds:DeleteDirectory", "ds:UpdateDirectory" ], "Resource": "*", "Condition": { "StringEquals": { "aws:ResourceTag/Project": "Atlas", "aws:ResourceTag/Department": "Engineering", "aws:ResourceTag/Environment": "Staging" } } } ] }

下列標籤政策拒絕資源具有下列其中一個標籤 AWS Directory Service 的資源標記:

  • 生產

  • 安全

  • 機密

JSON
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Deny", "Action": [ "ds:AddTagsToResource" ], "Resource": "*", "Condition": { "ForAnyValue:StringEquals": { "aws:TagKeys": ["Production", "Security", "Confidential"] } } } ] }

如需 ARNs 的詳細資訊,請參閱 Amazon Resource Name (ARNs AWS 和服務命名空間

下列 AWS Directory Service API 操作清單支援標籤型資源層級許可: