如何使用 CloudTrail 跟踪我的账户中的安全组和资源更改?
2 分钟阅读
0
我想使用 AWS CloudTrail 跟踪我的 AWS 账户中的安全组和资源更改。
解决方法
您可以使用 AWS CloudTrail、Amazon Athena 和 AWS Config 来查看和监控您的 AWS 账户中的安全组事件历史记录。
先决条件:
- 配置 CloudTrail 以将日志传送到 Amazon Simple Storage Service (Amazon S3) 存储桶以进行 Athena 查询。
- 打开 AWS Config 配置记录器以查看默认 90 天限制之后的安全组事件历史记录。
使用 CloudTrail 事件历史记录查看安全组活动
**注意:**您可以使用 CloudTrail 搜索过去 90 天的事件历史记录。
- 打开 CloudTrail 控制台。
- 选择 Event history(事件历史记录)。
- 在 Filter(筛选器)中,从下拉列表中选择 Resource name(资源名称)。
- 在 Enter resource name(输入资源名称)文本框中,输入您的资源名称。例如:sg-123456789。
- 对于 Time range(时间范围),输入所需的时间范围。然后,选择 Apply(应用)。
- 在结果列表中选择一个事件。
有关详细信息,请参阅使用控制台查看最近的管理事件。
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 查询查看安全组活动
- 打开 Athena 控制台。
- 选择 Query Editor(查询编辑器)。
- 在 Athena 查询编辑器中,根据您的用例输入查询。然后,选择 Run query(运行查询)。
有关详细信息,请参阅了解 CloudTrail 日志和 Athena 表。
返回安全组创建和删除事件的查询示例:
**重要事项:**将 example table name 替换为您的表名。
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 配置历史记录查看安全组活动
- 打开 CloudTrail 控制台。
- 选择 Event history(事件历史记录)。
- 在 Filter(筛选器)中,从下拉列表中选择 Event name(事件名称)。
- 在 Enter event name(输入事件名称)文本框中,输入事件类型。例如,CreateSecurityGroup。然后,选择 Apply(应用)。
- 在结果列表中选择一个事件。
- 在 Resources Referenced(引用的资源)窗格中,选择 View AWS Config resource timeline(查看 AWS Config 资源时间表)以查看配置时间表。
有关详细信息,请参阅使用 AWS Config 查看引用的资源。
没有评论

