This section describes how to securely run a node in a public setting and/or on a mainnet on one of the many Cosmos SDK public blockchains.
There are many different ways to secure a server and your node, the described steps here is one way. To see another way of setting up a server see the run in production tutorial.
This walkthrough assumes the underlying operating system is Ubuntu.
Sever Setup
User
When creating a server most times it is created as userroot
. This user has heightened privileges on the server. When operating a node, it is recommended to not run your node as the root user.
- Create a new user
- We want to allow this user to perform sudo tasks
root
user can be used.
Go
- Install the Go version preconized by the application.
In the past, validators have had issues when using different versions of Go. It is recommended that the whole validator set uses the version of Go that is preconized by the application.
Firewall
Nodes should not have all ports open to the public, this is a simple way to get DDOS’d. Secondly it is recommended by CometBFT to never expose ports that are not required to operate a node. When setting up a firewall there are a few ports that can be open when operating a Cosmos SDK node. There is the CometBFT json-RPC, prometheus, p2p, remote signer and Cosmos SDK GRPC and REST. If the node is being operated as a node that does not offer endpoints to be used for submission or querying then a max of three endpoints are needed. Most, if not all servers come equipped with ufw. Ufw will be used in this tutorial.- Reset UFW to disallow all incoming connections and allow outgoing
- Lets make sure that port 22 (ssh) stays open.
- Allow Port 26656 (cometbft p2p port). If the node has a modified p2p port then that port must be used here.
- Allow port 26660 (cometbft prometheus). This acts as the applications monitoring port as well.
- IF the node which is being setup would like to expose CometBFTs jsonRPC and Cosmos SDK GRPC and REST then follow this step. (Optional)
CometBFT JsonRPC
Cosmos SDK GRPC
Cosmos SDK REST
- Lastly, enable ufw
Signing
If the node that is being started is a validator there are multiple ways a validator could sign blocks.File
File based signing is the simplest and default approach. This approach works by storing the consensus key, generated on initialization, to sign blocks. This approach is only as safe as your server setup as if the server is compromised so is your key. This key is located in theconfig/priv_val_key.json
directory generated on initialization.
A second file exists that user must be aware of, the file is located in the data directory data/priv_val_state.json
. This file protects your node from double signing. It keeps track of the consensus keys last sign height, round and latest signature. If the node crashes and needs to be recovered this file must be kept in order to ensure that the consensus key will not be used for signing a block that was previously signed.
Remote Signer
A remote signer is a secondary server that is separate from the running node that signs blocks with the consensus key. This means that the consensus key does not live on the node itself. This increases security because your full node which is connected to the remote signer can be swapped without missing blocks. The two most used remote signers are tmkms from Iqlusion and horcrux from Strangelove.TMKMS
Dependencies
- Update server dependencies and install extras needed.
- Install Rust:
- Install Libusb:
Setup
There are two ways to install tmkms, from source orcargo install
. In the examples we will cover downloading or building from source and using softsign. Softsign stands for software signing, but you could use a yubihsm as your signing key if you wish.
- Build:
To use tmkms with a yubikey install the binary with
--features=yubihsm
.- Migrate the validator key from the full node to the new tmkms instance.
- Import the validator key into tmkms.
priv_validator_key.json
from the validator node and the tmkms node. Since the key has been imported into tmkms (above) it is no longer necessary on the nodes. The key can be safely stored offline.
- Modifiy the
tmkms.toml
.
123.456.12.345
with a port of 26659
a chain_id of test-chain-waSDSe
. These are items that most be modified for the usecase of tmkms and the network.
- Set the address of the tmkms instance.
The above address it set to
0.0.0.0
but it is recommended to set the tmkms server to secure the startupIt is recommended to comment or delete the lines that specify the path of the validator key and validator:
- Start the two processes.