

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

# 为公有子网部署基于属性的预防性访问权限控制
<a name="deploy-preventative-attribute-based-access-controls-for-public-subnets"></a>

*Joel Alfredo Nunez Gonzalez 和 Samuel Ortega Sancho，Amazon Web Services*

## Summary
<a name="deploy-preventative-attribute-based-access-controls-for-public-subnets-summary"></a>

在集中式网络架构中，检查和边缘虚拟私有云 (VPCs) 集中所有入站和出站流量，例如进出互联网的流量。但是，这可能会造成瓶颈或导致达到 AWS 服务限额的限制。与更常见的集中式方法相比，将网络边缘安全与其中的工作负载一起部署可 VPCs 提供前所未有的可扩展性。这称为*分布式边缘*架构。

尽管在工作负载账户中部署公有子网可以带来好处，但它也会带来新的安全风险，因为它增加了攻击面。我们建议您仅在这些资源的公有子网中部署 Elastic Load Balancing (ELB) 资源，例如应用程序负载均衡器或 NAT 网关。 VPCs在专用公有子网中使用负载均衡器和 NAT 网关有助于实现对入站和出站流量的精细控制。

*基于属性的访问权限控制*（ABAC）是根据用户属性（如部门、工作角色和团队名称）创建精细访问权限的做法。有关更多信息，请参阅[适用于 AWS 的 ABAC](https://aws.amazon.com/identity/attribute-based-access-control/)。ABAC 可为工作负载账户中的公共子网提供防护机制。这有助于应用程序团队在不影响基础架构安全性的情况下保持敏捷性。

此模式描述了如何通过 AWS Organizations 中的[服务控制策略（SCP）](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html)和 AWS Identity and Access Management (IAM) 中的[策略](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html)实施 ABAC 来帮助保护公有子网。您可以将 SCP 应用于组织的成员账户或组织单位 (OU)。这些 ABAC 策略允许用户在目标子网中部署 NAT 网关，并防止他们部署其他亚马逊弹性计算云 (Amazon EC2) 资源，例如 EC2 实例和弹性网络接口。  

## 先决条件和限制
<a name="deploy-preventative-attribute-based-access-controls-for-public-subnets-prereqs"></a>

**先决条件**
+ AWS Organizations 中的组织
+ 对 AWS Organizations 根账户的管理访问权限
+ 在组织中，用于测试 SCP 的活动成员账户或 OU

**限制**
+ 此解决方案中的 SCP 不会阻止使用服务相关角色的 Amazon Web Services 在目标子网中部署资源。这些服务的示例包括弹性负载均衡（ELB）、Amazon Elastic Container Service (Amazon ECS) 和 Amazon Relational Database Service (Amazon RDS)。有关更多信息，请参阅 AWS Organizations 文档中的 [SCP 对权限的影响](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html#scp-effects-on-permissions)。实施安全控制来检测这些异常。

## 架构
<a name="deploy-preventative-attribute-based-access-controls-for-public-subnets-architecture"></a>

**目标技术堆栈**
+ SCP 应用于 AWS Organizations 中的 Amazon Web Services account 或 OU
+ 以下 IAM 角色：
  + `AutomationAdminRole` — 用于在实施 SCP 后修改子网标签和创建 VPC 资源
  + `TestAdminRole` — 用于测试 SCP 是否阻止其他 IAM 主体（包括具有管理访问权限的主体）执行为 `AutomationAdminRole` 保留的操作

**目标架构**

![这些标签可防止用户在公有子网中部署 NAT 网关以外的资源](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/25f22f67-5bb6-42ac-8fd6-836e00c436f1/images/b8345c8c-0fc5-46a3-be60-c171979cf979.png)


1. 您可在目标账户中创建 `AutomationAdminRole` IAM 角色。此角色有权管理网络资源。请注意此角色独有的以下权限：
   + 此角色可以创建 VPCs 和公有子网。
   + 此角色可以修改目标子网的标签分配。
   + 此角色可以管理自己的权限。

1. 在 AWS Organizations 中，您可以将 SCP 应用于目标 Amazon Web Services account 或 OU。有关示例策略，请参阅此模式中的[其他信息](#deploy-preventative-attribute-based-access-controls-for-public-subnets-additional)。

1.  CI/CD 管道中的用户或工具可以担任将`SubnetType`标签应用于目标子网的`AutomationAdminRole`角色。

1. 通过承担其他 IAM 角色，组织中的授权 IAM 主体可以管理目标子网中的 NAT 网关以及 Amazon Web Services account 中其他允许的网络资源，例如路由表。使用 IAM policy 以授予这些权限。有关更多信息，请参阅 [Amazon VPC 的身份和访问权限管理](https://docs.aws.amazon.com/vpc/latest/userguide/security-iam.html)。

**自动化和扩缩**

为了帮助保护公有子网，必须应用相应的[ AWS 标签](https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html)。应用 SCP 后，NAT 网关是授权用户可以在带有标签的子网中创建的唯一一种 Amazon EC2 资源。`SubnetType:IFA` （`IFA`指*面向互联网的资产*。） SCP 会阻止创建其他 Amazon EC2 资源，例如实例和弹性网络接口。 我们建议您使用代入`AutomationAdminRole`角色的 CI/CD 管道来创建 VPC 资源，以便将这些标签正确应用于公有子网。

## 工具
<a name="deploy-preventative-attribute-based-access-controls-for-public-subnets-tools"></a>

**Amazon Web Services**
+ [AWS Identity and Access Management (AWS IAM) ](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)通过控制验证和授权使用您 AWS 资源的用户，帮助您安全地管理对您 AWS 资源的访问。
+ [AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html) 是一项账户管理服务，使您可将多个 Amazon Web Services account 整合到您所创建的组织中并进行集中管理。在 AWS Organizations 中，您可以实施[服务控制策略 (SCPs)](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html)，这是一种可用于管理组织内权限的策略。
+ [Amazon Virtual Private Cloud（Amazon VPC）](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html)可帮助您将 AWS 资源启动到您定义的虚拟网络中。此虚拟网络类似于您在自己的数据中心内运行的传统网络，具有使用 AWS 可扩展基础设施的优势。

## 操作说明
<a name="deploy-preventative-attribute-based-access-controls-for-public-subnets-epics"></a>

### 应用 SCP
<a name="apply-the-scp"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建测试管理员角色。 | 在目标 Amazon Web Services account 中，创建一个名为 `TestAdminRole` 的 IAM 角色。将 **AdministratorAccess**AWS 托管 IAM 策略附加到新角色。有关说明，请参阅 IAM 文档中的[创建向 IAM 用户委派权限的角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user.html)。 | AWS 管理员 | 
| 创建自动化管理员角色。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-preventative-attribute-based-access-controls-for-public-subnets.html)以下是您可用于测试 `111122223333` 账户角色的信任策略示例。<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Effect": "Allow",<br />            "Principal": {<br />                "AWS": [<br />                    "arn:aws:iam::111122223333:root"<br />                ]<br />            },<br />            "Action": "sts:AssumeRole",<br />            "Condition": {}<br />        }<br />    ]<br />}</pre> | AWS 管理员 | 
| 创建并附加 SCP。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-preventative-attribute-based-access-controls-for-public-subnets.html) | AWS 管理员 | 

### 测试 SCP
<a name="test-the-scp"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建 VPC 或子网。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-preventative-attribute-based-access-controls-for-public-subnets.html) | AWS 管理员 | 
| 管理标签。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-preventative-attribute-based-access-controls-for-public-subnets.html) | AWS 管理员 | 
| 在目标子网中部署资源。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-preventative-attribute-based-access-controls-for-public-subnets.html) | AWS 管理员 | 
| 管理 AutomationAdminRole 角色。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-preventative-attribute-based-access-controls-for-public-subnets.html) | AWS 管理员 | 

### 清理
<a name="clean-up"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 清理已部署的资源。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-preventative-attribute-based-access-controls-for-public-subnets.html) | AWS 管理员 | 

## 相关资源
<a name="deploy-preventative-attribute-based-access-controls-for-public-subnets-resources"></a>

**AWS 文档**
+ [安装和拆卸 SCPs](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps_attach.html)
+ [创建、更新和删除 SCPs](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps_create.html)
+ [使用 AWS Config 为公有子网部署基于属性的检测性访问权限控制](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config.html)
+ [侦测性控制](https://docs.aws.amazon.com/prescriptive-guidance/latest/aws-security-controls/detective-controls.html)
+ [服务授权参考](https://docs.aws.amazon.com/service-authorization/latest/reference/reference.html)
+ [标记 AWS 资源](https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html)
+ [什么是适用于 AWS 的 ABAC？](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html)

**其他 AWS 参考**
+ [使用 AWS Organizations 中的服务控制策略保护用于授权的资源标签](https://aws.amazon.com/es/blogs/security/securing-resource-tags-used-for-authorization-using-service-control-policy-in-aws-organizations/)（AWS Blog 文章）

## 附加信息
<a name="deploy-preventative-attribute-based-access-controls-for-public-subnets-additional"></a>

以下服务控制策略是一个示例，您可以用来在您的组织中测试这种方法。

```
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "DenyVPCActions",
      "Effect": "Deny",
      "Action": [
        "ec2:CreateVPC",
        "ec2:CreateRoute",
        "ec2:CreateSubnet",
        "ec2:CreateInternetGateway",
        "ec2:DeleteVPC",
        "ec2:DeleteRoute",
        "ec2:DeleteSubnet",
        "ec2:DeleteInternetGateway"
      ],
      "Resource": [
        "arn:aws:ec2:*:*:*"
      ],
      "Condition": {
        "StringNotLike": {
          "aws:PrincipalARN": ["arn:aws:iam::*:role/AutomationAdminRole"]
        }
      }
    },
    {
      "Sid": "AllowNATGWOnIFASubnet",
      "Effect": "Deny",
      "NotAction": [
        "ec2:CreateNatGateway",
        "ec2:DeleteNatGateway"
      ],
      "Resource": [
        "arn:aws:ec2:*:*:subnet/*"
      ],
      "Condition": {
        "ForAnyValue:StringEqualsIfExists": {
          "aws:ResourceTag/SubnetType": "IFA"
        },
        "StringNotLike": {
          "aws:PrincipalARN": ["arn:aws:iam::*:role/AutomationAdminRole"]
        }
      }
    },
    {
      "Sid": "DenyChangesToAdminRole",
      "Effect": "Deny",
      "NotAction": [
        "iam:GetContextKeysForPrincipalPolicy",
        "iam:GetRole",
        "iam:GetRolePolicy",
        "iam:ListAttachedRolePolicies",
        "iam:ListInstanceProfilesForRole",
        "iam:ListRolePolicies",
        "iam:ListRoleTags"
      ],
      "Resource": [
        "arn:aws:iam::*:role/AutomationAdminRole"
      ],
      "Condition": {
        "StringNotLike": {
          "aws:PrincipalARN": ["arn:aws:iam::*:role/AutomationAdminRole"]
        }
      }
    }
  ]
}
```