

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

# 在 Application Load Balancer 上設定交互 TLS
<a name="configuring-mtls-with-elb"></a>

若要使用交互 TLS 傳遞模式，您只需將接聽程式設定為接受來自用戶端的任何憑證。當您使用交互 TLS 傳遞時，Application Load Balancer 會使用 HTTP 標頭將整個用戶端憑證鏈傳送至目標，這可讓您在應用程式中實作對應的身分驗證和授權邏輯。如需詳細資訊，請參閱[建立 Application Load Balancer 的 HTTPS 接聽程式](create-https-listener.md)。

 當您在驗證模式下使用交互 TLS 時，Application Load Balancer 會在負載平衡器交涉 TLS 連線時，為用戶端執行 X.509 用戶端憑證驗證。

若要使用交互 TLS 驗證模式，請執行下列動作：
+ 建立新的信任存放區資源。
+ 上傳您的憑證授權機構 (CA) 套件，以及選擇性的撤銷清單。
+ 將信任存放區連接到設定為驗證用戶端憑證的接聽程式。

使用下列程序在 Application Load Balancer 上設定交互 TLS 驗證模式。

**Topics**
+ [建立信任存放區](#create-trust-store)
+ [關聯信任存放區](#associate-trust-store)
+ [取代 CA 憑證套件](#replace-ca-cert-bundle)
+ [新增憑證撤銷清單](#add-cert-revocation-list)
+ [刪除憑證撤銷清單](#delete-cert-revocation-list)
+ [刪除信任存放區](#delete-trust-store)

## 建立信任存放區
<a name="create-trust-store"></a>

如果您在建立負載平衡器或接聽程式時新增信任存放區，信任存放區會自動與新的接聽程式建立關聯。否則，您必須自行將其與接聽程式建立關聯。

**先決條件**
+ 若要建立信任存放區，您必須擁有憑證授權單位 (CA) 的憑證套件。

------
#### [ Console ]

下列範例使用 主控台的信任存放區部分建立**信任存放區**。或者，您可以在建立 HTTP 接聽程式時建立信任存放區。

**建立信任存放區**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇**信任存放**區。

1. 選擇**建立信任存放區**。

1. **信任存放區組態**

   1. 針對**信任存放區名稱**，輸入信任存放區的名稱。

   1. 對於**憑證授權機構套件**，輸入要使用的 ca 憑證套件的 Amazon S3 路徑。

   1. （選用） 使用**物件版本**來選取舊版的 ca 憑證套件。否則，會使用目前的版本。

1. （選用） 對於**撤銷**，您可以將憑證撤銷清單新增至信任存放區。

   1. 選擇**新增 CRL**，然後在 Amazon S3 中輸入憑證撤銷清單的位置。

   1. （選用） 使用**物件版本**來選取憑證撤銷清單的先前版本。否則，會使用目前的版本。

1. （選用） 展開**信任存放區標籤**，並為信任存放區輸入最多 50 個標籤。

1. 選擇**建立信任存放區**。

------
#### [ AWS CLI ]

**建立信任存放區**  
使用 [create-trust-store](https://docs.aws.amazon.com/cli/latest/reference/elbv2/create-trust-store.html) 命令。

```
aws elbv2 create-trust-store \
    --name my-trust-store \
    --ca-certificates-bundle-s3-bucket amzn-s3-demo-bucket \
    --ca-certificates-bundle-s3-key certificates/ca-bundle.pem
```

------
#### [ CloudFormation ]

**建立信任存放區**  
定義 [AWS::ElasticLoadBalancingV2::TrustStore](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-elasticloadbalancingv2-truststore.html) 類型的資源。

```
Resources:
  myTrustStore:
    Type: 'AWS::ElasticLoadBalancingV2::TrustStore'
    Properties:
      Name: my-trust-store
      CaCertificatesBundleS3Bucket: amzn-s3-demo-bucket
      CaCertificatesBundleS3Key: certificates/ca-bundle.pem
```

------

## 關聯信任存放區
<a name="associate-trust-store"></a>

建立信任存放區之後，您必須將其與接聽程式建立關聯，Application Load Balancer 才能開始使用信任存放區。您只能有一個信任存放區與每個安全接聽程式相關聯，但一個信任存放區可以與多個接聽程式相關聯。

------
#### [ Console ]

您可以建立信任存放區與現有接聽程式的關聯，如下列程序所示。或者，您可以在建立 HTTPS 接聽程式時關聯信任存放區。如需詳細資訊，請參閱[建立 HTTPS 接聽程式](create-https-listener.md)。

**建立信任存放區的關聯**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格上選擇 **Load Balancers (負載平衡器)**。

1. 選取負載平衡器。

1. 在**接聽程式和規則**索引標籤上，選擇 **Protocol：Port** 欄中的連結，以開啟安全接聽程式的詳細資訊頁面。

1. 在**安全**索引標籤上，選擇**編輯安全接聽程式設定**。

1. 如果未啟用交互 TLS，請在**用戶端憑證處理**下選取**相互身分驗證 (mTLS)**，然後選擇**使用信任存放區驗證**。

1. 針對**信任存放區**，選擇信任存放區。

1. 選擇**儲存變更**。

------
#### [ AWS CLI ]

**建立信任存放區的關聯**  
使用 [modify-listener](https://docs.aws.amazon.com/cli/latest/reference/elbv2/modify-listener.html) 命令。

```
aws elbv2 modify-listener \
    --listener-arn listener-arn \
    --mutual-authentication "Mode=verify,TrustStoreArn=trust-store-arn"
```

------
#### [ CloudFormation ]

**建立信任存放區的關聯**  
更新 [AWS::ElasticLoadBalancingV2::Listener](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-elasticloadbalancingv2-listener.html) 資源。

```
Resources:
  myHTTPSListener:
    Type: 'AWS::ElasticLoadBalancingV2::Listener'
    Properties: 
      LoadBalancerArn: !Ref myLoadBalancer
      Protocol: HTTPS
      Port: 443
      DefaultActions:
        - Type: "forward"
          TargetGroupArn: !Ref myTargetGroup
      SslPolicy: ELBSecurityPolicy-TLS13-1-2-2021-06
      Certificates: 
        - CertificateArn: certificate-arn
      MutualAuthentication:
        - Mode: verify
          TrustStoreArn: trust-store-arn
```

------

## 取代 CA 憑證套件
<a name="replace-ca-cert-bundle"></a>

CA 憑證套件是信任存放區的必要元件。這是由憑證授權單位驗證的信任根憑證和中繼憑證集合。這些經過驗證的憑證可確保用戶端信任所呈現的憑證是由負載平衡器所擁有。

信任存放區一次只能包含一個 CA 憑證套件，但您可以在建立信任存放區之後隨時取代 CA 憑證套件。

------
#### [ Console ]

**若要取代 CA 憑證套件**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇**信任存放**區。

1. 選取信任存放區。

1. 選擇**動作**、**取代 CA 套件**。

1. 在**取代 CA 套件**頁面的**憑證授權機構套件**下，輸入所需 CA 套件的 Amazon S3 位置。

1. （選用） 使用**物件版本**來選取憑證撤銷清單的先前版本。否則，會使用目前的版本。

1. 選取**取代 CA 套件**。

------
#### [ AWS CLI ]

**若要取代 CA 憑證套件**  
使用 [modify-trust-store](https://docs.aws.amazon.com/cli/latest/reference/elbv2/modify-trust-store.html) 命令。

```
aws elbv2 modify-trust-store \
    --trust-store-arn trust-store-arn \
    --ca-certificates-bundle-s3-bucket amzn-s3-demo-bucket-new \
    --ca-certificates-bundle-s3-key certificates/new-ca-bundle-pem
```

------
#### [ CloudFormation ]

**更新 CA 憑證套件**  
定義 [AWS::ElasticLoadBalancingV2::TrustStore](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-elasticloadbalancingv2-truststore.html) 類型的資源。

```
Resources:
  myTrustStore:
    Type: 'AWS::ElasticLoadBalancingV2::TrustStore'
    Properties:
      Name: my-trust-store
      CaCertificatesBundleS3Bucket: amzn-s3-demo-bucket-new
      CaCertificatesBundleS3Key: certificates/new-ca-bundle.pem
```

------

## 新增憑證撤銷清單
<a name="add-cert-revocation-list"></a>

或者，您可以為信任存放區建立憑證撤銷清單。撤銷清單由憑證授權單位發佈，並包含已撤銷憑證的資料。Application Load Balancer 僅支援 PEM 格式的憑證撤銷清單。

當憑證撤銷清單新增至信任存放區時，會為其提供撤銷 ID。新增至信任存放區的每個撤銷清單的撤銷 IDs都會增加，而且無法變更。

Application Load Balancer 無法撤銷憑證撤銷清單中序號為負的憑證。

------
#### [ Console ]

**新增撤銷清單**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇**信任存放**區。

1. 選取信任存放區以檢視其詳細資訊頁面。

1. 在**憑證撤銷清單**索引標籤上，選取**動作**、**新增撤銷清單**。

1. 在**新增撤銷清單**頁面的**憑證撤銷清單**下，輸入所需憑證撤銷清單的 Amazon S3 位置

1. （選用） 使用**物件版本**來選取憑證撤銷清單的先前版本。否則會使用目前的版本。

1. 選取**新增撤銷清單**

------
#### [ AWS CLI ]

**新增撤銷清單**  
使用 [add-trust-store-revocations](https://docs.aws.amazon.com/cli/latest/reference/elbv2/add-trust-store-revocations.html) 命令。

```
aws elbv2 add-trust-store-revocations \
    --trust-store-arn trust-store-arn \
    --revocation-contents "S3Bucket=amzn-s3-demo-bucket,S3Key=crl/revoked-list.crl,RevocationType=CRL"
```

------
#### [ CloudFormation ]

**新增撤銷清單**  
定義 [AWS::ElasticLoadBalancingV2::TrustStoreRevocation](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-elasticloadbalancingv2-truststorerevocation.html) 類型的資源。

```
Resources:
  myRevocationContents:
    Type: 'AWS:ElasticLoadBalancingV2::TrustStoreRevocation'
    Properties:
      TrustStoreArn: !Ref myTrustStore
      RevocationContents:
        - RevocationType: CRL
          S3Bucket: amzn-s3-demo-bucket
          S3Key: crl/revoked-list.crl
```

------

## 刪除憑證撤銷清單
<a name="delete-cert-revocation-list"></a>

當您不再需要憑證撤銷清單時，您可以將其刪除。當您從信任存放區刪除憑證撤銷清單時，也會刪除其撤銷 ID，並且在信任存放區的生命週期內不會重複使用。

------
#### [ Console ]

**刪除撤銷清單**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇**信任存放區**。

1. 選取信任存放區。

1. 在**憑證撤銷清單**索引標籤上，選擇**動作**、**刪除撤銷清單**。

1. 出現確認提示時，請按一下 **confirm**。

1. 選擇 **刪除**。

------
#### [ AWS CLI ]

**刪除撤銷清單**  
使用 [remove-trust-store-revocations](https://docs.aws.amazon.com/cli/latest/reference/elbv2/remove-trust-store-revocations.html) 命令。

```
aws elbv2 remove-trust-store-revocations \
    --trust-store-arn trust-store-arn \
    --revocation-ids id-1 id-2 id-3
```

------

## 刪除信任存放區
<a name="delete-trust-store"></a>

當您不再為信任存放區使用 時，您可以將其刪除。您無法刪除與接聽程式相關聯的信任存放區。

------
#### [ Console ]

**刪除信任存放區**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇**信任存放**區。

1. 選取信任存放區。

1. 選擇 **刪除**。

1. 出現確認提示時，請輸入 `confirm`，然後選擇 **Delete** (刪除)。

------
#### [ AWS CLI ]

**刪除信任存放區**  
使用 [delete-trust-store](https://docs.aws.amazon.com/cli/latest/reference/elbv2/delete-trust-store.html) 命令。

```
aws elbv2 delete-trust-store \
    --trust-store-arn trust-store-arn
```

------