使用脚本批量迁移策略以使用 IAM 精细操作 - Amazon 账单
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

使用脚本批量迁移策略以使用 IAM 精细操作

注意

以下 Amazon Identity and Access Management (IAM) 操作已结束标准支持:

  • aws-portal 命名空间

  • purchase-orders:ViewPurchaseOrders

  • purchase-orders:ModifyPurchaseOrders

如果您正在使用 Amazon Organizations,则可以使用批量策略迁移程序脚本从您的付款人账户更新政策。您还可以使用旧到精细操作映射参考来验证需要添加的 IAM 操作。

有关更多信息,请参阅Amazon 账单、 Amazon 成本管理和账户控制台权限变更博客。

如果您在 2023 年 11 月 16 日上午 11:00(太平洋夏令时)当天或之后 Amazon Organizations 创建了或参与其中,则细粒度的操作已经在您的组织中生效。 Amazon Web Services 账户

为帮助迁移 IAM policy 以使用新操作(也称为精细操作),您可以使用 Amazon 示例网站上的脚本。

您可以从组织的付款人账户运行这些脚本,以确定您组织中使用旧 IAM 操作的以下受影响策略:

  • 客户管理型 IAM policy

  • 角色、组和用户 IAM 内联策略

  • 服务控制策略(SCP)(仅适用于付款人账户)

  • 权限集

这些脚本将生成与策略中所用现有操作对应的新操作建议。然后,您可以查看建议,并使用脚本为组织中所有受影响的策略添加新操作。您无需更新 Amazon 托管策略或 Amazon 托管 SCP(例如, Amazon Control Tower 和 Amazon Organizations SCP)。

您可以使用这些脚本来:

  • 可简化策略更新,以帮助您管理付款人账户中的受影响策略。

  • 减少更新策略所需的时间。无需登录每个成员账户并手动更新策略。

  • 可将来自不同成员账户的相同政策分为一组。然后,您可以检查并为所有相同的策略应用相同的更新,而不必逐一检查。

  • 确保在 2023 年 7 月 6 日 Amazon 停用旧的 IAM 操作后,用户访问不受影响。

有关策略和服务控制策略(SCP)的更多信息,请参阅以下主题:

概述

按照此主题的说明完成以下步骤:

先决条件

要开始使用,您必须首先完成以下操作:

  • 下载并安装 Python 3

  • 登录您的付款人账户并确认您拥有具有以下 IAM 权限的 IAM 主体:

    "iam:GetAccountAuthorizationDetails", "iam:GetPolicy", "iam:GetPolicyVersion", "iam:GetUserPolicy", "iam:GetGroupPolicy", "iam:GetRole", "iam:GetRolePolicy", "iam:CreatePolicyVersion", "iam:DeletePolicyVersion", "iam:ListAttachedRolePolicies", "iam:ListPolicyVersions", "iam:PutUserPolicy", "iam:PutGroupPolicy", "iam:PutRolePolicy", "iam:SetDefaultPolicyVersion", "organizations:ListAccounts", "organizations:ListPolicies", "organizations:DescribePolicy", "organizations:UpdatePolicy", "organizations:DescribeOrganization", "sso:DescribePermissionSet", "sso:DescribePermissionSetProvisioningStatus", "sso:GetInlinePolicyForPermissionSet", "sso:ListInstances", "sso:ListPermissionSets", "sso:ProvisionPermissionSet", "sso:PutInlinePolicyToPermissionSet", "sts:AssumeRole"
提示

首先,建议您使用账户的子集(例如测试账户)来验证建议的更改是否符合预期。

然后,再次为组织中的剩余账户运行脚本。

第 1 步:设置环境

首先从 Amazon 示例 网站下载所需的文件,然后运行命令来设置环境。

设置 环境
  1. 克隆 Amazon 示例 网站中的存储库。在命令行窗口中,您可以使用以下命令:

    git clone https://github.com/aws-samples/bulk-policy-migrator-scripts-for-account-cost-billing-consoles.git
  2. 导航到下载了文件的目录。您可以使用以下命令:

    cd bulk-policy-migrator-scripts-for-account-cost-billing-consoles

    在存储库中,您可以查找以下脚本和资源:

    • billing_console_policy_migrator_role.json— 在您组织的成员账户中创建 BillingConsolePolicyMigratorRole IAM 角色的 CloudFormation 模板。此角色允许脚本代入该角色,然后读取和更新受影响的策略。

    • action_mapping_config.json— 包含旧操作与新操作的 one-to-many 映射。脚本使用此文件为包含旧操作的每个受影响策略提供新操作建议。

      每个旧操作可对应多个精细操作。文件中建议的新操作允许用户在迁移 Amazon Web Services 之前访问该文件。

    • identify_affected_policies.py – 扫描并识别组织中受影响的策略。此脚本会生成一个 affected_policies_and_suggestions.json 文件,其中将列出受影响的策略以及建议的新操作。

      使用相同旧操作组合的受影响策略将在 JSON 文件中分为一组,以便您可以查看或更新建议的新操作。

    • update_affected_policies.py – 更新组织中受影响的策略。该脚本会输入 affected_policies_and_suggestions.json 文件,然后将建议的新操作添加到策略中。

    • rollback_affected_policies.py –(可选)还原对受影响策略所做的更改。此脚本将从受影响的策略中移除新的精细操作。

  3. 运行以下命令,以设置和激活虚拟环境。

    python3 -m venv venv
    source venv/bin/activate
  4. 运行以下命令来安装 Amazon SDK for Python (Boto3) 依赖关系。

    pip install -r requirements.txt
    注意

    您必须配置您的 Amazon 凭据才能使用 Amazon Command Line Interface (Amazon CLI)。有关更多信息,请参阅 Amazon SDK for Python (Boto3)

有关更多信息,请参阅 README.md 文件。

步骤 2:创建 CloudFormation StackSet

按照以下步骤创建 CloudFormation 堆栈集。然后,此堆栈集将为组织中的所有成员账户创建 BillingConsolePolicyMigratorRole IAM 角色。

注意

您只需从管理账户(付款人账户)完成此步骤一次即可。

要创建 CloudFormation StackSet
  1. 在文本编辑器中,打开 billing_console_policy_migrator_role.json 文件,并将每个 <management_account> 替换为付款人账户的账户 ID(例如,123456789012)。

  2. 保存该文件。

  3. 以付款人 Amazon Web Services Management Console 身份登录账户。

  4. 在 CloudFormation 控制台中,使用您更新的billing_console_policy_migrator_role.json文件创建堆栈集。

    有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的在 Amazon CloudFormation 控制台上创建堆栈集

CloudFormation 创建堆栈集后,您组织中的每个成员账户都有一个 BillingConsolePolicyMigratorRole IAM 角色。

该 IAM 角色包含以下权限:

"iam:GetAccountAuthorizationDetails", "iam:GetPolicy", "iam:GetPolicyVersion", "iam:GetUserPolicy", "iam:GetGroupPolicy", "iam:GetRolePolicy", "iam:CreatePolicyVersion", "iam:DeletePolicyVersion", "iam:ListPolicyVersions", "iam:PutUserPolicy", "iam:PutGroupPolicy", "iam:PutRolePolicy", "iam:SetDefaultPolicyVersion"
注意事项
  • 对于每个成员账户,脚本都会调用 AssumeRoleAPI 操作来获取临时证书以担任 BillingConsolePolicyMigratorRole IAM 角色。

  • 这些脚本调用 ListAccountsAPI 操作来获取所有成员账户。

  • 这些脚本还将调用 IAM API 操作来执行策略的读取和写入权限。

第 3 步:识别受影响的策略

创建堆栈集并下载文件后,运行 identify_affected_policies.py 脚本。此脚本将代入每个成员账户的 BillingConsolePolicyMigratorRole IAM 角色,然后识别受影响的策略。

识别受影响的策略
  1. 导航到下载了脚本的目录。

    cd policy_migration_scripts/scripts
  2. 运行 identify_affected_policies.py 脚本。

您可以使用以下输入参数:

  • Amazon Web Services 账户 你想让脚本扫描。要指定账户,请使用以下输入参数:

    • --all – 扫描组织中的所有成员账户。

      python3 identify_affected_policies.py --all
    • --accounts – 扫描组织中的某个成员账户子集。

      python3 identify_affected_policies.py --accounts 111122223333, 444455556666, 777788889999
    • --exclude-accounts – 排除组织中的特定成员账户。

      python3 identify_affected_policies.py --all --exclude-accounts 111111111111, 222222222222, 333333333333
  • –-action-mapping-config-file –(可选)指定 action_mapping_config.json 文件路径。该脚本将使用此文件,来为受影响的策略生成更新建议。如果未指定路径,则脚本将使用该文件夹中的 action_mapping_config.json 文件。

    python3 identify_affected_policies.py –-action-mapping-config-file c:\Users\username\Desktop\Scripts\action_mapping_config.json –-all
注意

您不能使用此脚本来指定组织部门(OU)。

运行脚本后,脚本会在 Affected_Policies_<Timestamp> 文件夹中创建两个 JSON 文件:

  • affected_policies_and_suggestions.json

  • detailed_affected_policies.json

affected_policies_and_suggestions.json

列出受影响的策略以及建议的新操作。使用相同旧操作组合的受影响策略在文件中分为一组。

此文件包含以下部分:

  • 概括说明您在脚本中指定的账户的元数据,包括:

    • 扫描的账户和 identify_affected_policies.py 脚本的输入参数

    • 受影响账户的数量

    • 受影响策略的数量

    • 相似策略组的数量

  • 相似策略组 – 包括账户列表和策略详细信息,包含以下部分:

    • ImpactedPolicies – 指定受影响并包含在同一组中的策略

    • ImpactedPolicyStatements – 提供有关当前使用受影响策略中旧操作的 Sid 块的信息。这一部分包括旧操作和 IAM 元素,例如 EffectPrincipalNotPrincipalNotActionCondition

  • SuggestedPolicyStatementsToAppend – 提供作为新 SID 块添加的建议新操作。

    更新策略后,系统会将此块会附加到策略结尾处。

例 示例 affected_policies_and_suggestions.json 文件

此文件根据以下标准将相似的策略分为一组:

  • 使用的旧操作相同 – 在所有 SID 块中使用相同旧操作的策略。

  • 详细信息一致 – 除受影响的操作外,这些策略还具有相同的 IAM 元素,例如:

    • Effect (Allow/Deny)

    • Principal(被允许或拒绝访问的主体)

    • NotAction(不允许执行的操作)

    • NotPrincipal(被显式拒绝访问的主体)

    • Resource(该政策适用于哪些 Amazon 资源)

    • Condition(政策适用的任何特定条件)

注意

有关更多信息,请参阅 IAM policy 示例

例 示例 affected_policies_and_suggestions.json
[{ "AccountsScanned": [ "111111111111", "222222222222" ], "TotalAffectedAccounts": 2, "TotalAffectedPolicies": 2, "TotalSimilarPolicyGroups": 2 }, { "GroupName": "Group1", "ImpactedPolicies": [{ "Account": "111111111111", "PolicyType": "UserInlinePolicy", "PolicyName": "Inline-Test-Policy-Allow", "PolicyIdentifier": "1111111_1-user:Inline-Test-Policy-Allow" }, { "Account": "222222222222", "PolicyType": "UserInlinePolicy", "PolicyName": "Inline-Test-Policy-Allow", "PolicyIdentifier": "222222_1-group:Inline-Test-Policy-Allow" } ], "ImpactedPolicyStatements": [ [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:ViewAccounts" ], "Resource": "*" }] ], "SuggestedPolicyStatementsToAppend": [{ "Sid": "BillingConsolePolicyMigrator0", "Effect": "Allow", "Action": [ "account:GetAccountInformation", "account:GetAlternateContact", "account:GetChallengeQuestions", "account:GetContactInformation", "billing:GetContractInformation", "billing:GetIAMAccessPreference", "billing:GetSellerOfRecord", "payments:ListPaymentPreferences" ], "Resource": "*" }] }, { "GroupName": "Group2", "ImpactedPolicies": [{ "Account": "111111111111", "PolicyType": "UserInlinePolicy", "PolicyName": "Inline-Test-Policy-deny", "PolicyIdentifier": "1111111_2-user:Inline-Test-Policy-deny" }, { "Account": "222222222222", "PolicyType": "UserInlinePolicy", "PolicyName": "Inline-Test-Policy-deny", "PolicyIdentifier": "222222_2-group:Inline-Test-Policy-deny" } ], "ImpactedPolicyStatements": [ [{ "Sid": "VisualEditor0", "Effect": "deny", "Action": [ "aws-portal:ModifyAccount" ], "Resource": "*" }] ], "SuggestedPolicyStatementsToAppend": [{ "Sid": "BillingConsolePolicyMigrator1", "Effect": "Deny", "Action": [ "account:CloseAccount", "account:DeleteAlternateContact", "account:PutAlternateContact", "account:PutChallengeQuestions", "account:PutContactInformation", "billing:PutContractInformation", "billing:UpdateIAMAccessPreference", "payments:UpdatePaymentPreferences" ], "Resource": "*" }] } ]
detailed_affected_policies.json

包含 identify_affected_policies.py 脚本为成员账户识别的所有受影响策略的定义。

该文件会将相似的策略分为一组。您可以将此文件作为参考,从而检查和管理策略更改,无需登录每个成员账户以分别检查每个策略和账户的更新。

您可以在文件中搜索策略名称(例如 YourCustomerManagedReadOnlyAccessBillingUser),然后检查受影响策略的定义。

例如:detailed_affected_policies.json
[{ "Account": "111111111111", "PolicyType": "CustomerManagedPolicy", "PolicyName": "AwsPortalviewAccount", "PolicyIdentifier": "arn:aws:iam::111111111111:policy/AwsPortalviewAccount", "PolicyDocument": { "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:ViewAccount" ], "Resource": "*" }] } }, { "Account": "222222222222", "PolicyType": "CustomerManagedPolicy", "PolicyName": "AwsPortalviewAccount", "PolicyIdentifier": "arn:aws:iam::222222222222:policy/AwsPortalviewAccount", "PolicyDocument": { "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:ViewAccount" ], "Resource": "*" }] } }, { "Account": "111111111111", "PolicyType": "CustomerManagedPolicy", "PolicyName": "AwsPortalModifyAccount", "PolicyIdentifier": "arn:aws:iam::111111111111:policy/AwsPortalModifyAccount", "PolicyDocument": { "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Deny", "Action": [ "aws-portal:ModifyAccount" ], "Resource": "*" }] } }, { "Account": "222222222222", "PolicyType": "CustomerManagedPolicy", "PolicyName": "AwsPortalModifyAccount", "PolicyIdentifier": "arn:aws:iam::222222222222:policy/AwsPortalModifyAccount", "PolicyDocument": { "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Deny", "Action": [ "aws-portal:ModifyAccount" ], "Resource": "*" }] } } ]

第 4 步:检查建议的更改

脚本创建 affected_policies_and_suggestions.json 文件后,检查文件并进行任何更改。

检查受影响的政策
  1. 在文本编辑器中,打开 affected_policies_and_suggestions.json文件。

  2. AccountsScanned 部分中,验证从扫描的账户中识别出的相似组数量是否符合预期。

  3. 检查将添加到受影响策略中的建议精细操作。

  4. 根据需要更新文件,然后保存。

示例 1:更新 action_mapping_config.json 文件

您可以在 action_mapping_config.json 中更新建议的映射。更新文件后,您可以重新运行 identify_affected_policies.py 脚本。此脚本将为受影响的策略生成更新后的建议。

您可以为 action_mapping_config.json 文件创建多个版本,以为具有不同权限的不同账户更改策略。例如,您可以创建一个名为 action_mapping_config_testing.json 的文件,来迁移测试账户的权限和生产账户的 action_mapping_config_production.json

示例 2:更新 affected_policies_and_suggestions.json 文件

要更改特定受影响策略组的建议替换方案,可以在 affected_policies_and_suggestions.json 文件中直接编辑建议替换部分。

您在这一部分所做的任何更改,都将应用于该特定受影响策略组中的所有策略。

示例 3:自定义特定的策略

如果您发现受影响策略组中的某个策略需要执行与建议更新不同的更改,则可以执行以下操作:

  • identify_affected_policies.py 脚本中排除特定的账户。然后,您可以单独检查这些被排除的账户。

  • 通过移除需要不同权限的受影响策略和账户,来更新受影响的 Sid 块。创建仅包含特定账户的 JSON 块,或从当前受更新影响的策略运行中将其排除。

    重新运行 identify_affected_policies.py 脚本时,更新后的块中将仅包含相关的账户。然后,您可以完善该特定 Sid 块的替换建议。

第 5 步:更新受影响的策略

检查并完善替换建议后,运行 update_affected_policies.py 脚本。此脚本会将 affected_policies_and_suggestions.json 文件作为输入。此脚本将代入 BillingConsolePolicyMigratorRole IAM 角色,来更新 affected_policies_and_suggestions.json 文件中列出的受影响策略。

更新受影响的策略
  1. 如果还没有,则打开 Amazon CLI的命令行窗口。

  2. 输入以下命令运行 update_affected_policies.py 脚本。您可以输入以下输入参数:

  • 包含要更新的受影响策略列表的 affected_policies_and_suggestions.json 文件的目录路径。此文件是上一步的输出。

python3 update_affected_policies.py --affected-policies-directory Affected_Policies_<Timestamp>

update_affected_policies.py 脚本将使用建议的新操作更新 affected_policies_and_suggestions.json 文件中的受影响策略。此脚本将向策略添加一个 Sid 块,标识为 BillingConsolePolicyMigrator#,其中 # 对应于一个增量计数器(例如,1、2、3)。

例如,假设受影响的策略中有多个使用旧操作的 Sid 块,则脚本会添加多个看起来像 BillingConsolePolicyMigrator#Sid 块,与每个 Sid 块一一对应。

重要
  • 此脚本不会移除策略中的旧 IAM 操作,也不会更改策略中现有的 Sid 块。相反,它会创建 Sid 块并将其附加到策略的结尾处。这些新的 Sid 块包含了 JSON 文件中建议的新操作。这可以确保原始策略的权限不会更改。

  • 我们不建议您更改 BillingConsolePolicyMigrator# Sid 块的名称,以防您需要还原更改。

例 示例:附加了 Sid 块的策略

参见 BillingConsolePolicyMigrator1BillingConsolePolicyMigrator2 块中附加的 Sid 块。

{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": [ "ce:*", "aws-portal:ViewAccount" ], "Resource": "*", "Principal": { "AWS": "arn:aws:iam::111111111111:BillingRole" }, "Condition": { "BoolIfExists": { "aws:MultiFactorAuthPresent": "true" } } }, { "Sid": "BillingConsolePolicyMigrator1", "Effect": "Allow", "Action": [ "account:GetAccountInformation", "account:GetAlternateContact", "account:GetChallengeQuestions", "account:GetContactInformation", "billing:GetContractInformation", "billing:GetIAMAccessPreference", "billing:GetSellerOfRecord", "payments:ListPaymentPreferences" ], "Resource": "*", "Principal": { "AWS": "arn:aws:iam::111111111111:BillingRole" }, "Condition": { "BoolIfExists": { "aws:MultiFactorAuthPresent": "true" } } }, { "Sid": "BillingConsolePolicyMigrator2", "Effect": "Deny", "Action": [ "account:CloseAccount", "account:DeleteAlternateContact", "account:PutAlternateContact", "account:PutChallengeQuestions", "account:PutContactInformation", "billing:PutContractInformation", "billing:UpdateIAMAccessPreference", "payments:UpdatePaymentPreferences" ], "Resource": "*" } ] }

此脚本会生成包含失败操作的状态报告,并在本地输出 JSON 文件。

例 示例:状态报告
[{ "Account": "111111111111", "PolicyType": "Customer Managed Policy" "PolicyName": "AwsPortalViewPaymentMethods", "PolicyIdentifier": "identifier", "Status": "FAILURE", // FAILURE or SKIPPED "ErrorMessage": "Error message details" }]
重要
  • 如果您重新运行 identify_affected_policies.pyupdate_affected_policies.py 脚本,则这些脚本会跳过所有包含 BillingConsolePolicyMigratorRole#Sid 块的策略。这些脚本将假定这些策略之前已经完成扫描和更新,并且不需要额外的更新。这样可以防止脚本在策略中重复相同的操作。

  • 更新受影响的策略后,您可以使用受影响策略工具来使用新的 IAM。如果您发现任何问题,则可以使用该工具切换回之前的操作。您还可以使用脚本来还原策略更新。

    有关更多信息,请参阅如何使用受影响策略工具以及Amazon 账单、成本管理和账户控制台权限变更博客文章。

  • 要管理更新,您可以:

    • 为每个账户分别运行脚本。

    • 为相似账户(例如测试、QA 和生产账户)批量运行脚本。

    • 为所有账户运行脚本。

    • 选择批量更新某些账户,然后单独更新其他账户的组合操作。

第 6 步:还原更改(可选)

rollback_affected_policies.py 脚本将会还原应用于指定账户的每个受影响策略的更改。此脚本会移除 update_affected_policies.py 脚本附加的所有 Sid 块。这些 Sid 块采用 BillingConsolePolicyMigratorRole# 格式。

还原更改
  1. 如果还没有,则打开 Amazon CLI的命令行窗口。

  2. 输入以下命令运行 rollback_affected_policies.py 脚本。您可以输入以下输入参数:

  • --accounts

    • 指定要包含在回滚中的 Amazon Web Services 账户 ID 的逗号分隔列表。

    • 以下示例扫描指定中的策略 Amazon Web Services 账户,并删除带有该BillingConsolePolicyMigrator#Sid块的所有语句。

      python3 rollback_affected_policies.py –-accounts 111122223333, 555555555555, 666666666666
  • --all

    • 包括组织中的所有 Amazon Web Services 账户 ID。

    • 以下示例将扫描您组织中的所有策略,并移除任何包含 BillingConsolePolicyMigratorRole# Sid 块的语句。

    python3 rollback_affected_policies.py –-all
  • --exclude-accounts

    • 指定要从回滚中排除的 Amazon Web Services 账户 ID 的逗号分隔列表。

      仅当您同时指定了 --all 参数时才可以使用此参数。

    • 以下示例扫描组织 Amazon Web Services 账户 中除指定账户之外的所有账户的策略。

      python3 rollback_affected_policies.py --all --exclude-accounts 777777777777, 888888888888, 999999999999

IAM policy 示例

以下内容相同的策略将视为相似策略:

  • 所有 Sid 块中的受影响操作。

  • 以下 IAM 元素中的详细信息:

    • Effect (Allow/Deny)

    • Principal(被允许或拒绝访问的主体)

    • NotAction(不允许执行的操作)

    • NotPrincipal(被显式拒绝访问的主体)

    • Resource(该政策适用于哪些 Amazon 资源)

    • Condition(政策适用的任何特定条件)

以下示例显示了 IAM 可能根据策略之间的差异认为相似或不相似的策略。

例 示例 1:策略被认为相似

每个策略的类型都不同,但两个策略都包含一个具有相同受影响 ActionSid 块。

Policy 1: Group inline IAM policy
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:ViewAccount", "aws-portal:*Billing" ], "Resource": "*" }] }
Policy 2: Customer managed IAM policy
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:ViewAccount", "aws-portal:*Billing" ], "Resource": "*" }] }
例 示例 2:策略被认为相似

两个策略都包含具有相同受影响 ActionSid 块。策略 2 包含其他的操作,但这些操作不受影响。

Policy 1
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:ViewAccount", "aws-portal:*Billing" ], "Resource": "*" }] }
Policy 2
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:ViewAccount", "aws-portal:*Billing", "athena:*" ], "Resource": "*" }] }
例 示例 3:策略被认为不相似

两个策略都包含具有相同受影响 ActionSid 块。但是,策略 2 包含策略 1 中不存在的 Condition 元素。

Policy 1
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:ViewAccount", "aws-portal:*Billing" ], "Resource": "*" }] }
Policy 2
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:ViewAccount", "aws-portal:*Billing", "athena:*" ], "Resource": "*", "Condition": { "BoolIfExists": { "aws:MultiFactorAuthPresent": "true" } } }] }
例 示例 4:策略被认为相似

策略 1 包含单个具有受影响 ActionSid 块。策略 2 包含多个 Sid 块,但受影响的 Action 仅出现在一个块中。

Policy 1
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:View*" ], "Resource": "*" }] }}
Policy 2
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:View*" ], "Resource": "*" }, { "Sid": "VisualEditor1", "Effect": "Allow", "Action": [ "cloudtrail:Get*" ], "Resource": "*" } ] }
例 示例 5:策略被认为不相似

策略 1 包含单个具有受影响 ActionSid 块。策略 2 包含多个 Sid 块,并且受影响的 Action 出现在多个块中。

Policy 1
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:View*" ], "Resource": "*" }] }
Policy 2
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:View*" ], "Resource": "*" }, { "Sid": "VisualEditor1", "Effect": "Deny", "Action": [ "aws-portal:Modify*" ], "Resource": "*" } ] }
例 示例 6:策略被认为相似

两个策略都有多个 Sid 块,每个 Action 块中具有相同的受影响 Sid

Policy 1
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:*Account", "iam:Get*" ], "Resource": "*" }, { "Sid": "VisualEditor1", "Effect": "Deny", "Action": [ "aws-portal:Modify*", "iam:Update*" ], "Resource": "*" } ] }
Policy 2
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:*Account", "athena:Get*" ], "Resource": "*" }, { "Sid": "VisualEditor1", "Effect": "Deny", "Action": [ "aws-portal:Modify*", "athena:Update*" ], "Resource": "*" } ] }
例 示例 7

以下两个策略被认为不相似。

策略 1 包含单个具有受影响 ActionSid 块。策略 2 包含一个具有相同受影响 ActionSid 块。但是,策略 2 还包含另一个具有不同操作的 Sid 块。

Policy 1
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:*Account", "iam:Get*" ], "Resource": "*" }, { "Sid": "VisualEditor1", "Effect": "Deny", "Action": [ "aws-portal:Modify*", "iam:Update*" ], "Resource": "*" } ] }
Policy 2
{ "Version": "2012-10-17", "Statement": [{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "aws-portal:*Account", "athena:Get*" ], "Resource": "*" }, { "Sid": "VisualEditor1", "Effect": "Deny", "Action": [ "aws-portal:*Billing", "athena:Update*" ], "Resource": "*" } ] }