

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

# 監控 IAM 根使用者活動
<a name="monitor-iam-root-user-activity"></a>

*JJ Sung 和 Mostefa Brougui，Amazon Web Services*

## 總結
<a name="monitor-iam-root-user-activity-summary"></a>

每個 Amazon Web Services (AWS) 帳戶都有根使用者。作為 AWS Identity and Access Management (IAM) [的安全最佳實務](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)，我們建議您使用根使用者來完成只有根使用者可以執行的任務。如需完整清單，請參閱《*AWS 帳戶管理參考指南*》中的[需要根使用者憑證的任務](https://docs.aws.amazon.com/accounts/latest/reference/root-user-tasks.html)。由於根使用者可以完整存取您的所有 AWS 資源和帳單資訊，因此建議您不要使用此帳戶並監控任何活動，這可能表示根使用者憑證已遭到入侵。

使用此模式，您可以設定監控 IAM 根使用者[的事件驅動架構](https://aws.amazon.com/event-driven-architecture/)。此模式會設定中hub-and-spoke解決方案，以監控多個 AWS 帳戶、*輻條*帳戶，並將管理和報告集中在中*樞*帳戶單一帳戶中。

使用 IAM 根使用者憑證時，Amazon CloudWatch 和 AWS CloudTrail 會分別在日誌和追蹤中記錄活動。在輪輻帳戶中，Amazon EventBridge 規則會將事件傳送至中樞帳戶中的中央[事件匯流排](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-bus.html)。在中樞帳戶中，EventBridge 規則會將事件傳送至 AWS Lambda 函數。函數使用 Amazon Simple Notification Service (Amazon SNS) 主題來通知您根使用者活動。

在此模式中，您會使用 AWS CloudFormation 範本在輪輻帳戶中部署監控和事件處理服務。您可以使用 HashiCorp Terraform 範本，在中樞帳戶中部署事件管理和通知服務。

## 先決條件和限制
<a name="monitor-iam-root-user-activity-prereqs"></a>

**先決條件**

1. 在 AWS 環境中部署 AWS 資源的許可。

1. 部署 CloudFormation 堆疊集的許可。如需詳細資訊，請參閱[堆疊集操作的先決條件 ](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-prereqs.html)(CloudFormation 文件）。

1. 安裝 Terraform 並準備好使用。如需詳細資訊，請參閱[入門 – AWS](https://learn.hashicorp.com/collections/terraform/aws-get-started) (Terraform 文件）。

1. 每個輻條帳戶中的現有線索。如需詳細資訊，請參閱 [AWS CloudTrail 入門](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-tutorial.html) (CloudTrail 文件）。

1. 線索已設定為將事件傳送至 CloudWatch Logs。如需詳細資訊，請參閱[將事件傳送至 CloudWatch Logs](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/send-cloudtrail-events-to-cloudwatch-logs.html) (CloudTrail 文件）。

1. 您的中樞和輻條帳戶必須由 AWS Organizations 管理。

## Architecture
<a name="monitor-iam-root-user-activity-architecture"></a>

下圖說明實作的建置區塊。

![在中樞帳戶中建立電子郵件通知的發言帳戶中的事件](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/175f356b-f9df-4d33-82fc-fe33b2c88b05/images/6147e5b5-616e-49a4-b330-dbb7e3381fe7.png)


1. 使用 IAM 根使用者憑證時，CloudWatch 和 CloudTrail 會分別在日誌和追蹤中記錄活動。

1. 在輪輻帳戶中，EventBridge 規則會將事件傳送至中樞帳戶中的中央[事件匯流排](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-bus.html)。

1. 在中樞帳戶中，EventBridge 規則會將事件傳送至 Lambda 函數。

1. Lambda 函數使用 Amazon SNS 主題，通知您根使用者活動。

## 工具
<a name="monitor-iam-root-user-activity-tools"></a>

**AWS 服務**
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可協助您設定 AWS 資源、快速且一致地佈建資源，以及在整個 AWS 帳戶和區域的生命週期進行管理。
+ [AWS CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html) 可協助您稽核 AWS 帳戶的控管、合規和營運風險。
+ [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) 可協助您集中所有系統、應用程式和 AWS 服務的日誌，以便您可以監控日誌並將其安全地存檔。
+ [Amazon EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html) 是一種無伺服器事件匯流排服務，可協助您將應用程式與來自各種來源的即時資料連線。例如，AWS Lambda 函數、使用 API 目的地的 HTTP 調用端點，或其他 AWS 帳戶中的事件匯流排。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一種運算服務，可協助您執行程式碼，而無需佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需支付使用的運算時間。
+ [Amazon Simple Notification Service (Amazon SNS)](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) 可協助您協調和管理發佈者和用戶端之間的訊息交換，包括 Web 伺服器和電子郵件地址。

**其他工具和服務**
+ [Terraform](https://www.terraform.io/docs) 是一種 CLI 應用程式，可透過使用組態檔案形式的程式碼來佈建和管理雲端基礎設施和資源。

**程式碼儲存庫**

此模式的原始程式碼和範本可在 [GitHub 儲存庫](https://github.com/aws-samples/aws-iam-root-user-activity-monitor)中使用。此模式提供兩種範本：
+ 包含您在中樞帳戶中部署之資源的 Terraform 範本
+ 您在輪輻帳戶中部署為堆疊集執行個體的 CloudFormation 範本

儲存庫的整體結構如下。

```
.
 |__README.md
 |__spoke-stackset.yaml
 |__hub.tf
 |__root-activity-monitor-module
     |__main.tf  # contains Terraform code to deploy resources in the Hub account
     |__iam      # contains IAM policies JSON files
         |__ lambda-assume-policy.json          # contains trust policy of the IAM role used by the Lambda function
         |__ lambda-policy.json                 # contains the IAM policy attached to the IAM role used by the Lambda function
     |__outputs  # contains Lambda function zip code
```

*Epics* 區段提供部署範本的step-by-step說明。

## 史詩
<a name="monitor-iam-root-user-activity-epics"></a>

### 將資源部署至中樞帳戶
<a name="deploy-resources-to-the-hub-account"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製範本程式碼儲存庫。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-iam-root-user-activity.html) | 一般 AWS | 
| 更新 Terraform 範本。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-iam-root-user-activity.html) | 一般 AWS | 
| 將資源部署至 AWS 中樞帳戶。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-iam-root-user-activity.html) | 一般 AWS | 

### 將資源部署到您的發言帳戶
<a name="deploy-resources-to-your-spoke-accounts"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 部署 CloudFormation 範本。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-iam-root-user-activity.html)如需詳細資訊和說明，請參閱[建立堆疊集](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-getting-started-create.html) (CloudFormation 文件）。 | 一般 AWS | 

### （選用） 測試通知
<a name="optional-test-the-notifications"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用根使用者憑證。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-iam-root-user-activity.html) | 一般 AWS | 

## 相關資源
<a name="monitor-iam-root-user-activity-resources"></a>
+ [安全最佳實務 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)(IAM 文件）
+ [使用 StackSets](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/what-is-cfnstacksets.html) (CloudFormation 文件）
+ [入門 ](https://learn.hashicorp.com/collections/terraform/aws-get-started)(Terraform 文件）

## 其他資訊
<a name="monitor-iam-root-user-activity-additional"></a>

[Amazon GuardDuty](https://docs.aws.amazon.com/guardduty/latest/ug/what-is-guardduty.html) 是一項持續的安全監控服務，可分析和處理日誌，以識別 AWS 環境中未預期和可能未經授權的活動。作為此解決方案的替代方案，如果您已啟用 GuardDuty，則可以在使用根使用者憑證時提醒您。GuardDuty 調查結果為 `Policy:IAMUser/RootCredentialUsage`，預設嚴重性為**低**。如需詳細資訊，請參閱[管理 Amazon GuardDuty 調查結果](https://docs.aws.amazon.com/guardduty/latest/ug/findings_management.html)。