取得組織政策的相關資訊 - AWS Organizations

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

取得組織政策的相關資訊

本主題說明各種取得組織中政策詳細資訊的方法。這些程序適用於所有政策類型。您必須在組織根上啟用政策類型,才能將該類型的政策連接至該組織根中的任何實體。

列出所有政策

最低許可

若要列出您的組織內的政策,您必須擁有以下許可:

  • organizations:ListPolicies

您可以在 中或使用 AWS Command Line Interface (AWS CLI) 命令 AWS Management Console 或 AWS SDK 操作來檢視組織中的政策。

列出組織中的所有政策
  1. 登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。

  2. Policies (政策) 頁面上,選擇您要列出的政策類型。

    如果已啟用指定的政策類型,主控台會顯示組織中目前可用的所有該類型政策的清單。

  3. 返回 Policies (政策) 頁面,然後針對每個政策類型重複執行此操作。

下列程式碼範例示範如何使用 ListPolicies

.NET
AWS SDK for .NET
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

using System; using System.Threading.Tasks; using Amazon.Organizations; using Amazon.Organizations.Model; /// <summary> /// Shows how to list the AWS Organizations policies associated with an /// organization. /// </summary> public class ListPolicies { /// <summary> /// Initializes an Organizations client object, and then calls its /// ListPoliciesAsync method. /// </summary> public static async Task Main() { // Create the client object using the default account. IAmazonOrganizations client = new AmazonOrganizationsClient(); // The value for the Filter parameter is required and must must be // one of the following: // AISERVICES_OPT_OUT_POLICY // BACKUP_POLICY // SERVICE_CONTROL_POLICY // TAG_POLICY var request = new ListPoliciesRequest { Filter = "SERVICE_CONTROL_POLICY", MaxResults = 5, }; var response = new ListPoliciesResponse(); try { do { response = await client.ListPoliciesAsync(request); response.Policies.ForEach(p => DisplayPolicies(p)); if (response.NextToken is not null) { request.NextToken = response.NextToken; } } while (response.NextToken is not null); } catch (AWSOrganizationsNotInUseException ex) { Console.WriteLine(ex.Message); } } /// <summary> /// Displays information about the Organizations policies associated /// with an organization. /// </summary> /// <param name="policy">An Organizations policy summary to display /// information on the console.</param> private static void DisplayPolicies(PolicySummary policy) { string policyInfo = $"{policy.Id} {policy.Name}\t{policy.Description}"; Console.WriteLine(policyInfo); } }
  • 如需 API 詳細資訊,請參閱 AWS SDK for .NET API Reference 中的 ListPolicies

CLI
AWS CLI

擷取特定類型組織中所有政策的清單

下列範例示範如何取得篩選條件參數所指定的 SCPs 清單:

aws organizations list-policies --filter SERVICE_CONTROL_POLICY

輸出包含具有摘要資訊的政策清單:

{ "Policies": [ { "Type": "SERVICE_CONTROL_POLICY", "Name": "AllowAllS3Actions", "AwsManaged": false, "Id": "p-examplepolicyid111", "Arn": "arn:aws:organizations::111111111111:policy/service_control_policy/p-examplepolicyid111", "Description": "Enables account admins to delegate permissions for any S3 actions to users and roles in their accounts." }, { "Type": "SERVICE_CONTROL_POLICY", "Name": "AllowAllEC2Actions", "AwsManaged": false, "Id": "p-examplepolicyid222", "Arn": "arn:aws:organizations::111111111111:policy/service_control_policy/p-examplepolicyid222", "Description": "Enables account admins to delegate permissions for any EC2 actions to users and roles in their accounts." }, { "AwsManaged": true, "Description": "Allows access to every operation", "Type": "SERVICE_CONTROL_POLICY", "Id": "p-FullAWSAccess", "Arn": "arn:aws:organizations::aws:policy/service_control_policy/p-FullAWSAccess", "Name": "FullAWSAccess" } ] }
  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 ListPolicies

Python
SDK for Python (Boto3)
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

def list_policies(policy_filter, orgs_client): """ Lists the policies for the account, limited to the specified filter. :param policy_filter: The kind of policies to return. :param orgs_client: The Boto3 Organizations client. :return: The list of policies found. """ try: response = orgs_client.list_policies(Filter=policy_filter) policies = response["Policies"] logger.info("Found %s %s policies.", len(policies), policy_filter) except ClientError: logger.exception("Couldn't get %s policies.", policy_filter) raise else: return policies
  • 如需 API 詳細資訊,請參閱 AWS SDK for Python (Boto3) API Reference 中的 ListPolicies

列出連接到根、OU 或帳戶的政策

最低許可

若要列出連接到您組織內的根、組織單位 (OU) 或帳戶的政策,您必須擁有以下許可:

  • organizations:ListPoliciesForTarget,並在包含指定目標 (或 "*") 的 Amazon 資源名稱 (ARN) 的相同政策陳述式中具有 Resource 元素

AWS Management Console
列出直接連接到指定的根、OU 或帳戶的所有政策
  1. 登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。

  2. AWS 帳戶 頁面上,選擇您要檢視其政策的根、OU 或帳戶的名稱。您可能需要展開 OU (選擇 Gray cloud icon representing cloud computing or storage services. ),以尋找您想要的 OU。

  3. 在根、OU 或帳戶頁面上,選擇 Policies (政策) 索引標籤。

    Policies (政策) 索引標籤會顯示連接至該根、OU 或帳戶的所有政策,並依政策類型分組。

AWS CLI & AWS SDKs
列出直接連接到指定的根、OU 或帳戶的所有政策

您可以使用下列其中一項命令來列出連接到實體的政策:

  • AWS CLI: list-policies-for-target

    下列範例會列出連接至指定 OU 的所有服務控制政策。您必須同時指定根、OU 或帳戶的 ID,以及您想要列出的政策類型。

    $ aws organizations list-policies-for-target \ --target-id ou-a1b2-f6g7h222 \ --filter SERVICE_CONTROL_POLICY { "Policies": [ { "Id": "p-FullAWSAccess", "Arn": "arn:aws:organizations::aws:policy/service_control_policy/p-FullAWSAccess", "Name": "FullAWSAccess", "Description": "Allows access to every operation", "Type": "SERVICE_CONTROL_POLICY", "AwsManaged": true } ] }
  • AWS SDKs:ListPoliciesForTarget

列出政策連接的所有根帳戶、OU 和帳戶

最低許可

若要列出政策連接的實體,您必須擁有以下許可:

  • organizations:ListTargetsForPolicy,並在包含指定政策 (或 "*") 的 ARN 的相同政策陳述式中具有 Resource 元素

AWS Management Console
列出已連接指定政策的所有根、OU 和帳戶
  1. 登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。

  2. 政策頁面上,選擇政策類型,然後選擇您要檢查其附件的政策名稱。

  3. 選擇 Targets (目標)索引標籤,以顯示所選政策連接的每個根、OU 和帳戶的資料表。

AWS CLI & AWS SDKs
列出已連接指定政策的所有根、OU 和帳戶

您可以使用下列其中一項命令來列出擁有政策的實體:

  • AWS CLI: list-targets-for-policy

    下列範例顯示指定政策的根、OU 和帳戶的所有連接。

    $ aws organizations list-targets-for-policy \ --policy-id p-FullAWSAccess { "Targets": [ { "TargetId": "ou-a1b2-f6g7h111", "Arn": "arn:aws:organizations::123456789012:ou/o-aa111bb222/ou-a1b2-f6g7h111", "Name": "testou2", "Type": "ORGANIZATIONAL_UNIT" }, { "TargetId": "ou-a1b2-f6g7h222", "Arn": "arn:aws:organizations::123456789012:ou/o-aa111bb222/ou-a1b2-f6g7h222", "Name": "testou1", "Type": "ORGANIZATIONAL_UNIT" }, { "TargetId": "123456789012", "Arn": "arn:aws:organizations::123456789012:account/o-aa111bb222/123456789012", "Name": "My Management Account (bisdavid)", "Type": "ACCOUNT" }, { "TargetId": "r-a1b2", "Arn": "arn:aws:organizations::123456789012:root/o-aa111bb222/r-a1b2", "Name": "Root", "Type": "ROOT" } ] }
  • AWS SDKs:ListTargetsForPolicy

取得關於政策的詳細資訊

最低許可

若要顯示政策的詳細資訊,您必須擁有以下許可:

  • organizations:DescribePolicy,並在包含指定政策 (或 "*") 的 ARN 的相同政策陳述式中具有 Resource 元素

取得關於政策的詳細資訊
  1. 登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。

  2. Policies (政策) 頁面上,選擇您要檢查的政策類型,然後選擇政策名稱。

    政策頁面顯示關於政策的可用資訊,包括其 ARN、描述和連接的目標。

    • Content (內容) 索引標籤會以 JSON 格式顯示政策的目前內容。

    • Targets (目標) 索引標籤會顯示政策連接的根、OU 和帳戶的清單。

    • Tags (標籤) 索引標籤會顯示附加至政策的標籤。注意:Tags (標籤) 索引標籤不適用於 AWS 受管政策。

    若要編輯政策,請選擇 Edit policy (編輯政策)。由於每個政策類型都有不同的編輯需求,因此,請參閱建立和更新指定政策類型之政策的指示。

下列程式碼範例示範如何使用 DescribePolicy

CLI
AWS CLI

取得政策的相關資訊

下列範例示範如何請求政策的相關資訊:

aws organizations describe-policy --policy-id p-examplepolicyid111

輸出包含政策物件,其中包含政策的詳細資訊:

{ "Policy": { "Content": "{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Action\": \"*\",\n \"Resource\": \"*\"\n }\n ]\n}", "PolicySummary": { "Arn": "arn:aws:organizations::111111111111:policy/o-exampleorgid/service_control_policy/p-examplepolicyid111", "Type": "SERVICE_CONTROL_POLICY", "Id": "p-examplepolicyid111", "AwsManaged": false, "Name": "AllowAllS3Actions", "Description": "Enables admins to delegate S3 permissions" } } }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribePolicy

Python
SDK for Python (Boto3)
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

def describe_policy(policy_id, orgs_client): """ Describes a policy. :param policy_id: The ID of the policy to describe. :param orgs_client: The Boto3 Organizations client. :return: The description of the policy. """ try: response = orgs_client.describe_policy(PolicyId=policy_id) policy = response["Policy"] logger.info("Got policy %s.", policy_id) except ClientError: logger.exception("Couldn't get policy %s.", policy_id) raise else: return policy
  • 如需 API 詳細資訊,請參閱 SDK AWS for Python (Boto3) API 參考中的 DescribePolicy