LoginSignup
1
0

More than 3 years have passed since last update.

【CloudTrail解説編】VPC操作ってどんなログ出るの?

Last updated at Posted at 2021-04-03

はじめに

皆様、CloudTrailをうまく活用出来てますか?
シリーズ化しようと思っているCloudTrail解説編の第二弾になります!

image.png

「CloudTrailを活用しようと思っているけど、具体的にどう見れば良いのか分からない」
という相談をよくいただきます。

ご要望にお応えできるナレッジ共有が続けられれば良いなと思っています。
以下は第一弾の記事になります。

【参考】
【CloudTrail解説編】AWSマネージメントコンソールのログイン監視

今回実施したこと

今回は、マネージメントコンソールでのVPCに関する操作に特化した内容になっています。
よく利用する下記のサービスを中心に解説したいと思います。

  • VPC
  • サブネット
  • ルートテーブル
  • インターネットゲートウェイ (以下、IGW)
  • Elastic IP
  • NATゲートウェイ (以下、NATGW)
  • ピアリング接続
  • ネットワークACL
  • セキュリティグループ

テストシナリオ

具体的には以下の32個のシナリオで動作テストしてみました。

# サービス名 分類 テストシナリオ eventName (=API名)
01 VPC 作成 VPCを新規作成する CreateVpc
02 VPC 変更 VPCに新しいCIDRを追加する AssociateVpcCidrBlock
03 VPC 削除 VPCを削除する DeleteVpc
04 サブネット 作成 VPCにサブネットを新規作成する CreateSubnet
05 サブネット 変更 「自動割り当てIP設定の変更」をオンにする ModifySubnetAttribute
06 サブネット 削除 VPCからサブネットを削除する DeleteSubnet
07 ルートテーブル 作成 VPCにルートテーブルを新規作成する CreateRouteTable
08 ルートテーブル 変更 デフォルトルート(0.0.0.0/0 via IGW)を追加する CreateRoute
09 ルートテーブル 変更 デフォルトルート(0.0.0.0/0 via NATGW)を変更する ReplaceRoute
10 ルートテーブル 変更 デフォルトルート(0.0.0.0/0 viq NATGW)を削除する DeleteRoute
11 ルートテーブル 削除 ルートテーブルを削除する DeleteRouteTable
12 IGW 作成 IGWを新規作成する CreateInternetGateway
13 IGW 変更 VPCにIGWをアタッチする AttachInternetGateway
14 IGW 削除 VPCからIGWをデタッチする DetachInternetGateway
15 IGW 削除 IGWを削除する DeleteInternetGateway
16 Elastic IP 作成 Elastic IPを割り当てる AllocateAddress
17 Elastic IP 変更 EC2にElastic IPを関連付ける AssociateAddress
18 Elastic IP 変更 EC2からElastic IPの関連付けを解除する DisassociateAddress
19 Elastic IP 削除 Elastic IPを解放する ReleaseAddress
20 NATGW 作成 NATGWを新規作成する CreateNatGateway
21 NATGW 削除 NATGWを削除する DeleteNatGateway
22 ピアリング接続 作成 VPCにピアリング接続を作成する CreateVpcPeeringConnection
23 ピアリング接続 削除 ピアリング接続を削除する DeleteVpcPeeringConnection
24 ネットワークACL 作成 VPCにネットワークACLを作成する CreateNetworkAcl
25 ネットワークACL 変更 ネットワークACLのアウトバウンドルールを追加する CreateNetworkAclEntry
26 ネットワークACL 変更 ネットワークACLをサブネットに割り当てる ReplaceNetworkAclAssociation
27 ネットワークACL 変更 ネットワークACLのアウトバウンドルールを削除する DeleteNetworkAclEntry
28 ネットワークACL 削除 ネットワークACLを削除する DeleteNetworkAcl
29 セキュリティグループ 作成 VPCにセキュリティグループを作成する CreateSecurityGroup
30 セキュリティグループ 変更 インバウンドルールに許可ルールを追加する AuthorizeSecurityGroupIngress
31 セキュリティグループ 変更 EC2にセキュリティグループを割り当てる ModifyNetworkInterfaceAttribute
32 セキュリティグループ 削除 セキュリティグループを削除する DeleteSecurityGroup

eventNameとは

イベントの内容であるAPI名が記録されるCloudTrail証跡ログのフィールドの1つです。
マネージメントコンソールで操作する際、URLにパラメータとしてAPI名が埋め込まれています。
https://us-east-2.console.aws.amazon.com/vpc/home?region=us-east-2#CreateVpc:
image.png

CloudTrailは、AWS内の各サービスを操作したAPIコールログを記録するサービスになります。
eventNameを理解することで、AWSで何が起きているか理解できると言っても過言ではありません。

共通するフィールド

以下、CloudTrail証跡ログのサンプルになります。形式はJSONになります。
requestParametersresponseElements以外のフィールドはどのイベントにも存在します。

共通するフィールド
{
    "eventVersion": "<ログイベント形式のバージョン>",
    "userIdentity": {
        "type": "<イベントの種類>",
        "principalId": "<呼び出しを行ったエンティティの一意の識別子>",
        "arn": "<操作したIAMユーザのARN>",
        "accountId": "<AWSアカウント(12桁)>",
        "accessKeyId": "<AWSアクセスキー>",
        "userName": "<操作したIAMユーザ名>",
        "sessionContext": {
            "sessionIssuer": {"<認証情報がどのように取得されたかに関する情報>"},
            "webIdFederationData": {"<IDプロバイダーに関する情報>"},
            "attributes": {
                "mfaAuthenticated": "<MFAデバイスによる認証有無(true/false)>",
                "creationDate": "<一時的セキュリティ認証情報が発行された時刻(ISO8601形式)>"
            }
        }
    },
    "eventTime": "<イベント発生時刻(ISO8601形式)>",
    "eventSource": "<リクエストが行われたAWSサービス>",
    "eventName": "<イベント名(=API名)>",
    "awsRegion": "<ログインしたAWSリージョン>",
    "sourceIPAddress": "<送信元IPアドレス>",
    "userAgent": "<接続元のユーザーエージェント(マネージメントコンソールだとconsole.ec2.amazonaws.comになる)",
    "requestParameters": {
        "<リクエストとともに送信されたパラメータ(後述しますが、APIに応じて内容が異なる)>"
    },
    "responseElements": {
        "<変更を行うアクションのレスポンスの要素(後述しますが、APIに応じて内容が異なる)>"
    },
    "requestID": "<リクエストを識別するID>",
    "eventID": "<CloudTrail証跡ログの中で一意となるイベントID>",
    "readOnly": <読み取り専用の操作であるかどうか(falseになる)>,
    "eventType": "<イベントレコードを生成したイベントのタイプ(AwsApiCallになる)>",
    "managementEvent": <管理用イベントかどうか(trueになる)>,
    "eventCategory": "<イベントのカテゴリ(Managementになる)>",
    "recipientAccountId": "<イベントを受信したAWSアカウント(12桁)>"
}

【参考】
CloudTrail レコードの内容
CloudTrail userIdentity要素

各イベントごとのログ内容と見張るポイント

ここからは、シナリオごとに出力された証跡ログの中でも
個々に異なるrequestParametersresponseElementsに絞って解説します。

1. CreateVpc

test_vpcという名前のVPCを新規作成した時に出力されたログになります。
CIDRはIPv4の10.1.0.0/16のみのデフォルトテナンシーです。

CreateVpc
    "requestParameters": {
        "cidrBlock": "10.1.0.0/16",
        "instanceTenancy": "default",
        "amazonProvidedIpv6CidrBlock": false,
        "tagSpecificationSet": {
            "items": [
                {
                    "resourceType": "vpc",
                    "tags": [
                        {
                            "key": "Name",
                            "value": "test_vpc"
                        }
                    ]
                }
            ]
        }
    },
    "responseElements": {
        "requestId": "7ef273c6-a35e-4b94-b3d9-4aa7e68839b4",
        "vpc": {
            "vpcId": "vpc-0cadedb1948e67f9d",
            "state": "pending",
            "ownerId": "123456789012",
            "cidrBlock": "10.1.0.0/16",
            "cidrBlockAssociationSet": {
                "items": [
                    {
                        "cidrBlock": "10.1.0.0/16",
                        "associationId": "vpc-cidr-assoc-04636d42262eb0800",
                        "cidrBlockState": {
                            "state": "associated"
                        }
                    }
                ]
            },
            "ipv6CidrBlockAssociationSet": {},
            "dhcpOptionsId": "dopt-f9138391",
            "instanceTenancy": "default",
            "tagSet": {
                "items": [
                    {
                        "key": "Name",
                        "value": "test_vpc"
                    }
                ]
            },
            "isDefault": false
        }
    }

2. AssociateVpcCidrBlock

1.で作成したtest_vpcに対して
新しいCIDR10.2.0.0/16を追加した時に出力されたログになります。

AssociateVpcCidrBlock
    "requestParameters": {
        "AssociateVpcCidrBlockRequest": {
            "VpcId": "vpc-0cadedb1948e67f9d",
            "CidrBlock": "10.2.0.0/16"
        }
    },
    "responseElements": {
        "AssociateVpcCidrBlockResponse": {
            "xmlns": "http://ec2.amazonaws.com/doc/2016-11-15/",
            "cidrBlockAssociation": {
                "cidrBlock": "10.2.0.0/16",
                "cidrBlockState": {
                    "state": "associating"
                },
                "associationId": "vpc-cidr-assoc-09af3e1641bb40a37"
            },
            "requestId": "c0616704-7bbe-46a4-86d3-7257a5a70512",
            "vpcId": "vpc-0cadedb1948e67f9d"
        }
    }

3. DeleteVpc

1.で作成したtest_vpcを削除した時に出力されたログになります。

DeleteVpc
    "requestParameters": {
        "vpcId": "vpc-0cadedb1948e67f9d"
    },
    "responseElements": {
        "requestId": "05855acc-fcbf-4b1f-b5be-cac7e9cef331",
        "_return": true
    }

4. CreateSubnet

1.で作成したVPCにtest_subというサブネットを新規作成した時に出力されたログになります。
AZ名はus-east-2a、AZIDはuse2-az1に作成されていますね。

CreateSubnet
    "requestParameters": {
        "vpcId": "vpc-0cadedb1948e67f9d",
        "cidrBlock": "10.1.1.0/24",
        "availabilityZoneId": "use2-az1",
        "tagSpecificationSet": {
            "items": [
                {
                    "resourceType": "subnet",
                    "tags": [
                        {
                            "key": "Name",
                            "value": "test_sub"
                        }
                    ]
                }
            ]
        }
    },
    "responseElements": {
        "requestId": "bc989990-24e8-40d2-b805-239ead83b9d8",
        "subnet": {
            "subnetId": "subnet-09e76b27bf9f41841",
            "subnetArn": "arn:aws:ec2:us-east-2:123456789012:subnet/subnet-09e76b27bf9f41841",
            "state": "available",
            "vpcId": "vpc-0cadedb1948e67f9d",
            "cidrBlock": "10.1.1.0/24",
            "ipv6CidrBlockAssociationSet": {},
            "availableIpAddressCount": 251,
            "availabilityZone": "us-east-2a",
            "availabilityZoneId": "use2-az1",
            "ownerId": "123456789012",
            "defaultForAz": false,
            "mapPublicIpOnLaunch": false,
            "assignIpv6AddressOnCreation": false,
            "tagSet": {
                "items": [
                    {
                        "key": "Name",
                        "value": "test_sub"
                    }
                ]
            }
        }
    }

5. ModifySubnetAttribute

4.で作成したtest_sub自動割り当てIP設定の変更をオンにした時に出力されたログになります。
mapPublicIpOnLaunchの値がtrueにセットされていますね。

ModifySubnetAttribute
    "requestParameters": {
        "subnetId": "subnet-09e76b27bf9f41841",
        "mapPublicIpOnLaunch": {
            "value": true
        }
    },
    "responseElements": {
        "requestId": "a3e37d56-eb0e-4d5f-a2bc-b3763e1784fb",
        "_return": true
    }

6. DeleteSubnet

4.で作成したtest_subのサブネットを削除した時に出力されたログになります。

DeleteSubnet
    "requestParameters": {
        "subnetId": "subnet-09e76b27bf9f41841"
    },
    "responseElements": {
        "requestId": "23915c2c-8632-44ae-b355-bc23d229f404",
        "_return": true
    }

7. CreateRouteTable

1.で作成したVPCにルートテーブルを新規作成した時に出力されたログになります。
VPCに含まれる2つのCIDRに対して、ローカルでルーティングする経路がアサインされてますね。

CreateRouteTable
    "requestParameters": {
        "vpcId": "vpc-0cadedb1948e67f9d"
    },
    "responseElements": {
        "requestId": "173e741e-9853-4528-8a5d-18e9eb89e0d2",
        "routeTable": {
            "routeTableId": "rtb-0ae9547160a79eed8",
            "vpcId": "vpc-0cadedb1948e67f9d",
            "ownerId": "123456789012",
            "routeSet": {
                "items": [
                    {
                        "destinationCidrBlock": "10.1.0.0/16",
                        "gatewayId": "local",
                        "state": "active",
                        "origin": "CreateRouteTable"
                    },
                    {
                        "destinationCidrBlock": "10.2.0.0/16",
                        "gatewayId": "local",
                        "state": "active",
                        "origin": "CreateRouteTable"
                    }
                ]
            },
            "associationSet": {},
            "propagatingVgwSet": {},
            "tagSet": {}
        }
    }

8. CreateRoute

7.で作成したルートテーブルに新規ルートとして
12.で作成したIGWをターゲットにデフォルトルートを追加した時に出力されたログになります。

CreateRoute
    "requestParameters": {
        "routeTableId": "rtb-0ae9547160a79eed8",
        "destinationCidrBlock": "0.0.0.0/0",
        "gatewayId": "igw-00ec58b652195d8a3"
    },
    "responseElements": {
        "requestId": "edea8f3d-f3e6-484b-8d76-54114368b0f5",
        "_return": true
    }

【補足】
AWSマネージメントコンソールに不正ログインされるような攻撃を受けた場合
許可していない宛先へのルートが作られていないか見張る上で活用することができます。

9. ReplaceRoute

8.で作成したデフォルトルートのターゲットについて
20.で作成したNATゲートウェイに変更した時に出力されたログになります。

ReplaceRoute
    "requestParameters": {
        "routeTableId": "rtb-0ae9547160a79eed8",
        "destinationCidrBlock": "0.0.0.0/0",
        "natGatewayId": "nat-02d3aba70e2c742c2"
    },
    "responseElements": {
        "requestId": "73ad380d-00b7-4657-a230-574cf06276ad",
        "_return": true
    }

10. DeleteRoute

8.で作成したルート(デフォルトルート)を削除した時に出力されたログになります。

DeleteRoute
    "requestParameters": {
        "routeTableId": "rtb-0ae9547160a79eed8",
        "destinationCidrBlock": "0.0.0.0/0"
    },
    "responseElements": {
        "requestId": "f649ab57-92cb-46a2-852b-7a2a6870d4ae",
        "_return": true
    }

11. DeleteRouteTable

7.で作成したルートテーブルを削除した時に出力されたログになります。

DeleteRouteTable
    "requestParameters": {
        "routeTableId": "rtb-0ae9547160a79eed8"
    },
    "responseElements": {
        "requestId": "74a18b25-7036-4d3d-a424-30a5bfe98146",
        "_return": true
    }

12. CreateInternetGateway

test_igwという名前のIGWを新規作成した時に出力されたログになります。

CreateInternetGateway
    "requestParameters": {
        "tagSpecificationSet": {
            "items": [
                {
                    "resourceType": "internet-gateway",
                    "tags": [
                        {
                            "key": "Name",
                            "value": "test_igw"
                        }
                    ]
                }
            ]
        }
    },
    "responseElements": {
        "requestId": "1b245752-d0b1-4073-b3b3-01c46c3a1584",
        "internetGateway": {
            "internetGatewayId": "igw-00ec58b652195d8a3",
            "ownerId": "123456789012",
            "attachmentSet": {},
            "tagSet": {
                "items": [
                    {
                        "key": "Name",
                        "value": "test_igw"
                    }
                ]
            },
            "association": {}
        }
    }

13. AttachInternetGateway

12.で作成したIGWを1.で作成したVPCにアタッチした時に出力されたログになります。

AttachInternetGateway
    "requestParameters": {
        "internetGatewayId": "igw-00ec58b652195d8a3",
        "vpcId": "vpc-0cadedb1948e67f9d"
    },
    "responseElements": {
        "requestId": "be367983-bbdb-4348-a5a7-b0e718acfa0a",
        "_return": true
    }

【補足】
AWSマネージメントコンソールに不正ログインされるような攻撃を受けた場合
インターネットとの経路を勝手に作られていないか見張る上で活用することができます。

14. DetachInternetGateway

13.でVPCにアタッチしたIGWをでアタッチした時に出力されたログになります。

DetachInternetGateway
    "requestParameters": {
        "internetGatewayId": "igw-00ec58b652195d8a3",
        "vpcId": "vpc-0cadedb1948e67f9d"
    },
    "responseElements": {
        "requestId": "ec125fa8-3641-432e-b2ed-52d2170fe6ef",
        "_return": true
    }

15. DeleteInternetGateway

12.で作成したIGWを削除した時に出力されたログになります。

DeleteInternetGateway
    "requestParameters": {
        "internetGatewayId": "igw-00ec58b652195d8a3"
    },
    "responseElements": {
        "requestId": "3efbdbb4-306b-4ed8-8c99-6e4c0513e873",
        "_return": true
    }

16. AllocateAddress

Elastic IPをtest_eipという名前で新規作成した時に出力されたログになります。
オハイオリージョンus-east-2で利用できるIPアドレス3.141.213.252が割り当てられました。

AllocateAddress
    "requestParameters": {
        "domain": "vpc",
        "tagSpecificationSet": {
            "items": [
                {
                    "resourceType": "elastic-ip",
                    "tags": [
                        {
                            "key": "Name",
                            "value": "test_eip"
                        }
                    ]
                }
            ]
        }
    },
    "responseElements": {
        "requestId": "58a30bb4-5e25-4688-ad48-84c698186027",
        "publicIp": "3.141.213.252",
        "domain": "vpc",
        "allocationId": "eipalloc-019faf9a13318ac20",
        "publicIpv4Pool": "amazon",
        "networkBorderGroup": "us-east-2"
    }

17. AssociateAddress

16.で割り当てられたElastic IPをEC2インスタンスに関連付けした時に出力されたログになります。
該当のEC2のインスタンスIDはi-0b82f7b0f0c2e3c0eですね。

AssociateAddress
    "requestParameters": {
        "instanceId": "i-0b82f7b0f0c2e3c0e",
        "allocationId": "eipalloc-019faf9a13318ac20",
        "allowReassociation": false
    },
    "responseElements": {
        "requestId": "68d66732-c49d-4dda-99fc-7cc298d3e5c9",
        "_return": true,
        "associationId": "eipassoc-0b3422d49dd4e34c5"
    }

【補足】
AWSマネージメントコンソールに不正ログインされるような攻撃を受けた場合
インターネットとの通信できないEC2にElastic IPが関連付けられていないか
見張る上で活用することができます。

18. DisassociateAddress

17.で関連付けたElastic IPを解除した時に出力されたログになります。

DisassociateAddress
    "requestParameters": {
        "associationId": "eipassoc-0b3422d49dd4e34c5"
    },
    "responseElements": {
        "requestId": "a69caa2b-51ed-4d0c-85a8-e1d60c6c5b9a",
        "_return": true
    }

19. ReleaseAddress

16.で新規作成したElastic IPを解放した時に出力されたログになります。

ReleaseAddress
    "requestParameters": {
        "allocationId": "eipalloc-019faf9a13318ac20"
    },
    "responseElements": {
        "requestId": "e45658a4-114f-4985-8d4b-39e4271e4d06",
        "_return": true
    }

20. CreateNatGateway

test_natgwという名前のNATGWを新規作成した時に出力されたログになります。
NATGWに関連付けしたElastic IPは16.で作成したIPアドレスになります。
NATGWは4.で作成したサブネット(subnet-09e76b27bf9f41841)に作成しています。

CreateNatGateway
    "requestParameters": {
        "CreateNatGatewayRequest": {
            "AllocationId": "eipalloc-019faf9a13318ac20",
            "SubnetId": "subnet-09e76b27bf9f41841",
            "TagSpecification": {
                "ResourceType": "natgateway",
                "tag": 1,
                "Tag": {
                    "Value": "test_natgw",
                    "tag": 1,
                    "Key": "Name"
                }
            }
        }
    },
    "responseElements": {
        "CreateNatGatewayResponse": {
            "xmlns": "http://ec2.amazonaws.com/doc/2016-11-15/",
            "natGateway": {
                "connectivityType": "public",
                "subnetId": "subnet-09e76b27bf9f41841",
                "tagSet": {
                    "item": {
                        "value": "test_natgw",
                        "key": "Name"
                    }
                },
                "natGatewayAddressSet": {
                    "item": {
                        "allocationId": "eipalloc-019faf9a13318ac20"
                    }
                },
                "createTime": "2021-03-31T23:22:22.000Z",
                "vpcId": "vpc-0cadedb1948e67f9d",
                "natGatewayId": "nat-02d3aba70e2c742c2",
                "state": "pending"
            },
            "requestId": "7e55bbce-e95a-4cb3-86da-3ead71285982"
        }
    }

21. DeleteNatGateway

20.で作成したNATGWを削除した時に出力されたログになります。

DeleteNatGateway
    "requestParameters": {
        "DeleteNatGatewayRequest": {
            "NatGatewayId": "nat-02d3aba70e2c742c2"
        }
    },
    "responseElements": {
        "DeleteNatGatewayResponse": {
            "xmlns": "http://ec2.amazonaws.com/doc/2016-11-15/",
            "requestId": "2ac357ab-14dd-4081-9cf5-ed9ea9f6c835",
            "natGatewayId": "nat-02d3aba70e2c742c2"
        }
    }

22. CreateVpcPeeringConnection

1.で作成したVPCにVPCピアリングを新規作成した時に出力されたログになります。
ピアリングのリクエストを承認した際にはCloudTrailの証跡ログは発見できませんでした。

CreateVpcPeeringConnection
    "requestParameters": {
        "vpcId": "vpc-0cadedb1948e67f9d",
        "peerVpcId": "vpc-09be24b8533330c11"
    },
    "responseElements": {
        "requestId": "b7a8fa3f-3db2-4e35-bc6d-b15d97bb529c",
        "vpcPeeringConnection": {
            "vpcPeeringConnectionId": "pcx-0fa806d53eb4264f5",
            "requesterVpcInfo": {
                "ownerId": "123456789012",
                "vpcId": "vpc-0cadedb1948e67f9d",
                "cidrBlock": "10.1.0.0/16",
                "region": "us-east-2",
                "cidrBlockSet": {
                    "items": [
                        {
                            "cidrBlock": "10.1.0.0/16"
                        },
                        {
                            "cidrBlock": "10.2.0.0/16"
                        }
                    ]
                },
                "peeringOptions": {
                    "allowEgressFromLocalClassicLinkToRemoteVpc": false,
                    "allowEgressFromLocalVpcToRemoteClassicLink": false,
                    "allowDnsResolutionFromRemoteVpc": false
                }
            },
            "accepterVpcInfo": {
                "ownerId": "123456789012",
                "vpcId": "vpc-09be24b8533330c11",
                "region": "us-east-2"
            },
            "status": {
                "code": "initiating-request",
                "message": "Initiating Request to 123456789012"
            },
            "expirationTime": 1617838496000,
            "tagSet": {}
        }
    }

【補足】
AWSマネージメントコンソールに不正ログインされるような攻撃を受けた場合
攻撃者の用意したVPCとピアリングされてデータを盗まれないことを見張る上で
活用することができます。

23. DeleteVpcPeeringConnection

22.で作成したVPCピアリングを削除した時に出力されたログになります。

DeleteVpcPeeringConnection
    "requestParameters": {
        "vpcPeeringConnectionId": "pcx-0fa806d53eb4264f5"
    },
    "responseElements": {
        "requestId": "50cdc2c4-890a-4896-92d4-9a0484758160",
        "_return": true
    }

24. CreateNetworkAcl

1.で作成したVPCにネットワークACLtest_naclを新規作成した時に出力されたログになります。

CreateNetworkAcl
    "requestParameters": {
        "vpcId": "vpc-0cadedb1948e67f9d",
        "tagSpecificationSet": {
            "items": [
                {
                    "resourceType": "network-acl",
                    "tags": [
                        {
                            "key": "Name",
                            "value": "test_nacl"
                        }
                    ]
                }
            ]
        }
    },
    "responseElements": {
        "requestId": "d3ba4ccd-e147-4136-b2e9-10df3b1174a6",
        "networkAcl": {
            "networkAclId": "acl-0ad5205baab7d5322",
            "vpcId": "vpc-0cadedb1948e67f9d",
            "ownerId": "123456789012",
            "isDefault": false,
            "entrySet": {
                "items": [
                    {
                        "ruleNumber": 32767,
                        "aclProtocol": "-1",
                        "ruleAction": "deny",
                        "cidrBlock": "0.0.0.0/0",
                        "egress": true,
                        "icmpTypeCode": {},
                        "portRange": {}
                    },
                    {
                        "ruleNumber": 32767,
                        "aclProtocol": "-1",
                        "ruleAction": "deny",
                        "cidrBlock": "0.0.0.0/0",
                        "egress": false,
                        "icmpTypeCode": {},
                        "portRange": {}
                    }
                ]
            },
            "associationSet": {},
            "tagSet": {
                "items": [
                    {
                        "key": "Name",
                        "value": "test_nacl"
                    }
                ]
            }
        }
    }

25. CreateNetworkAclEntry

24.で作成したネットワークACLのアウトバウンドルールに対して
全ての通信、全ての宛先に対する通信許可ルールを追加した時に出力されたログになります。

CreateNetworkAclEntry
    "requestParameters": {
        "networkAclId": "acl-0ad5205baab7d5322",
        "ruleNumber": 1,
        "egress": true,
        "ruleAction": "allow",
        "icmpTypeCode": {},
        "portRange": {},
        "aclProtocol": "-1",
        "cidrBlock": "0.0.0.0/0"
    },
    "responseElements": {
        "requestId": "796c9f8b-e0ff-4c6f-bcc6-d2d511aa96f5",
        "_return": true
    }

26. ReplaceNetworkAclAssociation

24.で作成したネットワークACLを4.で作成したサブネットに関連付けた時に出力されたログになります。

ReplaceNetworkAclAssociation
    "requestParameters": {
        "associationId": "aclassoc-53fcc036",
        "networkAclId": "acl-0ad5205baab7d5322"
    },
    "responseElements": {
        "requestId": "069245c7-26a2-483e-b420-75e0da5f354c",
        "newAssociationId": "aclassoc-009f98f53c372eba8"
    }

27. DeleteNetworkAclEntry

25.で追加したアウトバウンドルールを削除した時に出力されたログになります。

DeleteNetworkAclEntry
    "requestParameters": {
        "networkAclId": "acl-0ad5205baab7d5322",
        "ruleNumber": 1,
        "egress": true
    },
    "responseElements": {
        "requestId": "02473d41-f3e7-420b-9dfb-19867529e033",
        "_return": true
    }

28. DeleteNetworkAcl

24.で作成したネットワークACLを削除した時に出力されたログになります。

DeleteNetworkAcl
    "requestParameters": {
        "networkAclId": "acl-0ad5205baab7d5322"
    },
    "responseElements": {
        "requestId": "f8a56f1e-5bee-410c-a130-9b95ef0f76aa",
        "_return": true
    }

29. CreateSecurityGroup

1.で作成したVPCにセキュリティグループtest_sgを新規作成した時に出力されたログになります。

CreateSecurityGroup
    "requestParameters": {
        "groupName": "test_sg",
        "groupDescription": "test",
        "vpcId": "vpc-0cadedb1948e67f9d",
        "tagSpecificationSet": {
            "items": [
                {
                    "resourceType": "security-group",
                    "tags": [
                        {
                            "key": "Name",
                            "value": "test_sg"
                        }
                    ]
                }
            ]
        }
    },
    "responseElements": {
        "requestId": "73770429-2956-4bb3-b9a5-430deb5bf2ae",
        "_return": true,
        "groupId": "sg-07ead3b5afa105744",
        "tagSet": {
            "items": [
                {
                    "key": "Name",
                    "value": "test_sg"
                }
            ]
        }
    }

30. AuthorizeSecurityGroupIngress

29.で作成したセキュリティグループのインバウンドルールとして
10.1.0.0/16宛のICMP通信を追加した時に出力されたログになります。

AuthorizeSecurityGroupIngress
    "requestParameters": {
        "groupId": "sg-07ead3b5afa105744",
        "ipPermissions": {
            "items": [
                {
                    "ipProtocol": "icmp",
                    "fromPort": -1,
                    "toPort": -1,
                    "groups": {},
                    "ipRanges": {
                        "items": [
                            {
                                "cidrIp": "10.1.0.0/16",
                                "description": "test"
                            }
                        ]
                    },
                    "ipv6Ranges": {},
                    "prefixListIds": {}
                }
            ]
        }
    },
    "responseElements": {
        "requestId": "7ffc5e80-0e85-41cb-ac8b-d462bab14470",
        "_return": true
    }

【補足】
AWSマネージメントコンソールに不正ログインされるような攻撃を受けた場合
EC2で許可していない通信が勝手に追加されていないことを見張る上で活用することができます。

31. ModifyNetworkInterfaceAttribute

29.で作成したセキュリティグループをEC2に割り当てた時に出力されたログになります。
eni-01078c68e9e75ad3dはEC2のネットワークインターフェースIDですね。

ModifyNetworkInterfaceAttribute
    "requestParameters": {
        "networkInterfaceId": "eni-01078c68e9e75ad3d",
        "groupSet": {
            "items": [
                {
                    "groupId": "sg-07ead3b5afa105744"
                }
            ]
        }
    },
    "responseElements": {
        "requestId": "d6f30c00-b835-4749-bbd7-0f371828699b",
        "_return": true
    }

32. DeleteSecurityGroup

29.で作成したセキュリティグループを削除時に出力されたログになります。

DeleteSecurityGroup
    "requestParameters": {
        "groupId": "sg-07ead3b5afa105744"
    },
    "responseElements": {
        "requestId": "60e1fb9e-5fcf-4c31-b098-2f9847f5b114",
        "_return": true
    }

まとめ

さて、いかがでしたでしょうか?

ここまで細かくVPCに関するAPIコールログを見ることないんじゃない?って言われそうですよね。
はい、そうだと思います。ですが、どのような新たな攻撃が来るかわかりません。
ビジネスアプリケーションに必要な通信に対して、少しでも違和感がないかを見極めるには
必要になることもあります。

AWS Config Rules1でも見張れるものもあります。
restricted-ssheip-attachedec2-security-group-attached-to-eni
などを利用する感じですね。

しかしマネージドルールにない要件を検知したい場合は、カスタムルールを作成するか
CloudTrailを活用した検知ルールをCloudWatchで作成していくことになります。

いずれにしてもAPIコールログを理解できるに越したことはないと思います。
皆様にとっても役に立つナレッジになっていれば良いなと思う次第です^^

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0