

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# を使用してパブリックサブネットの検出属性ベースのアクセスコントロールをデプロイする AWS Config
<a name="deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config"></a>

*Amazon Web Services、Alberto Menendez*

## 概要
<a name="deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config-summary"></a>

分散型エッジネットワークアーキテクチャは、仮想プライベートクラウド (VPC) 内のワークロードとともに実行されるネットワークエッジセキュリティに依存しています。これにより、より一般的で一元化されたアプローチと比較して、かつてないスケーラビリティが得られます。パブリックサブネットをワークロードアカウントにデプロイすることには利点がありますが、アタックサーフェスが増えるため、新たなセキュリティリスクも生じます。これらの VPC のパブリックサブネットでは、Application Load Balancer や NAT ゲートウェイなどの Elastic Load Balancing (ELB) リソースのみをデプロイすることを推奨します。専用のパブリックサブネットでロードバランサーと NAT ゲートウェイの使用は、インバウンドトラフィックとアウトバウンドトラフィックのきめ細かな制御に役立ちます。

パブリックサブネットにデプロイできるリソースのタイプを制限するために、予防的コントロールと検出的コントロールの両方を実装することを推奨します。属性ベースのアクセス制御 (ABAC) を使用してパブリックサブネットの予防的コントロールをデプロイする方法の詳細については、「[Deploy preventative attribute-based access controls for public subnets](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/deploy-preventative-attribute-based-access-controls-for-public-subnets.html)」を参照してください。ほとんどの状況で有効ですが、これらの予防的コントロールは、考え得るすべてのユースケースに対処できるとは限りません。したがって、このパターンは ABAC アプローチに基づいて構築され、パブリックサブネットにデプロイされている非準拠リソースに関する警告を設定するのに役立ちます。このソリューションは、Elastic Network Interface がパブリックサブネットで許可されていないリソースに属しているかどうかをチェックします。

これを実現するために、このパターンでは [AWS Config カスタムルール](https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules.html)と [ABAC](https://aws.amazon.com/identity/attribute-based-access-control/) を使用します。カスタムルールは、Elastic Network Interface が作成または変更されるたびに、その設定を処理します。大まかに言うと、このルールは 2 つのアクションを実行して、ネットワークインターフェイスが適合しているかどうかを判断します。

1. ネットワークインターフェイスがこのルールの範囲内にあるかどうかを判断するために、ルールは、サブネットにパブリックサブネットであることを示す特定の [AWS タグ](https://docs.aws.amazon.com/tag-editor/latest/userguide/tagging.html)があるかどうかをチェックします。例えば、タグには `IsPublicFacing=True` などがあります。

1. ネットワークインターフェイスがパブリックサブネットにデプロイされている場合、ルールはこのリソースを AWS のサービス 作成した をチェックします。リソースが Elastic Load Balancing リソースまたは NAT ゲートウェイでない場合、リソースは非準拠としてマークされます。

## 前提条件と制限
<a name="deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config-prereqs"></a>

**前提条件**
+ アクティブな AWS アカウント
+ AWS Configが、ワークロードアカウントで[設定済み](https://docs.aws.amazon.com/config/latest/developerguide/gs-console.html)
+ ワークロードアカウントに必要なリソースをデプロイするためのアクセス許可
+ パブリックサブネットのある VPC
+ ターゲットのパブリックサブネットを識別するために適切に適用されるタグ
+ (オプション) の組織 AWS Organizations
+ (オプション) AWS Config と の委任管理者である中央セキュリティアカウント AWS Security Hub CSPM

## アーキテクチャ
<a name="deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config-architecture"></a>

**ターゲットアーキテクチャ**

![\[AWS Config カスタムルールを使用してパブリックサブネット内の非準拠リソースを検出する\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/images/pattern-img/85d54ead-7f00-4381-89fb-cffe307c4cfc/images/a8c19913-d260-4b70-96ba-732bb1b9881f.png)


この図表は、以下を示すものです:

1. Elastic Network Interface リソース (`AWS::EC2::NetworkInterface`) がデプロイまたは変更されると、 はイベントと設定を AWS Config キャプチャします。

1. AWS Config は、このイベントを、設定の評価に使用されるカスタムルールと照合します。

1. このカスタムルールに関連付けられた AWS Lambda 関数が呼び出されます。関数はリソースを評価し、指定されたロジックを適用して、リソース設定が `COMPLIANT`、`NON_COMPLIANT` または `NOT_APPLICABLE` かを判断します。

1. リソースが であると判断された場合`NON_COMPLIANT`、 は Amazon Simple Notification Service (Amazon SNS) を介してアラート AWS Config を送信します。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config.html)

**Lambda 関数の評価ロジック**

次の図は、Elastic Network Interface のコンプライアンスを評価するために Lambda 関数によって適用されるロジックを示しています。

![\[Lambda 関数ロジックの図\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/images/pattern-img/85d54ead-7f00-4381-89fb-cffe307c4cfc/images/9575e20f-142b-4eba-b34d-3b9bda163144.png)


**自動化とスケール**

このパターンは検出的ソリューションです。また、修復ルールで補完して、非準拠のリソースを自動的に解消することもできます。詳細については、[AWS Config 「ルールを使用した非準拠リソースの修復](https://docs.aws.amazon.com/config/latest/developerguide/remediation.html)」を参照してください。

このソリューションは、次の方法でスケールできます。
+ パブリックサブネットを識別するために確立した対応する AWS タグの適用を強制します。詳細については、 AWS Organizations ドキュメントの[「タグポリシー](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html)」を参照してください。
+ 組織内のすべてのワークロードアカウントに AWS Config カスタムルールを適用する中央セキュリティアカウントを設定します。詳細については、[「Automate configuration compliance at scale in AWS](https://aws.amazon.com/blogs/mt/automate-configuration-compliance-at-scale-in-aws/)」(AWS ブログ記事) を参照してください。
+  AWS Config と統合 AWS Security Hub CSPM して、大規模なキャプチャ、一元化、通知を行います。詳細については、 AWS Security Hub CSPM ドキュメントの[「 の設定 AWS Config](https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-prereq-config.html)」を参照してください。

## ツール
<a name="deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config-tools"></a>
+ [AWS Config](https://docs.aws.amazon.com/config/latest/developerguide/WhatIsConfig.html) は、 内のリソースの詳細ビュー AWS アカウント と、その設定方法を提供します。リソースがどのように相互に関連しているか、またそれらの構成が時間の経過とともにどのように変化したかを特定するのに役立ちます。
+ 受信したアプリケーションまたはネットワークトラフィックを複数のターゲットに分散するには、[Elastic Load Balancing](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/what-is-load-balancing.html) を使用します。例えば、1 つまたは複数のアベイラビリティーゾーンの Amazon Elastic Compute Cloud (Amazon EC2) インスタンス、コンテナ、および IP アドレスにトラフィックを分散できます。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) は、サーバーのプロビジョニングや管理を行うことなくコードを実行できるコンピューティングサービスです。必要に応じてコードを実行し、自動的にスケーリングするため、課金は実際に使用したコンピューティング時間に対してのみ発生します。
+ 「[Amazon Simple Notiﬁcation Service (Amazon SNS)](https://docs.aws.amazon.com/sns/latest/dg/welcome.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-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config-best-practices"></a>

カスタム AWS Config ルールを開発するためのその他の例とベストプラクティスについては、GitHub の公式[AWS Config ルールリポジトリ](https://github.com/awslabs/aws-config-rules)を参照してください。

## エピック
<a name="deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config-epics"></a>

### 解決策をデプロイする
<a name="deploy-the-solution"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| Lambda 関数を作成します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config.html) | AWS 全般 | 
| アクセス許可を Lambda 関数の実行ロールに追加する。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config.html) | AWS 全般 | 
| Lambda 関数の Amazon リソースネーム (ARN) を取得する。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config.html) | AWS 全般 | 
|  AWS Config カスタムルールを作成します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config.html) | AWS 全般 | 
| 通知を設定する。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config.html) | AWS 全般 | 

### ソリューションをテストする
<a name="test-the-solution"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| 適合リソースを作成する。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config.html) | AWS 全般 | 
| 非準拠リソースを作成する。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config.html) | AWS 全般 | 
| 適用外リソースを作成する。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config.html) | AWS 全般 | 

## 関連リソース
<a name="deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config-resources"></a>

**AWS ドキュメント**
+ [セットアップ AWS Config](https://docs.aws.amazon.com/config/latest/developerguide/gs-console.html)
+ [AWS Config カスタムルール](https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules.html)
+ [の ABAC AWS](https://aws.amazon.com/identity/attribute-based-access-control/)
+ [Deploy preventative attribute-based access controls for public subnets](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/deploy-preventative-attribute-based-access-controls-for-public-subnets.html)

**その他の AWS リソース**
+ [大規模な設定コンプライアンスの自動化 AWS](https://aws.amazon.com/blogs/mt/automate-configuration-compliance-at-scale-in-aws/)
+ [ゲートウェイロードバランサーを使用した分散型検査アーキテクチャ](https://d1.awsstatic.com/architecture-diagrams/ArchitectureDiagrams/distributed-inspection-architectures-gwlb-ra.pdf)

## 追加情報
<a name="deploy-detective-attribute-based-access-controls-for-public-subnets-by-using-aws-config-additional"></a>

以下は、デモンストレーション目的で提供される Lambda 関数の例です。

```
import boto3
import json
import os

# Init clients
config_client = boto3.client('config')
ec2_client = boto3.client('ec2')

def lambda_handler(event, context):

    # Init values
    compliance_value = 'NOT_APPLICABLE'
    invoking_event = json.loads(event['invokingEvent'])
    configuration_item = invoking_event['configurationItem']
    
    status = configuration_item['configurationItemStatus']
    eventLeftScope = event['eventLeftScope']

    # First check if the event configuration applies. Ex. resource event is not delete
    if (status == 'OK' or status == 'ResourceDiscovered') and not eventLeftScope:
        compliance_value = evaluate_change_notification_compliance(configuration_item)
    
    
    config_client.put_evaluations(
       Evaluations=[
           {
               'ComplianceResourceType': invoking_event['configurationItem']['resourceType'],
               'ComplianceResourceId': invoking_event['configurationItem']['resourceId'],
               'ComplianceType': compliance_value,
               'OrderingTimestamp': invoking_event['configurationItem']['configurationItemCaptureTime']
           },
       ],
       ResultToken=event['resultToken'])
    
# Function with the logs to evaluate the resource
def evaluate_change_notification_compliance(configuration_item):
    is_in_scope = is_in_scope_subnet(configuration_item['configuration']['subnetId'])
    
    if (configuration_item['resourceType'] != 'AWS::EC2::NetworkInterface') or not is_in_scope:
        return 'NOT_APPLICABLE'

    else:
        alb_condition = configuration_item['configuration']['requesterId'] in ['amazon-elb']
        nlb_condition = configuration_item['configuration']['interfaceType'] in ['network_load_balancer']
        nat_gateway_condition = configuration_item['configuration']['interfaceType'] in ['nat_gateway']

        if alb_condition or nlb_condition or nat_gateway_condition:
            return 'COMPLIANT'
    return 'NON_COMPLIANT'

# Function to check if elastic network interface is in public subnet
def is_in_scope_subnet(eni_subnet):

    subnet_description = ec2_client.describe_subnets(
        SubnetIds=[eni_subnet]
    )

    for subnet in subnet_description['Subnets']:
        for tag in subnet['Tags']:
            if tag['Key'] == os.environ.get('TAG_KEY') and tag['Value'] == os.environ.get('TAG_VALUE'):
                return True
    
    return False
```