bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 17쪽
y exactly one key. The `backend` field selects the custodian, and the remaining fields depend on it; fields belonging to other backends are ignored.
Fields shared by every backend:
| Field | Type | Required | Description |
| - | - | - | - |
| `chain_ids` | list of strings | yes | Chains this key signs for. Each must match a declared `chains[].id`. |
| `backend` | string | no | `file` (default), `pkcs11`, or `awskms`. |
| `algorithm` | string | yes | Key algorithm: `ed25519`, `secp256k1`, `secp256k1eth`, or `mldsa65`. Set it explicitly. |
| `key_id` | string | per backend | For `pkcs11`: hex `CKA_ID` of the key object. For `awskms`: KMS key ID, ARN, or `alias/<name>`. |
Consensus signing supports `ed25519`, `secp256k1eth`, and `mldsa65` on every backend, and `secp256k1` on the AWS KMS backend only. The algorithm name `mldsa65` has no underscores; the chain-side key type `ml_dsa_65` does.
### backend: file
A key read from disk into memory. Development and testing only; the key is held in plaintext.
| Field | Type | Required | Description |
| - | - | - | - |
| `key_file` | string | yes | Path to the key. Accepts a CometBFT `priv_validator_key.json`, or a raw private key file (base64-encoded for `ed25519` and `mldsa65`, hex-encoded for `secp256k1eth`). |
### backend: pkcs11
A key on a PKCS#11 token or HSM. Signing happens on-device; the signer uses an existing key and never generates or imports one.
| Field | Type | Required | Description |
| - | - | - | - |
| `module` | string | yes | Path to the PKCS#11 module shared library. |
| `token_label` | string | exactly one of the two | `CKA_LABEL` of the token. |
| `slot` | integer | exactly one of the two | Slot number of the token. |
| `key_label` | string | at least one of `key_label`/`key_id` | `CKA_LABEL` of the key object. |
| `pin` | string | exactly one PIN source | User PIN, inline. Prefer the alternatives below. |
| `pin_env` | string | exactly one PIN source | Environment variable holding the PIN. |
| `pin_file` | string | exactly one PIN source | Path to a file holding the PIN. |
### backend: awskms
A key held in AWS KMS. Signing happens through the KMS Sign API; credentials resolve through the AWS default credential chain, and no secret material appears in the config.
| Field | Type | Required | Description |
| - | - | - | - |
| `region` | string | no | AWS region of the key. Falls back to the AWS default chain. |
| `profile` | string | no | Shared-config profile name. Falls back to the AWS default chain. |
| `endpoint` | string | no | Custom KMS endpoint URL, for LocalStack-style testing. Leave unset for AWS. |
## grpc
Optional. When present, the signer also serves the SignerService gRPC API alongside privval. Its usage documentation ships with the interoperability release; the fields are listed here for completeness.
| Field | Type | Required | Description |
| - | - | - | - |
| `listen` | string | yes | `host:port` the gRPC server binds to. |
| `tls_cert` | string | no | TLS server certificate file. Omitting both TLS fields serves plaintext, for local testing only. |
| `tls_key` | string | no | TLS server private key file. |
| `keys` | list | yes | The keys the service exposes; see below. |
Each `grpc.keys` entry:
| Field | Type | Required | Description |
| - | - | - | - |
| `id` | string | yes | Logical key identifier returned to clients. |
| `backend` | string | yes | `file`, `awskms`, or `pkcs11`. |
| `algorithm` | string | yes | For `file` and `pkcs11`: `ed25519` or `secp256k1eth`. For `awskms`: `ed25519`, `secp256k1`, or `secp256k1eth`. `mldsa65` has no gRPC signature scheme and is privval-only. |
| `key_id` | string | awskms | KMS key ID, ARN, or `alias/<name>`. |
| `key_file` | string | file | Path to the key. Accepts a CometBFT `priv_validator_key.json`, or a raw private key file (base64-encoded for `ed25519`, hex-encoded for `secp256k1eth`). |
A `grpc.keys` entry with `backend: pkcs11` also takes the PKCS#11 fields, with the same rules and the same validation as a privval key. See [backend: pkcs11](#backend-pkcs11) for `module`, `token_label`, `slot`, `key_label`, `key_id`, and the PIN sources.
<Warning>The gRPC server performs no caller authentication or authorization. Any client that can reach the listener can use every configured key. Restrict access with TLS and network controls.</Warning>
## Constraints checked at startup
* Every `validators[].chain_id` and every entry in `keys[].chain_ids` must match a declared `chains[].id`.
* Each chain must be backed by exactly one key.
* PKCS#11 keys must select the token with exactly one of `token_label` or `slot`, select the key with `key_label` or `key_id`, and supply exactly one PIN source.
* A declared chain with no `validators` entry is not rejected. The signer starts, binds nothing, and signs nothing, with no warning, so check that every chain has a validator entry.
* Every chain's sign-state file must exist and be non-empty. A missing or empty file fails closed with `sign-state file <path> is missing or empty; refusing to start at height 0`, so the signer cannot re-sign a height it has no record of. See [First start on a new chain](#first-start-on-a-new-chain).
This list is not exhaustive. Config-level rejections are prefixed `config:` and name the field at fault; errors raised later, when a backend or chain signer is opened, use their own prefixes such as `app:` or `file:`.
## First start on a new chain
A key that has never signed on a chain has no sign-state file, so the checks above block its first start. Write the height-0 floor with:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
kms start --home <home> --allow-fresh-state <chain-id>
```
`kms state init` writes a floor too, but it loads and validates `kms.yaml` first, so it only works once the chain is declared and the config is complete. It also defaults `--step` to 3, which refuses everything at that height and round, where `--allow-fresh-state` writes step 0. Pass `--step 0` to match. See [Migrate from TMKMS](/sdk/latest/kms/migrate-from-tmkms) for more details.
<Warning>Pass `--allow-fresh-state` only for a chain the key has genuinely never signed on. It will not overwrite an existing floor, but a service definition that carries it permanently removes the protection: a deleted or truncated state file resets the double-sign floor to zero instead of stopping the signer.</Warning>
## Next steps
* Task-shaped backend setup. See [Configure a signing backend](/sdk/latest/kms/configure-backend).
* First-time setup end to end. See [Remote signing tutorial](/sdk/latest/kms/tutorial-file-backend).
# Configure a signing backend
Source: https://docs.cosmos.network/sdk/latest/kms/configure-backend
Point Cosmos-KMS at the custodian holding the consensus key: AWS KMS, a PKCS#11 HSM, or a file.
A signing backend is the custodian that holds the validator's consensus key and signs with it. Cosmos-KMS supports three: AWS KMS, a PKCS#11 hardware module, and a file on disk. The `keys` block in `kms.yaml` selects one, and this guide configures each in turn.
## Prerequisites
* A running signer and node, which [Remote signing tutorial](/sdk/latest/kms/tutorial-file-backend) sets up. Between backends only the `keys` block changes in `kms.yaml`. The file backend reuses the tutorial's existing key, but the AWS KMS and PKCS#11 backends hold a new consensus key the validator must adopt first. See [Adopt the key on a validator](#adopt-the-key-on-a-validator).
* Per backend: the [AWS CLI](https://aws.amazon.com/cli/) and an AWS account for AWS KMS; your HSM's tooling plus [OpenSC](https://github.com/OpenSC/OpenSC)'s `pkcs11-tool` for PKCS#11, with [SoftHSM2](https://www.opendnssec.org/softhsm/) as a local test rig.
* The chain's binary; the examples use `simd`. To build it and run a node, see [Run a node](/sdk/latest/node/run-node).
The `algorithm` field is required for all backends.
## AWS KMS
<Warning>AWS KMS caps messages it signs in raw form at 4096 bytes. This binds `ed25519` and `secp256k1`, which send the raw consensus message, so be careful with features that enlarge it, such as vote extensions. The signer checks the size itself and fails before calling AWS. `mldsa65` and `secp256k1eth` are not bound by the cap.</Warning>
AWS Key Management Service (KMS) is a managed service that stores cryptographic keys and signs with them on request. With this backend, the consensus key lives in KMS and never leaves it. The signer calls the KMS Sign API to produce each signature. Credentials come from the standard AWS default chain: environment, shared config, SSO, or an IAM role. No secrets enter `kms.yaml`.
This backend signs with any key type Cosmos-KMS supports: `ed25519`, `secp256k1`, `secp256k1eth`, and post-quantum `mldsa65`. Provision the AWS key with the key spec that matches the algorithm, such as `ECC_NIST_EDWARDS25519` for `ed25519` or `ML_DSA_65` for `mldsa65`.
Create an ML-DSA-65 signing key and give it an alias (or skip these and point `key_id` at a key you already have):
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
aws kms create-key --key-spec ML_DSA_65 --key-usage SIGN_VERIFY
```
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
aws kms create-alias --alias-name alias/validator --target-key-id <key-id>
```
Then bind it in the `keys` block:
```yaml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
keys:
- chain_ids: [my-chain-1]
backend: awskms
algorithm: mldsa65
key_id: alias/validator
region: us-east-1
```
The `key_id` accepts a key ID, a full ARN, or an alias. `region` is optional and falls back to the AWS default chain. Two more optional fields, not shown above, are `profile` (a named shared-config profile) and `endpoint` (for LocalStack-style testing only).
The signer needs only two IAM permissions on the key: `kms:GetPublicKey`, called once at startup, and `kms:Sign`, called per block. `kms:DescribeKey` is not required. Attach a least-privilege policy scoped to the key ARN, not the alias; AWS resolves the alias to the key server-side:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["kms:GetPublicKey", "kms:Sign"],
"Resource": "arn:aws:kms:<region>:<account-id>:key/<key-id>"
}
]
}
```
A freshly created KMS key is a new consensus key. To move an existing validator onto it, rotate the validator to the new key; to stand up a new validator, register it with the new key's public key. See [Rotate a consensus key held in Cosmos-KMS](/sdk/latest/kms/rotate-key-remote-signer). Creating the key inside KMS keeps it from ever leaving the service.
## `PKCS#11`
The `PKCS#11` backend keeps the consensus key on a hardware security module (HSM) or token and signs on the device through `PKCS#11`, the standard interface for cryptographic hardware. The key never leaves the module. The signer uses an existing key only, so provision one with your HSM tooling first. The example commands below show how to provision an ed25519 key with SoftHSM2 for testing:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
softhsm2-util --init-token --free --label validator-token --pin 1234 --so-pin 4321
```
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --login --pin 1234 --keypairgen --key-type EC:edwards25519 --label validator --id 01
```
The `--module` path is platform-specific: Linux uses `/usr/lib/softhsm/libsofthsm2.so`, and macOS Homebrew uses `/opt/homebrew/lib/softhsm/libsofthsm2.so` (`/usr/local/lib/softhsm/...` on Intel). Use the same path for the `module` field below.
Then bind it:
```yaml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
keys:
- chain_ids: [my-chain-1]
backend: pkcs11
algorithm: ed25519
module: /usr/lib/softhsm/libsofthsm2.so
token_label: validator-token
key_label: validator
pin_env: KMS_PIN
```
The signer enforces three field rules at startup:
* Select the token with exactly one of `token_label` or `slot`.
* Select the key with `key_label`, `key_id` (the hex `CKA_ID`), or both.
* Supply the PIN through exactly one of `pin`, `pin_env`, or `pin_file`.
Prefer `pin_env` or `pin_file`. An inline `pin` puts the PIN in the config file.
Set the PIN in the environment the signer runs in so it matches `pin_env`: `export KMS_PIN=<pin>`. If you are using SoftHSM2 as the test rig, also `export SOFTHSM2_CONF=<path-to-softhsm2.conf>` so the module can find the token.
As with AWS KMS, a key generated in the HSM is a new consensus key. Move an existing validator onto it by rotation, or register a new validator with its public key. See [Rotate a consensus key held in Cosmos-KMS](/sdk/latest/kms/rotate-key-remote-signer).
## File
The file backend reads the consensus key from a file on the signer's disk into memory. It is the development and testing backend. The key sits in plaintext, so it is not production custody. The [Remote signing tutorial](/sdk/latest/kms/tutorial-file-backend) covers it end to end:
```yaml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
keys:
- chain_ids: [my-chain-1]
backend: file
algorithm: ed25519
key_file: priv_validator_key.json
```
The `key_file` accepts a CometBFT `priv_validator_key.json` or a raw base64-encoded private key. The file backend also signs post-quantum consensus keys. Generate the key with `simd init <moniker> --consensus-key-algo ml_dsa_65` and bind it:
```yaml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
keys:
- chain_ids: [my-chain-1]
backend: file
algorithm: mldsa65
key_file: priv_validator_key.json
```
## Adopt the key on a validator
The AWS KMS and PKCS#11 backends generate the key inside the custodian, so it is a new consensus key, not the one your validator already runs. Do not just repoint an existing validator's signer at a fresh key. The node finds its consensus key absent from the validator set and demotes itself, so it never proposes and there is no signature error to look for. The symptom is `This node is not a validator` in the node log and a chain that does not advance. Only the file backend, pointed at the validator's existing `priv_validator_key.json`, skips this step.
Adopt the key one of two ways:
* Existing validator: rotate its consensus key to the new one, which derives the new public key from a shadow node and swaps it in with no downtime. See [Rotate a consensus key held in Cosmos-KMS](/sdk/latest/kms/rotate-key-remote-signer).
* New validator: register it with the new key's consensus public key using `gentx --pubkey` (or the `pubkey` field of `create-validator`'s validator.json). Read the public key from the custodian itself, since `gentx` runs before the chain exists and there is no node to query. For PKCS#11, read the object and strip the DER wrapper, leaving the raw 32 bytes to base64:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
pkcs11-tool --module <module> --login --pin <pin> --read-object --type pubkey --label validator \
| xxd -p | tr -d '\n' | sed 's/^302a300506032b6570032100//' | xxd -r -p | base64
```
For AWS KMS, `aws kms get-public-key` returns a DER `SubjectPublicKeyInfo`; strip the same wrapper before encoding.
## Verify any backend
Verification is the same regardless of custodian. Start the signer, start the node, and confirm blocks flow, exactly as in [the tutorial](/sdk/latest/kms/tutorial-file-backend).
If this key has never signed on the chain, the signer's first start needs `--allow-fresh-state <chain-id>` to write the height-0 double-sign floor, otherwise it exits with `sign-state file ... is missing or empty; refusing to start at height 0`. Pass it only on that first start. See [Start the signer](/sdk/latest/kms/tutorial-file-backend) in the tutorial for the full explanation, and the [configuration reference](/sdk/latest/kms/configuration-reference) for `kms state init`.
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
curl -s localhost:26657/status | jq '.result.sync_info.latest_block_height'
```
## What can go wrong
* The signer rejects the config at startup: both `token_label` and `slot` set, or more than one PIN source. The error names the offending field. A missing `algorithm` on the file backend instead fails with the less specific `file: unknown key type`.
* The signer starts but cannot reach the key: wrong `module` path, wrong `key_id` or alias, or AWS credentials with no permission (denied `kms:GetPublicKey` fails at `kms start` with `awskms: get public key for "<key_id>": <AccessDeniedException>`). These also fail at startup.
* The node exits with a pubkey timeout: the signer is not running or not reachable. Start the signer first. It dials and retries.
## Next steps
* Look up any config field, its type, and its constraints. See the [configuration reference](/sdk/latest/kms/configuration-reference).
* Run the whole flow once with the file backend. See [Remote signing tutorial](/sdk/latest/kms/tutorial-file-backend).
* Move an existing validator onto a key in a new backend by rotation. See [Rotate a consensus key held in Cosmos-KMS](/sdk/latest/kms/rotate-key-remote-signer).
# Migrate from TMKMS
Source: https://docs.cosmos.network/sdk/latest/kms/migrate-from-tmkms
Move a validator from TMKMS to Cosmos-KMS: translate the config, move or rotate the key, and cut over without double signing.
This guide moves a validator's signing from TMKMS to Cosmos-KMS, the recommended remote signer going forward. Cosmos-KMS includes several upgrades over TMKMS: it adds AWS KMS and PKCS#11 backends and post-quantum ML-DSA signing. The migration translates the config, gets the key into a Cosmos-KMS backend, and cuts over with exactly one signer alive at every moment. For what Cosmos-KMS is and how it relates to TMKMS, see [Cosmos-KMS and remote signing](/sdk/latest/kms/remote-signing).
The validator node itself needs no changes: both signers speak the same privval protocol to the same `priv_validator_laddr` listener. TMKMS connects over CometBFT's SecretConnection, and the Cosmos-KMS `tcp://` transport is the same, so the listener works unchanged.
## Prerequisites
* A validator currently signing through TMKMS, with access to its `tmkms.toml` and state file.
* [jq](https://jqlang.org/), used to translate the state file in step 4.
* Cosmos-KMS installed and initialized with `kms init`. [Remote signing tutorial](/sdk/latest/kms/tutorial-file-backend) covers installation, which needs [Go](https://go.dev/doc/install) 1.26 or later, [make](https://www.gnu.org/software/make/), and [git](https://git-scm.com/).
## 1. Translate the config
Create `kms.yaml` and translate each block from your `tmkms.toml`:
| tmkms.toml | kms.yaml | Notes |
| - | - | - |
| `[[chain]]` `id` | `chains[].id` | Same value. |
| `[[chain]]` `state_file` | `chains[].state_file` | See [step 4](#4-translate-the-double-sign-state) before reusing a path. |
| `[[chain]]` `key_format` | none | Not needed; Cosmos-KMS has no per-chain serialization config. |
| `[[validator]]` `addr` | `validators[].addr` | Drop the `<node-id>@` prefix; `tcp://host:port` uses CometBFT's SecretConnection, matching TMKMS. For a node running libp2p, use `noise://<validator-peer-id>@<ip>:<port>` instead, where the peer ID is the validator's, from `cometbft show-node-id --libp2p`. A `noise://` host must be an IP literal, bracketed for IPv6; hostnames are rejected. Noise is mutual, so the validator must also carry the signer's peer ID, from `kms peer-id`, in its 프로젝트로 돌아가기