

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

# 部署公有子網路的預防性屬性型存取控制
<a name="deploy-preventative-attribute-based-access-controls-for-public-subnets"></a>

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

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

在集中式網路架構中，檢查和邊緣虛擬私有雲端 (VPCs) 會集中所有傳入和傳出流量，例如往返網際網路的流量。不過，這可能會產生瓶頸，或導致達到 AWS 服務配額的限制。與更常見、集中的方法相比，在其 VPCs中的工作負載中部署網路邊緣安全性提供了前所未有的可擴展性。這稱為*分散式邊緣*架構。

雖然在工作負載帳戶中部署公有子網路可以帶來好處，但它也會帶來新的安全風險，因為它會增加攻擊面。我們建議您僅在這些 VPCs 的公有子網路中部署 Elastic Load Balancing (ELB) 資源，例如 Application Load Balancer 或 NAT 閘道。在專用公有子網路中使用負載平衡器和 NAT 閘道，可協助您針對傳入和傳出流量實作精細的控制。

*屬性型存取控制* (ABAC) 是根據使用者屬性建立精細許可的做法，例如部門、任務角色和團隊名稱。如需詳細資訊，請參閱 [ABAC for AWS](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，以協助保護公有子網路的安全。 AWS Organizations 您可以將 SCP 套用到組織的成員帳戶或組織單位 (OU)。這些 ABAC 政策允許使用者在目標子網路中部署 NAT 閘道，並防止他們部署其他 Amazon Elastic Compute Cloud (Amazon EC2) 資源，例如 EC2 執行個體和彈性網路介面。  

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

**先決條件**
+ AWS Organizations 中的組織
+ 對 AWS Organizations 根帳戶的管理存取權
+ 在組織中，用於測試 SCP 的作用中成員帳戶或 OU

**限制**
+ 此解決方案中的 SCP 不會阻止使用服務連結角色的 AWS 服務在目標子網路中部署資源。這些服務的範例包括 Elastic Load Balancing (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)。實作安全控制以偵測這些例外狀況。

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

**目標技術堆疊**
+ 套用至 AWS Organizations 中 AWS 帳戶或 OU 的 SCP
+ 下列 IAM 角色：
  + `AutomationAdminRole` – 用於修改子網路標籤，並在實作 SCP 後建立 VPC 資源
  + `TestAdminRole` – 用來測試 SCP 是否阻止其他 IAM 主體執行為 預留的動作，包括具有管理存取權的主體 `AutomationAdminRole`

**目標架構**

![這些標籤可防止使用者在公有子網路中部署 NAT 閘道以外的資源](http://docs.aws.amazon.com/zh_tw/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 套用到目標 AWS 帳戶或 OU。如需範例政策，請參閱此模式中[的其他資訊](#deploy-preventative-attribute-based-access-controls-for-public-subnets-additional)。

1. CI/CD 管道中的使用者或工具可以擔任`AutomationAdminRole`角色，將`SubnetType`標籤套用至目標子網路。

1. 透過擔任其他 IAM 角色，組織中的授權 IAM 主體可以管理目標子網路中的 NAT 閘道，以及 AWS 帳戶中其他允許的聯網資源，例如路由表。使用 IAM 政策授予這些許可。如需詳細資訊，請參閱 [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 閘道是授權使用者可以在具有 `SubnetType:IFA`標籤的子網路中建立的唯一 Amazon EC2 資源類型。(`IFA` *表示面向網際網路的資產*。) SCP 可防止建立其他 Amazon EC2 資源，例如執行個體和彈性網路介面。我們建議您使用擔任該`AutomationAdminRole`角色的 CI/CD 管道來建立 VPC 資源，以便將這些標籤正確套用至公有子網路。

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

**AWS 服務**
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html) 是一種帳戶管理服務，可協助您將多個 AWS 帳戶合併到您建立並集中管理的組織。在 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>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立測試管理員角色。 | 在目標 AWS 帳戶中建立名為 `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_tw/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_tw/prescriptive-guidance/latest/patterns/deploy-preventative-attribute-based-access-controls-for-public-subnets.html) | AWS 管理員 | 

### 測試 SCP
<a name="test-the-scp"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 VPC 或子網路。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/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_tw/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_tw/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_tw/prescriptive-guidance/latest/patterns/deploy-preventative-attribute-based-access-controls-for-public-subnets.html) | AWS 管理員 | 

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


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 清除已部署的資源。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/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)
+ [什麼是 ABAC for AWS？](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 部落格文章）

## 其他資訊
<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"]
        }
      }
    }
  ]
}
```