

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

# AWS CloudHSM 用戶端 SDK 5 金鑰複寫失敗
<a name="troubleshoot-sdk5-key-replicate-failures"></a>

CloudHSM CLI 中的 `key replicate`命令會將金鑰從來源 AWS CloudHSM 叢集複寫到目的地 AWS CloudHSM 叢集。本指南解決來源叢集內或來源和目的地叢集之間不一致所造成的故障。

## 問題：選取的金鑰不會在整個叢集中同步
<a name="troubleshoot-sdk5-key-replicate-failures-desynch"></a>

金鑰複寫程序會檢查整個來源叢集的金鑰同步。如果任何金鑰資訊或屬性的值為「不一致」，這表示金鑰不會跨叢集同步。金鑰複寫失敗，並顯示下列錯誤訊息：

```
{
  "error_code": 1,
  "data": "The selected key is not synchronized throughout the cluster"
}
```

若要檢查來源叢集中的金鑰非同步：

1. 在 CloudHSM CLI 中執行 `key list`命令。

1. 使用 `--filter `旗標指定 金鑰。

1. 新增 `--verbose`旗標，以查看包含金鑰涵蓋範圍資訊的完整輸出。

```
aws-cloudhsm > key list --filter attr.label=example-desynchronized-key-label --verbose
{
  "error_code": 0,
  "data": {
    "matched_keys": [
      {
        "key-reference": "0x000000000048000f",
        "key-info": {
          "key-owners": [
            {
              "username": "cu1",
              "key-coverage": "full"
            }
          ],
          "shared-users": [],
        "key-quorum-values": {
          "manage-key-quorum-value": 0,
          "use-key-quorum-value": 0
        },
          "cluster-coverage": "full"
        },
        "attributes": {
          "key-type": "aes",
          "label": "example-desynchronized-key-label",
          "id": "0x",
          "check-value": "0xbe79db",
          "class": "secret-key",
          "encrypt": false,
          "decrypt": false,
          "token": true,
          "always-sensitive": true,
          "derive": false,
          "destroyable": true,
          "extractable": true,
          "local": true,
          "modifiable": true,
          "never-extractable": false,
          "private": true,
          "sensitive": true,
          "sign": "inconsistent",
          "trusted": false,
          "unwrap": false,
          "verify": true,
          "wrap": false,
          "wrap-with-trusted": false,
          "key-length-bytes": 16
        }
      }
    ],
    "total_key_count": 1,
    "returned_key_count": 1
  }
}
```

**解決方案：同步整個來源叢集的金鑰資訊和屬性**

若要同步整個來源叢集的金鑰資訊和屬性：

1.  對於不一致的金鑰屬性：使用 `key set-attribute`命令來設定特定金鑰所需的屬性。

1.  對於不一致的共用使用者涵蓋範圍：使用 `key share`或 `key unshare`命令來調整與所需使用者的金鑰共用。

## 問題：具有不同資訊或屬性的目的地叢集中存在具有相同參考的金鑰
<a name="troubleshoot-sdk5-key-replicate-failures-ref-attribs"></a>

 如果具有相同參考的金鑰存在於目的地叢集中，但具有不同的資訊或屬性，則可能會發生下列錯誤：

```
{
  "error_code": 1,
  "data": "Key replicate failed on 1 of 3 connections"
}
```

**Resolution**

1. 決定應保留的金鑰版本。

1. 使用適當叢集中的 `key delete`命令刪除不需要的金鑰版本。

1. 從具有正確版本的叢集複寫金鑰。