

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

# 安全組態和 IAM 角色
<a name="dotnet-migrating-applications-security"></a>

**eb migrate** 命令會透過 IAM 角色、執行個體描述檔和服務角色來管理 AWS 安全組態。了解這些元件可確保遷移期間適當的存取控制和安全性合規。

## 執行個體描述檔組態
<a name="dotnet-migrating-applications-security-instance"></a>

執行個體描述檔做為 IAM 角色的容器，Elastic Beanstalk 會連接到您環境中的 EC2 執行個體。執行 時**eb migrate**，您可以指定自訂執行個體描述檔：

```
PS C:\migrations_workspace> eb migrate --instance-profile "CustomInstanceProfile"
```

如果您未指定執行個體描述檔， **eb migrate**會建立具有這些許可的預設描述檔：

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:GetObjectVersion",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::elasticbeanstalk-*",
                "arn:aws:s3:::elasticbeanstalk-*/*"
            ]
        }
    ]
}
```

------

## 服務角色管理
<a name="dotnet-migrating-applications-security-service"></a>

服務角色可讓 Elastic Beanstalk 代表您管理 AWS 資源。使用下列命令在遷移期間指定自訂服務角色：

```
PS C:\migrations_workspace> eb migrate --service-role "CustomServiceRole"
```

如果未指定， **eb migrate** 會使用允許 Elastic Beanstalk 擔任角色的信任政策`aws-elasticbeanstalk-service-role`建立名為 的預設服務角色。此服務角色對於 Elastic Beanstalk 監控您環境的運作狀態和執行受管平台更新至關重要。服務角色需要兩個受管政策：
+ `AWSElasticBeanstalkEnhancedHealth` - 允許 Elastic Beanstalk 使用增強型運作狀態報告系統監控執行個體和環境運作狀態
+ `AWSElasticBeanstalkManagedUpdates` - 允許 Elastic Beanstalk 執行受管平台更新，包括在有新平台版本可用時更新環境資源

透過這些政策，服務角色具有以下許可：
+ 建立和管理 Auto Scaling 群組
+ 建立和管理 Application Load Balancer
+ 將日誌上傳至 Amazon CloudWatch
+ 管理 EC2 執行個體

如需服務角色的詳細資訊，請參閱 Elastic Beanstalk 開發人員指南[Elastic Beanstalk 服務角色](concepts-roles-service.md)中的 。

## 安全群組組態
<a name="dotnet-migrating-applications-security-sg"></a>

**eb migrate** 命令會根據 IIS 網站繫結，自動設定安全群組。例如，如果您的來源環境有使用連接埠 80、443 和 8081 的網站，則下列組態結果：

```
<site name="Default Web Site">
    <bindings>
        <binding protocol="http" bindingInformation="*:80:" />
        <binding protocol="https" bindingInformation="*:443:" />
    </bindings>
</site>
<site name="InternalAPI">
    <bindings>
        <binding protocol="http" bindingInformation="*:8081:" />
    </bindings>
</site>
```

遷移程序會完成下列動作：
+ 建立負載平衡器安全群組，允許連接埠 80 和 443 從網際網路傳入流量 (0.0.0.0/0)
+ 建立 EC2 安全群組，允許來自負載平衡器的流量
+ 如果`--copy-firewall-config`指定 ，則設定其他連接埠 （例如 8081)

根據預設，Application Load Balancer 設定為從網際網路公開存取。如果您需要自訂此行為，例如限制存取特定 IP 範圍或使用私有負載平衡器，您可以使用 `--vpc-config` 參數覆寫預設 VPC 和安全群組組態：

```
PS C:\migrations_workspace> eb migrate --vpc-config vpc-config.json
```

例如，下列`vpc-config.json`組態會在私有子網路中建立私有負載平衡器：

```
{
    "id": "vpc-12345678",
    "publicip": "false",
    "elbscheme": "internal",
    "ec2subnets": ["subnet-private1", "subnet-private2"],
    "elbsubnets": ["subnet-private1", "subnet-private2"]
}
```

如需 VPC 組態選項的詳細資訊，請參閱 [VPC 組態](dotnet-migrating-applications-network.md#dotnet-migrating-applications-network-vpc)。

## SSL 憑證整合
<a name="dotnet-migrating-applications-security-ssl"></a>

使用 HTTPS 繫結遷移網站時，請透過 AWS Certificate Manager (ACM) 整合 SSL 憑證：

```
PS C:\migrations_workspace> eb migrate --ssl-certificates "arn:aws:acm:region:account:certificate/certificate-id"
```

此組態會完成下列動作：
+ 將憑證與 Application Load Balancer 建立關聯
+ 在負載平衡器維護 HTTPS 終止
+ 保留負載平衡器和 EC2 執行個體之間的內部 HTTP 通訊

## Windows 身分驗證
<a name="dotnet-migrating-applications-security-windows"></a>

對於使用 Windows 身分驗證的應用程式， 會在應用程式的 中**eb migrate**保留身分驗證設定`web.config`，如下所示：

```
<configuration>
    <system.webServer>
        <security>
            <authentication>
                <windowsAuthentication enabled="true">
                    <providers>
                        <add value="Negotiate" />
                        <add value="NTLM" />
                    </providers>
                </windowsAuthentication>
            </authentication>
        </security>
    </system.webServer>
</configuration>
```

**重要**  
**eb migrate** 命令不會透過使用者設定檔或帳戶從來源環境複製到目標 Elastic Beanstalk 執行個體。您在來源伺服器上建立的任何自訂使用者帳戶或群組，都需要在遷移後於目標環境重新建立。

預設會在目標 Windows Server 執行個體上包含內建 Windows 帳戶，例如 `IUSR`和 群組`IIS_IUSRS`，以及所有其他內建帳戶和群組。如需內建 IIS 帳戶和群組的詳細資訊，請參閱 Microsoft 文件中的[了解 IIS 中的內建使用者和群組帳戶](https://learn.microsoft.com/en-us/iis/get-started/planning-for-security/understanding-built-in-user-and-group-accounts-in-iis)。

如果您的應用程式依賴自訂 Windows 使用者帳戶或 Active Directory 整合，則需要在遷移完成後分別設定這些層面。

## 最佳實務和疑難排解
<a name="dotnet-migrating-applications-security-best"></a>

### 角色管理
<a name="dotnet-migrating-applications-security-best-role"></a>

 AWS 在管理 Elastic Beanstalk 環境的角色時實作 IAM 最佳實務：

角色建立和管理  
+ 盡可能使用 AWS 受管政策建立角色
+ 遵循 [IAM 安全最佳實務](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)
+ 將[AWS 政策產生器](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create-console.html)用於自訂政策
+ 實作額外安全性的[許可界限](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html) 

監控和稽核  
啟用 AWS CloudTrail 以監控角色用量：  
+ 遵循 [AWS CloudTrail 使用者指南](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html)
+ 設定 CloudWatch Logs 整合以進行即時監控
+ 設定未經授權的 API 呼叫提醒

定期審查程序  
建立每季審查週期來執行下列任務：  
+ 使用 [IAM Access Analyzer](https://docs.aws.amazon.com/IAM/latest/UserGuide/what-is-access-analyzer.html) 稽核未使用的許可
+ 移除過時的許可
+ 根據最低權限原則更新角色

### 憑證管理
<a name="dotnet-migrating-applications-security-best-cert"></a>

在您的 Elastic Beanstalk 環境中實作這些 SSL/TLS 憑證實務：

憑證生命週期  
+ 使用 [AWS Certificate Manager](https://docs.aws.amazon.com/acm/latest/userguide/acm-overview.html) 進行憑證管理
+ 為 ACM 發行的憑證啟用[自動續約](https://docs.aws.amazon.com/acm/latest/userguide/check-certificate-renewal-status.html) 
+ 設定[過期通知](https://docs.aws.amazon.com/acm/latest/userguide/notifications-for-ACM.html)

安全標準  
+ 使用 TLS 1.2 或更新版本
+ 遵循 HTTPS 接聽程式[AWS 的安全政策](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html#describe-ssl-policies) 
+ 視需要實作 HTTP 嚴格傳輸安全性 (HSTS)

### 安全群組管理
<a name="dotnet-migrating-applications-security-best-sg"></a>

實作這些安全群組最佳實務：

規則管理  
+ 記錄所有自訂連接埠需求
+ 使用 [VPC 流程日誌](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html)來監控流量
+ 盡可能使用[安全群組參考規則](https://docs.aws.amazon.com/vpc/latest/userguide/security-group-rules.html)，而非 IP 範圍

定期稽核  
建立每月審查以執行下列任務：  
+ 識別和移除未使用的規則
+ 驗證來源/目的地需求
+ 檢查是否有重疊的規則

### 日誌記錄和監控
<a name="dotnet-migrating-applications-security-best-logging"></a>

為了有效監控安全，請設定下列日誌：

EC2 執行個體上的 Windows 事件日誌  

```
# Review Security event log
PS C:\migrations_workspace> Get-EventLog -LogName Security -Newest 50

# Check Application event log
PS C:\migrations_workspace> Get-EventLog -LogName Application -Source "IIS*"
```

CloudWatch Logs 整合  
設定 CloudWatch Logs 代理程式將 Windows 事件日誌串流至 CloudWatch，以進行集中式監控和警示。

對於持久性問題，請收集這些日誌並聯絡 AWS 支援 並提供下列資訊：
+ 環境 ID
+ 部署 ID （如適用）
+ 相關錯誤訊息
+ 安全性變更的時間表