

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 Amazon Macie 保護 CloudWatch Logs 中的敏感資料
<a name="secure-cloudwatch-logs-using-macie"></a>

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

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

此模式說明如何使用 Amazon Macie 透過實作全面的安全監控工作流程，自動偵測 Amazon CloudWatch Logs 日誌群組中的敏感資料。解決方案使用 Amazon Data Firehose 將 CloudWatch Logs 項目串流至 Amazon Simple Storage Service (Amazon S3)。Macie 會定期掃描此儲存貯體是否有個人身分識別資訊 (PII)、財務資料和其他敏感內容。基礎設施是透過佈建所有必要 AWS 服務 和 組態的 AWS CloudFormation 範本進行部署。

CloudWatch Logs 通常包含的應用程式資料可能會不小心包含敏感的使用者資訊。這可能會產生合規和安全性風險。傳統日誌監控方法缺乏自動化敏感資料偵測功能。這可能會導致難以即時識別和回應潛在的資料暴露。

此模式透過自動偵測和提醒記錄系統中的敏感資料，協助安全團隊和合規主管維護資料機密性。此解決方案可透過 Amazon Simple Notification Service (Amazon SNS) 通知啟用主動事件回應，並自動將敏感資料隔離到安全的 Amazon S3 儲存貯體。您可以自訂偵測模式，並將工作流程與您現有的安全操作程序整合。

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

**先決條件**
+ 作用中 AWS 帳戶
+ 建立 CloudFormation 堆疊的許可
+ 您要監控的 CloudWatch Logs 日誌群組
+ 接收來自 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)和[設定的](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) AWS Command Line Interface (AWS CLI)

**限制**
+ Macie 受限於服務配額。如需詳細資訊，請參閱 [Macie 文件中的 Macie 配額](https://docs.aws.amazon.com/macie/latest/user/macie-quotas.html)。

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

**目標架構**

下圖顯示使用 Macie 檢查 CloudWatch Logs 日誌項目是否有敏感資料的工作流程。

 

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


工作流程會顯示下列步驟：

1. CloudWatch Logs 日誌群組會產生受訂閱篩選條件約束的日誌。

1. 訂閱篩選條件會將日誌轉送至 Amazon Data Firehose。

1. 當日誌通過 Amazon Data Firehose 交付串流時，會使用 AWS Key Management Service (AWS KMS) 金鑰加密日誌。

1. 交付串流會將日誌交付至 Amazon S3 中匯出的日誌儲存貯體。

1. Amazon EventBridge 會在每天凌晨 4 點啟動 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 Logs 資料的匯出日誌儲存貯體
  + 用於存放敏感資訊的資料隔離儲存貯體
+ 回應 Macie 調查結果的 Amazon EventBridge [規則](https://docs.aws.amazon.com/macie/latest/user/findings-monitor-events-eventbridge.html) 
+ 啟動事件並將日誌匯出至 Amazon S3 儲存貯體的AWS Lambda [函數](https://docs.aws.amazon.com/lambda/latest/dg/concepts-basics.html#gettingstarted-concepts-function) 
+ Amazon 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)
+ Amazon 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 Logs [訂閱篩選條件](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 Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) 可協助您集中所有系統、應用程式的日誌， 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-logs](https://github.com/aws-samples/sample-macie-for-securing-cloudwatch-logs) 儲存庫中使用。

## 最佳實務
<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>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製程式碼儲存庫。 | 輸入下列命令，將儲存庫複製到本機工作站：<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_tw/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_tw/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_tw/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_tw/prescriptive-guidance/latest/patterns/secure-cloudwatch-logs-using-macie.html) | 一般 AWS | 
| 確認 Amazon SNS 訂閱。 | 請遵循 [Amazon SNS 文件中的確認 ](https://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.confirm.html)Amazon SNS 訂閱中的指示，以確認您的 Amazon SNS 訂閱。 | 應用程式開發人員 | 

### 測試解決方案
<a name="test-the-solution"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選項 1 – 使用自動報告進行測試。 | 如果您使用預設堆疊名稱，請輸入下列命令來測試解決方案：<pre>./scripts/test-macie-solution.sh \<br />   --full-test</pre><br />如果您使用自訂堆疊名稱，請輸入下列命令來測試解決方案：<pre>./scripts/test-macie-solution.sh \<br />   --full-test \<br />   --stack-name <stack name></pre><br />如果您使用自訂堆疊名稱和自訂參數，請輸入下列命令來測試解決方案：<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_tw/prescriptive-guidance/latest/patterns/secure-cloudwatch-logs-using-macie.html) | 一般 AWS | 

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


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選項 1 – 執行自動清除。 | 如果您使用預設堆疊名稱，請輸入下列命令來刪除堆疊：<pre>./scripts/cleanup-macie-solution.sh \<br />  --full-cleanup</pre><br />如果您使用自訂堆疊名稱，請輸入下列命令來刪除堆疊：<pre>./scripts/cleanup-macie-solution.sh \<br />  --full-cleanup \<br />  --stack-name <stack name></pre><br />如果您使用自訂堆疊名稱和自訂參數，請輸入下列命令來刪除堆疊：<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_tw/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_tw/prescriptive-guidance/latest/patterns/secure-cloudwatch-logs-using-macie.html) | 一般 AWS | 

## 疑難排解
<a name="secure-cloudwatch-logs-using-macie-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| CloudFormation 堆疊狀態顯示 **CREATE\_FAILED**。 |  CloudFormation 範本設定為將日誌發佈至 CloudWatch Logs。您可以在 中檢視日誌， 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 網站）
+ [指標篩選條件、訂閱篩選條件、篩選條件日誌事件和 Live Tail 的篩選條件模式語法 ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html)(CloudWatch Logs 文件）
+ [使用 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 文件）