

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 Amazon Macie 保护 CloudWatch 日志中的敏感数据
<a name="secure-cloudwatch-logs-using-macie"></a>

*Amazon Web Services 的 Anisha Salunkhe、Omar Franco 和 David Guardiola*

## Summary
<a name="secure-cloudwatch-logs-using-macie-summary"></a>

此模式向您展示如何使用 Amazon Macie 通过实施全面的安全监控工作流程自动检测 Amazon Log CloudWatch s 日志组中的敏感数据。该解决方案使用 Amazon Data Firehose 将 CloudWatch 日志条目流式传输到亚马逊简单存储服务 (Amazon S3) Service。Macie 会定期扫描此存储桶以查找个人身份信息 (PII)、财务数据和其他敏感内容。基础架构是通过模板部署的，该 AWS CloudFormation 模板提供了所有必要的配置 AWS 服务 和配置。

CloudWatch 日志通常包含应用程序数据，这些数据可能无意中包含敏感的用户信息。这可能会造成合规和安全风险。传统的日志监控方法缺乏自动敏感数据检测功能。这可能使实时识别和应对潜在的数据暴露变得困难。

这种模式通过为日志系统中的敏感数据提供自动检测和警报，帮助安全团队和合规官员维护数据机密性。该解决方案支持通过亚马逊简单通知服务 (Amazon SNS) Simple Notification 通知进行主动事件响应，并自动将敏感数据隔离到安全的 Amazon S3 存储桶中。您可以自定义检测模式，并将工作流程与现有的安全操作流程集成。

## 先决条件和限制
<a name="secure-cloudwatch-logs-using-macie-prereqs"></a>

**先决条件**
+ 活跃的 AWS 账户
+ 创建 CloudFormation 堆栈的权限
+ 要监控的 CloudWatch 日志日志组
+ 用于接收来自 Amazon SNS 的通知的有效电子邮件地址
+ 对 [AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html) 的访问权限
+ （可选）访问已[安装](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)和[配置的 AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) (AWS CLI)

**限制**
+ Macie 受服务配额的限制。有关更多信息，请参阅 Macie [文档中的 Macie 配额](https://docs.aws.amazon.com/macie/latest/user/macie-quotas.html)。

## 架构
<a name="secure-cloudwatch-logs-using-macie-architecture"></a>

**目标架构**

下图显示了使用 Macie 检查 CloudWatch 日志条目中是否有敏感数据的工作流程。

 

![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/c9979070-09ab-4331-b969-5eff26fb2baa/images/d02f34ce-a7d1-4f96-a430-22975224eb9d.png)


该工作流程显示了以下步骤：

1.  CloudWatch 日志日志组生成日志，这些日志受订阅筛选器的约束。

1. 订阅筛选器将日志转发到 Amazon Data Firehose。

1. 这些日志在通过 Amazon Data Firehose 传输流时使用 AWS Key Management Service (AWS KMS) 密钥进行加密。

1. 传输流将日志传送到 Amazon S3 中导出的日志存储桶。

1. 每天凌晨 4 点，Amazon 都会 EventBridge 启动一项 AWS Lambda 功能，启动 Macie 扫描导出的日志存储桶中的敏感数据。

1. 如果 Macie 识别出存储桶中的敏感数据，则 Lambda 函数会从导出的日志存储桶中删除该日志，并使用对其进行加密。 AWS KMS key

1. Lambda 函数在数据隔离存储桶中隔离包含敏感数据的日志。

1. 识别敏感数据会启动 Amazon SNS 话题。

1. Amazon SNS 会向您配置的电子邮件地址发送电子邮件通知，其中包含有关包含敏感数据的日志的信息。

**已部署的资源**

该 CloudFormation 模板在您的目标中部署以下资源， AWS 账户 并且 AWS 区域：
+ 两个 Amazon S3 [存储桶](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html#BasicsBucket)：
  + 用于存储日志数据的导出 CloudWatch 日志存储桶
  + 用于存储敏感信息的数据隔离桶
+ 回应 Macie 调查结果的亚马逊 EventBridge [规则](https://docs.aws.amazon.com/macie/latest/user/findings-monitor-events-eventbridge.html)
+ AWS Lambda 用于启动事件并将日志导出到 Amazon S3 存储桶的[函数](https://docs.aws.amazon.com/lambda/latest/dg/concepts-basics.html#gettingstarted-concepts-function)
+ [亚马逊 SNS [主题和订阅](https://docs.aws.amazon.com/sns/latest/dg/sns-create-topic.html)](https://docs.aws.amazon.com/sns/latest/dg/sns-create-subscribe-endpoint-to-topic.html)
+ [亚马逊 Data Firehose 直播](https://docs.aws.amazon.com/firehose/latest/dev/what-is-this-service.html#key-concepts)
+ [一场 Macie 会话](https://docs.aws.amazon.com/macie/latest/user/macie-terms.html#macie-terms-session)
+ Macie [自定义数据标识符](https://docs.aws.amazon.com/macie/latest/user/macie-terms.html#macie-terms-cdi)
+  CloudWatch 日志订[阅过滤器](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters.html)
+ AWS KMS 用于加密存储在存储桶中的日志的[密钥](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html)
+ 解决方案所必需的 AWS Identity and Access Management (IAM) [角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)和[策略](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html)

## 工具
<a name="secure-cloudwatch-logs-using-macie-tools"></a>

**AWS 服务**
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)帮助您设置 AWS 资源，快速一致地配置资源，并在和的整个 AWS 账户 生命周期中对其进行管理 AWS 区域。
+ [Amazon CloudWatch Lo](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) gs 可帮助您集中所有系统和应用程序的日志， AWS 服务 这样您就可以监控它们并安全地将其存档。
+ [Amazon Data Firehose](https://docs.aws.amazon.com/firehose/latest/dev/what-is-this-service.html) 可帮助您将实时流数据传输到其他 AWS 服务自定义 HTTP 终端节点以及受支持的第三方服务提供商拥有的 HTTP 终端节点。
+ [Amazon EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html) 是一项无服务器事件总线服务，可帮助您将应用程序与来自各种来源的实时数据连接起来。例如，诸如 AWS Lambda 函数、使用 API 目的地的 HTTP 调用端点或其他 AWS 账户中的事件总线之类的来源。
+ [AWS Key Management Service (AWS KMS)](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) 可帮助您创建和控制加密密钥以帮助保护您的数据。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一项计算服务，可帮助您运行代码，无需预调配或管理服务器。它只在需要时运行您的代码，并自动进行扩展，因此您只需为使用的计算时间付费。
+ [Amazon Macie](https://docs.aws.amazon.com/macie/latest/user/what-is-macie.html) 可帮助您发现敏感数据，提供数据安全风险的可见性，并实现针对这些风险的自动防护。
+ [Amazon Simple Notification Service（Amazon SNS）](https://docs.aws.amazon.com/sns/latest/dg/welcome.html)可帮助您协调和管理发布者与客户端（包括 Web 服务器和电子邮件地址）之间的消息交换。
+ [Amazon Simple Storage Service（Amazon S3）](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)是一项基于云的对象存储服务，可帮助您存储、保护和检索任意数量的数据。

**代码存储库 **

此模式的代码可在 GitHub [sample-macie-for-securing-cloudwatch-l](https://github.com/aws-samples/sample-macie-for-securing-cloudwatch-logs) ogs 存储库中找到。

## 最佳实践
<a name="secure-cloudwatch-logs-using-macie-best-practices"></a>

遵循 CloudFormation 文档中的[CloudFormation 最佳实践](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html)。

## 操作说明
<a name="secure-cloudwatch-logs-using-macie-epics"></a>

### 部署解决方案
<a name="deploy-the-solution"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 克隆代码存储库。 | 输入以下命令将存储库克隆到本地工作站：<pre>git clone https://github.com/aws-samples/sample-macie-for-securing-cloudwatch-logs</pre> | 应用程序开发人员 | 
| （可选）编辑 CloudFormation 模板。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/secure-cloudwatch-logs-using-macie.html) | 应用程序开发人员 | 
| 选项 1-使用带有命令行参数的脚本进行部署。 | 输入以下命令以使用命令行参数部署解决方案，其中`true`仅当尚未启用 Amazon Macie 时，的值才为：`enable-macie`<pre>./scripts/test-macie-solution.sh --deploy-stack \<br />  --stack-name <stack name> \<br />  --email <email address> \<br />  --enable-macie <true or false> \<br />  --region <region> \<br />  --resource-name <prefix for all resources> \<br />  --bucket-name <bucket name></pre> | 常规 AWS | 
| 选项 2-使用带有环境变量的脚本进行部署。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/secure-cloudwatch-logs-using-macie.html) | 常规 AWS | 
| 选项 3-使用进行部署 AWS CLI。 | 输入以下命令以使用部署解决方案 AWS CLI，其中，`true`仅当尚未启用 Amazon Macie 时，的值才为：`EnableMacie`<pre>aws cloudformation create-stack \<br />  --region us-east-1 \<br />  --stack-name macie-for-securing-cloudwatch-logs \<br />  --template-body file://app/main.yml \<br />  --capabilities CAPABILITY_IAM \<br />  --parameters \<br />    ParameterKey=ResourceName,ParameterValue=<prefix for all resources> \<br />    ParameterKey=BucketName,ParameterValue=<bucket name> \<br />    ParameterKey=LogGroupName,ParameterValue=<path for log group> \<br />    ParameterKey=SNSTopicEndpointEmail,ParameterValue=<email address> \<br />    ParameterKey=EnableMacie,ParameterValue=<true or false></pre> |  | 
| 选项 4-通过部署 AWS 管理控制台。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/secure-cloudwatch-logs-using-macie.html) | 常规 AWS | 
| 监控部署状态并确认部署。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/secure-cloudwatch-logs-using-macie.html) | 常规 AWS | 
| 确认 Amazon SNS 订阅。 | 按照亚马逊 SNS 文档中[确认您的亚马逊 SNS 订阅](https://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.confirm.html)中的说明确认您的亚马逊 SNS 订阅。 | 应用程序开发人员 | 

### 测试解决方案
<a name="test-the-solution"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 选项 1 — 使用自动报告进行测试。 | 如果您使用默认堆栈名称，请输入以下命令来测试解决方案：<pre>./scripts/test-macie-solution.sh \<br />   --full-test</pre>如果您使用了自定义堆栈名称，请输入以下命令来测试解决方案：<pre>./scripts/test-macie-solution.sh \<br />   --full-test \<br />   --stack-name <stack name></pre>如果您使用了自定义堆栈名称和自定义参数，请输入以下命令来测试解决方案：<pre>./scripts/test-macie-solution.sh --full-test \<br />  --stack-name <stack name> \<br />  --region <region> \<br />  --log-group <log group path></pre> | 常规 AWS | 
| 选项 2 — 使用有针对性的验证进行测试。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/secure-cloudwatch-logs-using-macie.html) | 常规 AWS | 

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


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 选项 1-执行自动清理。 | 如果您使用默认堆栈名称，请输入以下命令来删除堆栈：<pre>./scripts/cleanup-macie-solution.sh \<br />  --full-cleanup</pre>如果您使用了自定义堆栈名称，请输入以下命令来删除堆栈：<pre>./scripts/cleanup-macie-solution.sh \<br />  --full-cleanup \<br />  --stack-name <stack name></pre>如果您使用了自定义堆栈名称和自定义参数，请输入以下命令来删除堆栈：<pre>./scripts/cleanup-macie-solution.sh \<br />  --full-cleanup \<br />  --stack-name <stack name> \<br />  --region <region> \<br />  --disable-macie <true or false></pre> | 常规 AWS | 
| 选项 2-执行 step-by-step清理。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/secure-cloudwatch-logs-using-macie.html) | 常规 AWS | 
| 验证清理完毕。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/secure-cloudwatch-logs-using-macie.html) | 常规 AWS | 

## 问题排查
<a name="secure-cloudwatch-logs-using-macie-troubleshooting"></a>


| 问题 | 解决方案 | 
| --- | --- | 
| CloudFormation 堆栈状态显示 **CREATE\$1FAILED**。 | 该 CloudFormation 模板配置为将日志发布到 CloudWatch 日志。您可以在中查看日志， AWS 管理控制台 这样就不必连接到 Amazon EC2 实例。有关更多信息，请参阅在[控制台中查看 CloudFormation 日志](https://aws.amazon.com/blogs/devops/view-cloudformation-logs-in-the-console/)（AWS 博客文章）。 | 
| CloudFormation `delete-stack`命令失败。 | 一些资源必须为空才能进行删除。例如，必须先删除 Amazon S3 存储桶中的所有对象或移除 Amazon EC2 安全组中的所有实例，然后才能删除该存储桶或安全组。有关更多信息，请参阅 Amazon S3 文档中的[删除堆栈失败](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/troubleshooting.html#troubleshooting-errors-delete-stack-fails)。 | 
| 解析参数时出错。 | 使用 AWS CLI 或 CloudFormation 控制台传入值时，请添加引号。 | 

## 相关资源
<a name="secure-cloudwatch-logs-using-macie-resources"></a>
+ [存储架构最佳实践](https://aws.amazon.com/architecture/storage/?docs3_bp1&cards-all.sort-by=item.additionalFields.sortDate&cards-all.sort-order=desc&awsf.content-type=*all&awsf.methodology=*all)（AWS 网站）
+ [指标筛选器、订阅过滤器、筛选日志事件和实时跟踪的筛选模式语法](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html)（CloudWatch 日志文档）
+ [使用 Amazon 设计和实施日志记录和监控 CloudWatch](https://docs.aws.amazon.com/prescriptive-guidance/latest/implementing-logging-monitoring-cloudwatch/welcome.html)（AWS 规范性指南）
+ [故障排除 CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/troubleshooting.html)（CloudFormation 文档）