如何使用 CloudTrail 查看我的 AWS 帳戶中的安全群組或資源是否已變更?

2 分的閱讀內容
0

為了稽核目的,我想要尋找在我的 Amazon Virtual Private Cloud (Amazon VPC) 中對安全群組所做的變更。檢閱 AWS 帳戶中安全群組變更的最佳方式是什麼?

簡短描述

若要檢視和監控 AWS 帳戶中的安全群組事件歷史記錄,您可以使用下列任何 AWS 服務和功能:

**注意:**以下是安全群組相關 API 呼叫的一些範例:

解決方法

若要使用 CloudTrail 事件歷史記錄來檢閱 AWS 帳戶中的安全群組變更

**注意:**您可以使用 CloudTrail 搜尋過去 90 天的事件歷史記錄。

1.    開啟CloudTrail 主控台

2.    選擇 Event history(事件歷史記錄)。

3.    在 Filter(篩選)中,選取下拉式清單。然後,選擇 Resource name(資源名稱)。

4.    在 Enter resource name(輸入資源名稱)文字方塊中,輸入資源的名稱 (例如,sg-123456789)。

5.    在 Time range(時間範圍)下,輸入所需的時間範圍。然後,選擇 Apply(套用)。

6.    在 Event time(事件時間)中,展開事件。然後,選擇 View event(檢視事件)。

如需詳細資訊,請參閱在 CloudTrail 主控台中檢視 CloudTrail 事件

CloudTrail 事件歷史記錄事件範例

**注意:**在此範例中,傳入規則允許來自 192.168.0.0/32 的 TCP 連接埠 998。

{
    "eventVersion": "1.05",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "123456789:Bob",
        "arn": "arn:aws:sts::123456789:assumed-role/123456789/Bob",
        "accountId": "123456789",
        "accessKeyId": "123456789",
        "sessionContext": {
            "attributes": {
                "mfaAuthenticated": "false",
                "creationDate": "2019-08-05T07:15:25Z"
            },
            "sessionIssuer": {
                "type": "Role",
                "principalId": "123456789",
                "arn": "arn:aws:iam::123456789:role/123456789",
                "accountId": "123456789",
                "userName": "Bob"
            }
        }
    },
    "eventTime": "2019-08-05T07:16:31Z",
    "eventSource": "ec2.amazonaws.com",
    "eventName": "AuthorizeSecurityGroupIngress",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "111.111.111.111",
    "userAgent": "console.ec2.amazonaws.com",
    "requestParameters": {
        "groupId": "sg-123456789",
        "ipPermissions": {
            "items": [
                {
                    "ipProtocol": "tcp",
                    "fromPort": 998,
                    "toPort": 998,
                    "groups": {},
                    "ipRanges": {
                        "items": [
                            {
                                "cidrIp": "192.168.0.0/32"
                            }
                        ]
                    },
                    "ipv6Ranges": {},
                    "prefixListIds": {}
                }
            ]
        }
    },
    "responseElements": {
        "requestId": "65ada3c8-d72f-4366-a583-9a9586811111",
        "_return": true
    },
    "requestID": "65ada3c8-d72f-4366-a583-9a9586811111",
    "eventID": "6c604d53-d9c3-492e-a26a-a48ac3f711111",
    "eventType": "AwsApiCall",
    "recipientAccountId": "123456789"
}

使用 Athena 查詢檢閱 AWS 帳戶中的安全群組變更

**注意:**若要使用 Athena 查詢 CloudTrail 日誌,您必須設定追蹤以登入 Amazon Simple Storage Service (Amazon S3) 儲存貯體。您可以使用 Athena 查詢過去 90 天內的 CloudTrail 日誌。

1.    開啟 Athena 主控台

2.    選擇 Query Editor(查詢編輯器)。Athena 查詢編輯器隨即開啟。

3.    在 Athena 查詢編輯器中,根據您的使用案例輸入查詢。然後,選擇 Run query(執行查詢)。

如需詳細資訊,請參閱瞭解 CloudTrail 日誌和 Athena 資料表

傳回所有 CloudTrail 事件以建立和刪除安全群組的範例

**重要事項:**將 示例表名稱 取代為您的表名。

SELECT *
FROM example table name
WHERE (eventname = 'CreateSecurityGroup' or eventname = 'DeleteSecurityGroup')
and eventtime > '2019-02-15T00:00:00Z'
order by eventtime asc

針對特定安全群組所做變更,傳回所有 CloudTrail 事件的範例

**重要事項:**將 示例表名稱 取代為您的表名。

SELECT *
FROM example table name
WHERE (eventname like '%SecurityGroup%' and requestparameters like '%sg-123456789%')
and eventtime > '2019-02-15T00:00:00Z'
order by eventtime asc;

使用 AWS Config 組態歷史記錄檢閱 AWS 帳戶中的安全群組變更

**注意:**您可以使用 AWS Config 檢視超過預設 90 天限制的安全群組事件歷史記錄的組態歷史記錄。您必須開啟 AWS Config 組態錄製程式。如需詳細資訊,請參閱管理組態錄製程式

1.    開啟CloudTrail 主控台

2.    選擇 Event history(事件歷史記錄)。

3.    在 Filter(篩選)中,選取下拉式清單。然後,選擇 Event name(事件名稱)。

4.    在 Enter event name(輸入事件名稱) 文字方塊中,輸入您要搜尋的事件類型 (例如,CreateSecurityGroup)。然後,選擇 Apply(套用)。

5.    在 Event time(事件時間)中,展開事件。

6.    在 Resources Referenced(參照的資源)窗格中,選擇Config timeline(組態時間表)欄中的時鐘圖示,以檢視組態時間表。

如需詳細資訊,請參閱檢視使用 AWS Config 參照的資源


AWS 官方
AWS 官方已更新 2 年前