

# SEC04-BP01 設定服務和應用程式記錄
<a name="sec_detect_investigate_events_app_service_logging"></a>

 設定整個工作負載中的記錄，包括應用程式日誌、資源日誌和 AWS 服務日誌。例如：確定組織內的所有帳戶已啟用 AWS CloudTrail、Amazon CloudWatch Logs、Amazon GuardDuty 和 AWS Security Hub CSPM。 

基本實務是在帳戶層級建立一套偵測機制。這組基本機制旨在記錄和偵測對您帳戶中所有資源的各種動作。可讓您建立完整的偵測功能，其中包含自動修復的選項，以及新增功能的合作夥伴整合。

在 AWS 中，此基本套組中的服務包括：
+ [AWS CloudTrail](http://aws.amazon.com/cloudtrail) 提供 AWS 帳戶活動的事件歷史記錄，包括透過 AWS 管理主控台、AWS 開發套件、命令列工具及其他 AWS 服務所採取的動作。
+ [AWS Config](http://aws.amazon.com/config) 可監控和記錄 AWS 資源組態，並讓您根據所需的組態自動評估和修復。
+ [Amazon GuardDuty](http://aws.amazon.com/guardduty) 是威脅偵測服務，可持續監控惡意活動和未經授權的行為，以保護 AWS 帳戶和工作負載。
+ [AWS Security Hub CSPM](http://aws.amazon.com/security-hub) 提供以單一位置從多個 AWS 服務和選用的第三方產品將安全提醒或發現結果加以彙總、組織和排列優先順序，為您提供安全提醒和合規狀態的全面檢視。

建立在帳戶層級的基礎上，許多核心 AWS 服務 (例如 [Amazon Virtual Private Cloud Console (Amazon VPC)](http://aws.amazon.com/vpc)提供服務層級的記錄功能。[Amazon VPC 流程日誌](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html) 可讓您擷在網路介面取傳入和傳出之 IP 流量的相關資訊，可提供關於連線歷史記錄的寶貴洞見，並能根據異常行為觸發自動動作。

對於不是源自 AWS 服務的Amazon Elastic Compute Cloud (Amazon EC2) 執行個體和應用程式日誌記錄，可以使用 [Amazon CloudWatch Logs](http://aws.amazon.com/cloudwatch)存放和分析日誌。代理 [程式](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_GettingStarted.html) 會從作業系統和執行中的應用程式收集日誌，並且自動存放。日誌在 CloudWatch Logs 中可用之後，您可以 [即時處理](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Subscriptions.html)，或使用 [CloudWatch Logs Insights](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html)深入分析。

對於收集和彙總日誌而言，同等重要的是從複雜架構產生的大量日誌和事件資料中，提取有意義見解的能力。如需更多詳細資訊，請參閱可靠性支柱白皮書的 *監控* 經濟實惠的 [可靠性支柱白皮書](https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/monitor-workload-resources.html) 。日誌本身可能包含視為敏感的資料，無論是當應用程式資料錯誤地進入 CloudWatch Logs 代理程式擷取的日誌檔時，或是為了日誌彙總設定跨區域記錄時，而且在於跨邊界運送特定類型的資訊有法令方面的考量。

其中一種方法是使用 AWS Lambda 函數 (在交付日誌時應事件而觸發)，在轉送到集中記錄位置 (例如 Amazon Simple Storage Service (Amazon S3) 儲存貯體) 之前篩選和修訂日誌資料。未修訂的日誌可以保留在本機儲存貯體中，直到合理時間 (由法規和法律團隊決定) 過去，屆時 Amazon S3 生命週期規則即能自動刪除。使用 [Amazon S3 Object Lock](https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lock.html)可進一步保護 Amazon S3 中的日誌，您可以使用單寫多讀 (WORM) 模型存放物件。

 **若未建立此最佳實務，暴露的風險等級為：** 高 

## 實作指引
<a name="implementation-guidance"></a>
+  啟用 AWS 服務的記錄：啟用 AWS 服務的記錄以符合您的需求。記錄功能如下：Amazon VPC 流程日誌、Elastic Load Balancing (ELB) 日誌、Amazon S3 儲存貯體日誌、CloudFront 存取日誌、Amazon Route 53 查詢日誌和 Amazon Relational Database Service (Amazon RDS) 日誌。
  +  [AWS Answers：原生 AWS 安全記錄功能 ](https://aws.amazon.com/answers/logging/aws-native-security-logging-capabilities/)
+  評估並啟用作業系統和應用程式專屬的記錄，以偵測可疑行為。 
  + [ CloudWatch Logs 入門 ](http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_GettingStarted.html)
  + [ 開發人員工具和日誌分析 ](https://aws.amazon.com/marketplace/search/results?category=4988009011)
+  將適當控制套用至日誌：日誌可能包含敏感資訊，因此只有授權使用者可以存取。考慮限制對 Amazon S3 儲存貯體和 CloudWatch Logs 日誌群組的許可。
  + [ Amazon CloudWatch 的身分驗證與存取控制 ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/auth-and-access-control-cw.html)
  +  [Amazon S3 中的身分和存取管理 ](https://docs.aws.amazon.com/AmazonS3/latest/dev/s3-access-control.html)
+  設定 [Amazon GuardDuty](https://docs.aws.amazon.com/guardduty/latest/ug/what-is-guardduty.html)：GuardDuty 是威脅偵測服務，可持續尋找惡意活動和未經授權的行為，以保護 AWS 帳戶和工作負載。使用實驗室啟用 GuardDuty 並設定電子郵件的自動提醒。
+  [在 CloudTrail 中設定自訂追蹤](http://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html)：設定軌跡可讓您儲存日誌的時間長於預設時間，以便之後分析這些日誌。
+  啟用 [AWS Config](https://docs.aws.amazon.com/config/latest/developerguide/WhatIsConfig.html)：AWS Config 提供了您的 AWS 帳戶中 AWS 資源組態的詳細檢視。檢視內容包括資源之間的關係，以及它們過去的組態，以便您了解組態和關係如何隨時間變更。
+  啟用 [AWS Security Hub CSPM](https://docs.aws.amazon.com/securityhub/latest/userguide/what-is-securityhub.html)：Security Hub CSPM 提供 AWS 安全狀態的全面檢視，並協助您檢查是否符合安全產業標準和最佳實務。Security Hub CSPM 會收集 AWS 帳戶、服務和支援的第三方合作夥伴產品的安全資料，協助您分析安全趨勢並找出優先順序最高的安全問題。

## 資源
<a name="resources"></a>

 **相關文件：** 
+ [ Amazon CloudWatch ](https://aws.amazon.com/cloudwatch/)
+  [Amazon EventBridge ](https://aws.amazon.com/eventbridge)
+ [ 入門：Amazon CloudWatch Logs ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_GettingStarted.html)
+  [安全合作夥伴解決方案：記錄與監控](https://aws.amazon.com/security/partner-solutions/#logging-monitoring) 

 **相關影片：** 
+ [ 集中監控資源組態與合規 ](https://youtu.be/kErRv4YB_T4)
+  [修補 Amazon GuardDuty 和 AWS Security Hub CSPM 發現結果 ](https://youtu.be/nyh4imv8zuk)
+ [ 雲端中的威脅管理：Amazon GuardDuty 和 AWS Security Hub CSPM](https://youtu.be/vhYsm5gq9jE)

 **相關範例：** 
+ [ 實驗室︰偵測控制的自動部署 ](https://wellarchitectedlabs.com/Security/200_Automated_Deployment_of_Detective_Controls/README.html)