Cosmos Hub 백서

Cosmos Hub

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 18쪽

allowlist, or it rejects the connection. | | `[[validator]]` `chain_id` | `validators[].chain_id` | Same value. | | `[[validator]]` `secret_key` | `validators[].identity_key` | Different format; use the `identity.json` from `kms init` rather than converting. | | `[[validator]]` `protocol_version` | none | Not needed. | | `[[providers.softsign]]` | `keys[]` with `backend: file` | See [step 2](#from-softsign). | | `[[providers.yubihsm]]` | `keys[]` with `backend: pkcs11` | PKCS#11 HSM; see [step 2](#from-yubihsm-or-another-hsm). | | `[[providers.ledgertm]]` | none | Not yet supported in Cosmos-KMS; see [step 2](#from-yubihsm-or-another-hsm). | A standard cosmos-sdk node has no peer ID on its `priv_validator_laddr` listener, so there is usually no `<node-id>@` prefix to carry over, and both TMKMS and Cosmos-KMS use a bare `tcp://host:port`. Below is a complete `kms.yaml` example for a single validator on the file backend: ```yaml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} chains: - id: my-chain-1 state_file: state/my-chain-1.json validators: - chain_id: my-chain-1 addr: tcp://127.0.0.1:26659 identity_key: identity.json keys: - chain_ids: [my-chain-1] backend: file algorithm: ed25519 key_file: priv_validator_key.json ``` The `keys` block shown is the file backend. Its fields differ per backend, which step 2 covers. It also needs `keys[].algorithm`, which has no `tmkms.toml` equivalent, so set it explicitly (`ed25519` for a softsign key), as the example shows. The [configuration reference](/sdk/latest/kms/configuration-reference) lists every field. ## 2. Move the consensus key into a backend Get the consensus key into the backend named in your `keys` block. The path depends on where TMKMS holds it today. ### From softsign The softsign backend keeps the key in a file, but the format differs from what the Cosmos-KMS file backend reads. A TMKMS softsign key is the base64-encoded 32-byte ed25519 seed, while the file backend expects a CometBFT `priv_validator_key.json` or the base64-encoded 64-byte ed25519 key. Pointing `key_file` at a softsign key directly fails with `expected 64-byte ed25519 key, got 32`. If you still have the validator's original `priv_validator_key.json` (TMKMS softsign was imported from it), point `key_file` at that file directly. No conversion is needed. From only the softsign key (the file named by the `path` in your `[[providers.softsign]]` block), expand the 32-byte seed into the 64-byte `seed||pubkey` form the file backend accepts. Replace `tmkms_softsign.key` in the command with that file: ```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} python3 - tmkms_softsign.key converted.key <<'PY' import base64, sys from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat seed = base64.b64decode(open(sys.argv[1]).read().strip()) assert len(seed) == 32, f"expected 32-byte seed, got {len(seed)}" sk = Ed25519PrivateKey.from_private_bytes(seed) pub = sk.public_key().public_bytes(Encoding.Raw, PublicFormat.Raw) open(sys.argv[2], "w").write(base64.b64encode(seed + pub).decode()) PY ``` Point `key_file` at `converted.key`. The command needs Python 3 with the `cryptography` package (`pip install cryptography`). <Warning>`converted.key` and the exported softsign key are unencrypted private keys. Shred them after import (`shred -u` or `rm -P`) and keep them out of shell history and backups.</Warning> ### From YubiHSM or another HSM Most HSM-held keys do not move. A YubiHSM, a Fortanix device, or any HSM that exposes the key over PKCS#11 works with the Cosmos-KMS `pkcs11` backend directly: wire up a `keys` block against the same module and keep signing with the same key. Keys generated inside an HSM are typically non-exportable, which is the point of an HSM, so this no-move path is the normal case. For the PKCS#11 config, see [Configure a signing backend](/sdk/latest/kms/configure-backend). When you are changing custodian rather than keeping the key in place, migrate by rotation: generate a new key in the target custodian and rotate the validator to it on chain, which retires the TMKMS-held key entirely. See [Rotate a consensus key, Staking](/sdk/latest/keys/rotate-validator-key). Ledger-held consensus keys are not currently supported in Cosmos-KMS. If you need it, open a [feature request](https://github.com/cosmos/kms/issues) so demand for it can be gauged. ## 3. Stop TMKMS Stop TMKMS and confirm the process is gone. The validator misses blocks until Cosmos-KMS takes over. That gap is expected: missed blocks are recoverable, a double sign from two live signers is not. Keep it short to avoid downtime jailing. <Danger>Never run TMKMS and Cosmos-KMS at the same time against the same validator key. Each keeps its own last-signed state, so together they can sign the same height, which is a double sign. Stop one fully before starting the other, in both directions, including any rollback.</Danger> ## 4. Translate the double-sign state TMKMS and Cosmos-KMS both track the last signed height, round, and step per chain, and the protection only works if the new signer starts at or above the old signer's high-water mark. The two store this state differently, so it needs translating. Point the following command at the TMKMS state file named by `state_file` in your `[[chain]]` block (`tmkms_state.json` is a placeholder). It writes the translated state into the Cosmos-KMS location: ```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} mkdir -p <home>/state jq '{height, round: (.round|tonumber), step: (.step + 1)}' tmkms_state.json > <home>/state/<chain-id>.json ``` The `jq` expression makes two conversions: `round` from string to number (the source of the `int32` error otherwise), and `step + 1` to remap TMKMS's 0/1/2 signing steps to CometBFT's 1/2/3. <Warning>The redirection above overwrites whatever is at that path, so a re-run or a stale `tmkms_state.json` silently lowers the double-sign floor. Check the file does not already exist first.</Warning> ## 5. Start Cosmos-KMS Start Cosmos-KMS with the completed `kms.yaml`. It dials the validator and resumes signing. ```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} kms start --home <home> ``` ## 6. Confirm signing resumed Confirm the chain is producing again and the signer's state file is advancing. Run the status check twice; a climbing height means signing resumed: ```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' ``` The signer's `<home>/state/<chain-id>.json` should also advance past the last height TMKMS signed. ## What can go wrong * Both signers briefly alive: the double-sign risk above. Cut over with the old process confirmed dead, not just signaled. * The validator stays dark after cutover: the new signer is not reaching the listener. Check the `validators[].addr` translation and the firewall between the hosts. * `dial tcp: lookup node-id@host: no such host`: the `<node-id>@` prefix was left in `validators[].addr`. Drop it and keep only host and port. * `file: parse key file "<path>": expected 64-byte ed25519 key, got 32`: a TMKMS softsign key was pointed at directly. See the [key section](#from-softsign). * `chain "<chain-id>": reload sign-state: json: cannot unmarshal string into Go value of type int32`: the TMKMS state file was reused as is. Translate it first; see [step 4](#4-translate-the-double-sign-state). ## Next steps * Harden the new setup. See [Remote signing best practices](/sdk/latest/kms/best-practices). * Full field reference for the translated config. See the [configuration reference](/sdk/latest/kms/configuration-reference). # Overview Source: https://docs.cosmos.network/sdk/latest/kms/remote-signing What privval is, what Cosmos-KMS is and is not, and why validator keys belong in a KMS or HSM rather than local files. This page covers remote signing for validators and Cosmos-KMS, the Cosmos stack's remote signer. The guides in this section set both up. ## What is remote signing? Remote signing splits a validator into two processes: a node that participates in consensus, and a signer that holds the consensus key and produces signatures on the node's behalf. The node handles blocks, gossip, and peers; the signer holds the one secret that matters. Separating the two keeps signing secure and makes the node replaceable. The key moves off the node's exposed filesystem into a hardware security module (HSM) or a cloud key service, where the people and automation that maintain the node never touch it. And because the node holds no secrets, it can be rebuilt, upgraded, or replaced at will. Once it is replaced, the signer reconnects and signing continues. CometBFT supports this through privval, the seam between the node and whatever holds the key. With `priv_validator_laddr` set in `config.toml`, the node signs nothing locally: it listens for a signer connection and sends each vote and proposal out for signature. The wire protocol carries four requests: sign this vote, sign this proposal, return the public key, and a keepalive ping. The node does not necessarily care what is on the other end. ```mermaid theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} sequenceDiagram participant N as Validator node participant S as Cosmos-KMS signer participant B as Backend (file / PKCS11 / AWS KMS) N->>S: vote or proposal to sign (privval) S->>B: sign with consensus key B-->>S: signature S-->>N: signature ``` The node forwards each vote or proposal to the signer over the privval connection. The signer has its backend produce the signature and returns only that, so the consensus key never leaves the backend. ## Cosmos-KMS The [`cosmos-kms`](https://github.com/cosmos/kms) repo is a remote signer for CometBFT, written in Go. It implements the signer side of privval and answers a node's signing requests from a backend that holds the key. One signer process can sign for multiple chains, with each chain backed by exactly one key, and can hold connections to multiple nodes per chain. It is built for operators who must keep validator keys in real custody, an HSM or a cloud key service, rather than in files on chain infrastructure. Three backends are supported: * File: a key file on the signer's disk, for development and testing, not production custody. * PKCS#11: a hardware security module, signing on-device through the standard HSM interface. * AWS KMS: a key that never leaves AWS KMS, using standard AWS credentials and IAM. Cosmos-KMS is designed to work with existing validator infrastructure, and validators should prefer it over previous remote-signing solutions. If you run [TMKMS](https://github.com/iqlusioninc/tmkms) today, see [Migrate from TMKMS](/sdk/latest/kms/migrate-from-tmkms). Cosmos-KMS speaks the CometBFT privval protocol, so it can sign for any node that implements that protocol. ## How it works A running signer comes down to five moving parts: * Configuration: one file, `kms.yaml`, in three blocks: the chains it signs for, the validators it dials, and the keys binding each chain to exactly one backend. The `kms init` command scaffolds it; `kms start` serves until stopped. * Signing: requests travel the privval connection, the backend signs in place, on disk, on the HSM, or inside AWS KMS, and only the signature returns. The private key never crosses the wire. * Connection: the signer dials out, so the signing host needs no inbound ports. The address scheme selects the transport: `tcp://` uses CometBFT's SecretConnection, and `noise://` adds mutual peer pinning, where each side refuses any connection from an unexpected peer. * Key types: over privval, the signer signs `ed25519`, `secp256k1eth`, and post-quantum `mldsa65`, plus `secp256k1` on the AWS KMS backend; the gRPC signer service signs `ed25519`, `secp256k1eth`, and `secp256k1`, but not `mldsa65`, which has no gRPC signature scheme and is privval-only. For per-backend support, see [Configure a signing backend](/sdk/latest/kms/configure-backend). * Double-sign protection: a per-chain last-signed state file refuses anything at or below a height, round, and step already signed. The protection lives with the key, so even a misbehaving or duplicated validator node cannot force a double sign. Because this protection is per state file, it is recommended never to run two signers for the same key. For a backup, connect a single signer to more than one validator node. ## Next steps * Run a remote signer against a local chain. See [Remote signing tutorial](/sdk/latest/kms/tutorial-file-backend). * Move the key into real custody, AWS KMS or an HSM. See [Configure a signing backend](/sdk/latest/kms/configure-backend). * Harden the signer's placement and transport. See [Remote signing best practices](/sdk/latest/kms/best-practices). * Look up any `kms.yaml` field. See the [configuration reference](/sdk/latest/kms/configuration-reference). * Understand which key the signer holds and how it rotates. See [Key rotation](/sdk/latest/keys/key-rotation). * Understand post-quantum consensus keys and their costs. See [Post-quantum keys](/sdk/latest/keys/post-quantum-keys). # Rotate a consensus key held in Cosmos-KMS Source: https://docs.cosmos.network/sdk/latest/kms/rotate-key-remote-signer Rotate a validator's consensus key when the current key lives in a remote signer: new key in the backend, a second node and signer, rotate, cut over. This tutorial rotates a staked validator's consensus key when Cosmos-KMS holds the current key rather than a local file. It continues the [remote signing tutorial](/sdk/latest/kms/tutorial-file-backend) and reuses that setup: the single-node chain `kms-demo-1`, with node home `~/.kms-demo-node` (RPC on port 26657, privval listener on port 26659) and signer home `~/.kms-demo`, whose signer dials that listener. The rotation is the standard zero-downtime rotation with three differences. The new key is generated in a signing backend. The second node gets its own signer process. The new public key comes from the second node's RPC instead of a key file. For the standard procedure and the rotation rules, see [Rotate a consensus key, Staking](/sdk/latest/keys/rotate-validator-key). <Warning>Key rotation can introduce security implications for your chain. Read the [Key rotation](/sdk/latest/keys/key-rotation) overview in its entirety before proceeding.</Warning> Commands use `simd` as the chain binary and `val` as the validator key name. Substitute your own for a real chain. The live pair and the new pair run on one host, so the second node and its new signer take spare ports: the second node listens for its signer on port 26669 and serves RPC on port 26667. ## Prerequisites * A validator already signing through Cosmos-KMS, from the [remote signing tutorial](/sdk/latest/kms/tutorial-file-backend), still running. * All prerequisites of the standard rotation: Cosmos SDK 0.55 and CometBFT 0.40 or later, the target key type in consensus params, no rotation in the current unbonding period, and funds for the burned rotation fee plus gas. See [Rotate a consensus key, Staking](/sdk/latest/keys/rotate-validator-key). * [jq](https://jqlang.org/) and [curl](https://curl.se/), used to derive the new public key. * Spare ports on the host for the second node and its signer. * The chain's binary; the examples use `simd`. To build it and run a node, see [Run a node](/sdk/latest/node/run-node). ## 1. Generate the new key in a backend For an HSM or AWS KMS, generate the key with the backend's own tooling. The commands are in [Configure a signing backend](/sdk/latest/kms/configure-backend). This guide uses the file backend, so a scratch `simd init` generates a fresh key file. ```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} simd init scratch --chain-id kms-demo-1 --home ~/.kms-demo-scratch ``` <Note>For a post-quantum `mldsa65` target on the file backend, add `--consensus-key-algo ml_dsa_65` to the `simd init` command above and set `algorithm: mldsa65` in the signer's `keys` block in step 2. The PKCS#11 and AWS KMS backends also sign `mldsa65`; see [Configure a signing backend](/sdk/latest/kms/configure-backend) for generating the key on those.</Note> The new key is `~/.kms-demo-scratch/config/priv_validator_key.json`. The rest of the scratch home is disposable. <Danger>The new key must be freshly generated. Reusing key material any signer has signed with risks a double sign, which tombstones the validator.</Danger> ## 2. Configure a second signer with the new key One Cosmos-KMS process cannot hold two keys for the same chain. The new key must run in its own process, with its own home and double-sign state: ```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} kms init --home ~/.kms-demo2 ``` Copy the new key to the second signer's home: ```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} cp ~/.kms-demo-scratch/config/priv_validator_key.json ~/.kms-demo2/priv_validator_key.json ``` Replace the contents of `~/.kms-demo2/kms.yaml` with the following. The `addr` is the port the second node listens on for its signer. For an HSM or AWS KMS key, the `keys` block instead binds the backend entry from step 1: ```yaml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} chains: - id: kms-demo-1 validators: - chain_id: kms-demo-1 addr: tcp://127.0.0.1:26669 identity_key: identity.json keys: - chain_ids: [kms-demo-1] backend: file algorithm: ed25519 key_file: priv_validator_key.json ``` <Note>For a post-quantum `mldsa65` key, set `algorithm: mldsa65` in the signer's `keys` block above.</Note> Do not start the signer yet. It starts in step 3, right before the second node, so its connection retries are still fast when the node comes up. ## 3. Bring up the second node and its signer Initialize a fresh node home and give it the chain's genesis: <Note>On a real chain with history, a fresh node takes days to sync from genesis. Use state sync or a snapshot to reach the chain head quickly. See [State sync](/sdk/latest/node/run-node#state-sync) for more info.</Note> ```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} simd init shadow --chain-id kms-demo-1 --home ~/.kms-demo-node2 ``` ```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} cp ~/.kms-demo-node/config/genesis.json ~/.kms-demo-node2/config/genesis.json ``` With the prep done, start the new signer and the second node in quick succession. In one terminal, start the signer. It logs `dial failed` and retries until the node exists: ```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}} kms start --home ~/.kms-demo2 --allow-fresh-state kms-demo-1 ``` The new key has never signed on this chain, and this signer home is new, so it holds no sign-state file. `--allow-fresh-state` writes the height-0 double-sign floor so the signer will start. Without it the signer exits with `sign-state file ... is missing or empty; refusing to start at height 0`. <Warning>Use `--allow-fresh-state` only here, for the new key's first start. Do not add it to the live signer or to any later start of this one. Once a state file exists the flag has no effect, so it fails quietly, but it means a lost or truncated state file resets the double-sign floor to zero rather than stopping the signer. After the cutover in step 5, run the new signer with the bare comma
프로젝트로 돌아가기