

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

# 使用 Transfer Family、Amazon Cognito 和 GuardDuty 保護檔案傳輸
<a name="secure-file-transfers"></a>

*Manoj Kumar，Amazon Web Services*

## 總結
<a name="secure-file-transfers-summary"></a>

此解決方案可協助您使用 透過 SFTP 伺服器安全地傳輸檔案 AWS Transfer Family。其中包括透過 Amazon GuardDuty 功能 [Malware Protection for S3](https://docs.aws.amazon.com/guardduty/latest/ug/gdu-malware-protection-s3.html) 的自動化惡意軟體掃描功能。它專為需要安全地與外部各方交換檔案，並在處理之前驗證所有傳入檔案是否掃描惡意軟體的組織而設計。

此模式隨附的基礎設施即程式碼 (IaC) 範本可協助您部署下列項目：
+ 透過 使用 Amazon Cognito 身分驗證的安全 SFTP 伺服器 AWS Lambda
+ Amazon Simple Storage Service (Amazon S3) 儲存貯體，用於已掃描惡意軟體的上傳和傳入檔案
+ 虛擬私有雲端 (VPC) 型架構，具有跨多個可用區域的公有和私有子網路
+ 輸入和輸出流量的 IP 型存取控制，具有可設定的允許和拒絕清單
+ 透過 GuardDuty 自動化惡意軟體掃描
+ 透過 Amazon EventBridge 和 Lambda 以掃描結果為基礎的智慧型檔案路由
+ 透過 Amazon Simple Notification Service (Amazon SNS) 即時通知安全事件
+ 透過 AWS Key Management Service (AWS KMS) 加密 Amazon S3 儲存貯體和 Lambda 環境變數
+ 無需網際網路暴露即可存取的 Amazon Virtual Private Cloud (Amazon VPC) 端點
+ 透過 Amazon CloudWatch 整合進行全面記錄

## 先決條件和限制
<a name="secure-file-transfers-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+  AWS Identity and Access Management (IAM) 中執行此模式中所描述動作的許可，包括部署佈建 IAM 角色的 AWS CloudFormation 範本
+ GuardDuty，在目標帳戶中[啟用](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_settingup.html) 
+ S3 的惡意軟體防護，在目標帳戶中[啟用](https://docs.aws.amazon.com/guardduty/latest/ug/malware-protection-s3-get-started-independent.html) 
+ 服務配額可讓您在目標帳戶中建立下列項目：
  + 一個 VPC
  + 一個私有子網路
  + 一個公有子網路
  + 三個彈性 IP 地址
  + 足夠的 Lambda 並行限制
+ 安全相關通知的有效電子郵件地址
+ （選用） 您要允許或拒絕的 IP 地址或 CIDR 範圍清單
+ （選用） AWS Command Line Interface (AWS CLI)，[已安裝](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html)並[設定](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)

**限制**
+ S3 的惡意軟體防護受到配額限制，例如檔案大小上限。如需詳細資訊，請參閱《GuardDuty 文件[》中的 S3 惡意軟體防護配額](https://docs.aws.amazon.com/guardduty/latest/ug/malware-protection-s3-quotas-guardduty.html)和 [Amazon S3 功能的支援能力](https://docs.aws.amazon.com/guardduty/latest/ug/supported-s3-features-malware-protection-s3.html)。
+ 此解決方案僅使用 Amazon Cognito 使用者名稱和密碼身分驗證。此範本不支援憑證型或其他身分驗證方法。根據預設，此解決方案不會設定多重要素驗證 (MFA)。
+ 解決方案只會透過安全群組實作 IP 型存取控制。

## Architecture
<a name="secure-file-transfers-architecture"></a>

下列架構圖顯示在此模式中部署的資源。此解決方案使用 Amazon Cognito 進行使用者身分驗證和授權。 AWS Transfer Family SFTP 伺服器用於檔案上傳。檔案存放在 Amazon S3 儲存貯體中，Amazon GuardDuty 會掃描檔案是否有惡意軟體。如果偵測到惡意軟體，Amazon SNS 會傳送電子郵件通知。

![使用 GuardDuty 和 Cognito 將檔案安全地傳輸至 Amazon S3 儲存貯體。](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/39d98ebe-2844-4ccd-a497-9b796b7da5e8/images/05567010-e189-40e7-acab-74e77c4f8525.png)


該圖顯示以下工作流程：

1. 使用者連線到其中的 SFTP 伺服器端點 AWS Transfer Family。這會使用 Amazon Cognito 使用者集區啟動身分驗證程序。

1. Lambda 函數會啟動身分驗證和授權程序，並使用 Amazon Cognito 驗證使用者的登入資料。

1. Lambda 函數會傳回 `UploadBucket` Amazon S3 儲存貯體做為主目錄。使用者擔任 Transfer Family 伺服器的 IAM 角色，Lambda 函數會通知使用者他們已成功驗證。

1. 使用者將檔案上傳至 Transfer Family SFTP 伺服器。檔案會存放在 `UploadBucket` Amazon S3 儲存貯體中。

1. GuardDuty 會掃描檔案是否有惡意軟體。潛在的掃描結果為 `NO_THREATS_FOUND`、`THREATS_FOUND`、`ACCESS_DENIED`、 `UNSUPPORTED`和 `FAILED`。如需範例結果，請參閱 GuardDuty 文件中的 [S3 物件掃描結果](https://docs.aws.amazon.com/guardduty/latest/ug/monitor-with-eventbridge-s3-malware-protection.html#s3-object-scan-status-malware-protection-s3-ev)。

1. EventBridge 規則會偵測掃描結果事件。

1. EventBridge 會啟動檔案路由 Lambda 函數。

1. Lambda 函數會處理事件，並根據掃描結果篩選檔案，如下所示：
   + 具有`NO_THREATS_FOUND`掃描結果的檔案會傳送至 `CleanBucket` Amazon S3 儲存貯體。
   + 具有`THREATS_FOUND`掃描結果的檔案會傳送至 `MalwareBucket` Amazon S3 儲存貯體。
   + 具有`UNSUPPORTED`掃描結果的檔案會傳送至 `ErrorBucket` Amazon S3 儲存貯體。
   + 具有`ACCESS_DENIED`掃描結果的檔案會傳送至 `ErrorBucket` Amazon S3 儲存貯體。
   + 具有`FAILED`掃描結果的檔案會傳送至 `ErrorBucket` Amazon S3 儲存貯體。

   所有檔案都會使用 加密 AWS KMS key。

1. 如果檔案已傳送至 `MalwareBucket` Amazon S3 儲存貯體，Lambda 函數會啟動 Amazon SNS 主題。Amazon SNS 主題會將電子郵件通知傳送至您設定的電子郵件地址。

## 工具
<a name="secure-file-transfers-tools"></a>

**AWS 服務**
+ [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) 可協助您 AWS 即時監控 AWS 資源的指標，以及您在 上執行的應用程式。
+ [Amazon Cognito](https://docs.aws.amazon.com/cognito/latest/developerguide/what-is-amazon-cognito.html) 為 Web 和行動應用程式提供身分驗證、授權和使用者管理。
+ [Amazon EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html) 是一種無伺服器事件匯流排服務，可協助您將應用程式與來自各種來源的即時資料連線。例如， AWS Lambda 函數、使用 API 目的地的 HTTP 調用端點，或其他事件匯流排 AWS 帳戶。
+ [Amazon GuardDuty](https://docs.aws.amazon.com/guardduty/latest/ug/what-is-guardduty.html) 是一種持續的安全監控服務，可分析和處理日誌，以識別您 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 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) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [AWS Transfer Family](https://docs.aws.amazon.com/transfer/latest/userguide/what-is-aws-transfer-family.html) 可協助您透過 SFTP、FTPS 或 FTP 通訊協定將檔案傳入和傳出 AWS 儲存服務。
+ [Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) 可協助您在已定義的虛擬網路中啟動 AWS 資源。此虛擬網路與您在自己的資料中心中操作的傳統網路相似，且具備使用 AWS可擴展基礎設施的優勢。

**程式碼儲存庫**

此模式的程式碼可在 GitHub [AWS Transfer Family 和 GuardDuty 惡意軟體掃描解決方案](https://github.com/aws-samples/sample-secure-transfer-family-code)儲存庫中使用。

## 最佳實務
<a name="secure-file-transfers-best-practices"></a>

提供的 CloudFormation 範本旨在整合許多 AWS 最佳實務，例如 IAM 角色和政策的最低權限許可、靜態和傳輸中的加密，以及自動金鑰輪換。對於生產環境，請考慮實作下列其他建議：
+ 為 Amazon Cognito 使用者啟用 [MFA](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-mfa.html) 
+ 實作[AWS Shield](https://docs.aws.amazon.com/waf/latest/developerguide/shield-chapter.html)分散式拒絕服務 (DDoS) 保護
+ 設定 [AWS Config](https://docs.aws.amazon.com/config/latest/developerguide/WhatIsConfig.html)以進行持續合規監控
+ 實作 [AWS CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html)進行全面的 API 記錄
+ 設定 [Amazon GuardDuty](https://docs.aws.amazon.com/guardduty/latest/ug/what-is-guardduty.html) 進行惡意軟體掃描以外的威脅偵測
+ 實作 [AWS Security Hub CSPM](https://docs.aws.amazon.com/securityhub/latest/userguide/what-is-securityhub-v2.html)以進行集中式安全管理
+ 使用 [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 進行登入資料管理
+ 使用[流量鏡像](https://docs.aws.amazon.com/vpc/latest/mirroring/what-is-traffic-mirroring.html)實作網路流量監控
+ 為 Amazon S3 中的敏感資料探索和保護設定 [Amazon Macie](https://docs.aws.amazon.com/macie/latest/user/what-is-macie.html) Amazon S3
+ 實作定期安全性評估和滲透測試
+ 建立正式的事件回應計劃
+ 實作所有元件的自動化修補
+ 為管理員執行定期安全訓練
+ [AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html) 設定多帳戶安全管理

## 史詩
<a name="secure-file-transfers-epics"></a>

### 部署 資源
<a name="deploy-the-resources"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製儲存庫。 | 輸入下列命令，將 [AWS Transfer Family 和 GuardDuty 惡意軟體掃描解決方案](https://github.com/aws-samples/sample-secure-transfer-family-code)儲存庫複製到您的本機工作站：<pre>git clone https://github.com/aws-samples/sample-secure-transfer-family-code.git</pre> | 應用程式開發人員、DevOps 工程師 | 
| 建立 CloudFormation 堆疊。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/secure-file-transfers.html) | 雲端管理員、DevOps 工程師 | 

### 設定 資源
<a name="configure-the-resources"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 開啟惡意軟體保護。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/secure-file-transfers.html) | 雲端管理員、AWS 管理員 | 
| 將使用者新增至使用者集區。 | 將一或多個使用者新增至 Amazon Cognito 使用者集區。如需說明，請參閱 [Amazon Cognito 文件中的管理使用者集區中的使用者](https://docs.aws.amazon.com/cognito/latest/developerguide/managing-users.html)。 Amazon Cognito  | 雲端管理員、AWS 管理員 | 

### 測試 SFTP 伺服器
<a name="test-the-sftp-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 連線至 SFTP 伺服器端點。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/secure-file-transfers.html) | 應用程式開發人員、雲端管理員、雲端架構師、DevOps 工程師 | 

## 疑難排解
<a name="secure-file-transfers-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 使用者身分驗證失敗 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/secure-file-transfers.html)如需可協助您執行這些故障診斷步驟的 AWS CLI 命令清單，請參閱[其他資訊](#secure-file-transfers-additional)一節中的*用於故障診斷的實用命令*。 | 
| SFTP 身分驗證失敗 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/secure-file-transfers.html)如需可協助您執行這些故障診斷步驟的 AWS CLI 命令清單，請參閱[其他資訊](#secure-file-transfers-additional)一節中的*用於故障診斷的實用命令*。 | 
| 檔案上傳存取遭拒 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/secure-file-transfers.html)如需可協助您執行這些故障診斷步驟的 AWS CLI 命令清單，請參閱[其他資訊](#secure-file-transfers-additional)一節中的*用於故障診斷的實用命令*。 | 
| 無惡意軟體掃描 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/secure-file-transfers.html)如需可協助您執行這些故障診斷步驟的 AWS CLI 命令清單，請參閱[其他資訊](#secure-file-transfers-additional)區段中的*用於故障診斷的實用命令*。 | 
| Lambda 函數錯誤 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/secure-file-transfers.html)如需可協助您執行這些故障診斷步驟的 AWS CLI 命令清單，請參閱[其他資訊](#secure-file-transfers-additional)區段中的*用於故障診斷的實用命令*。 | 

## 相關資源
<a name="secure-file-transfers-resources"></a>
+ [Transfer Family Web 應用程式](https://docs.aws.amazon.com/transfer/latest/userguide/web-app.html) (Transfer Family 文件）

## 其他資訊
<a name="secure-file-transfers-additional"></a>

**用於故障診斷的實用命令**

檢查 CloudFormation 堆疊的狀態：

```
aws cloudformation describe-stacks \
  --stack-name <STACK_NAME>
```

列出 Amazon Cognito 使用者集區中的所有使用者：

```
aws cognito-idp list-users \
  --user-pool-id <USER_POOL_ID>
```

檢視 Lambda 函數的日誌：

```
aws logs describe-log-groups \
  --log-group-name-prefix /aws/lambda/
```

檢查 GuardDuty 的狀態：

```
aws guardduty list-detectors
```

檢查安全群組規則：

```
aws ec2 describe-security-groups \
  --group-ids <SECURITY_GROUP_ID> \
  --output table
```

檢查 AWS Transfer Family 伺服器的狀態：

```
aws transfer describe-server \
  --server-id <SERVER_ID>
```

列出 Amazon S3 儲存貯體中的所有檔案：

```
aws s3 ls s3://<BUCKET_NAME>/ \
  --recursive
```

檢查 EventBridge 規則的狀態：

```
aws events describe-rule \
  --name <RULE_NAME>
```