OKP4

How to deploy sentry nodes in the OKP4 network

When deploying a Cosmos SDK based node such as OKP4, we must keep in mind that p2p networks are exposed to the risk of denial of service attacks, and an effective way to mitigate this type of attacks is by using sentinel nodes.

Why is it important to avoid denial of service attacks?

When our node is suffering a denial of service attack that cannot be mitigated by the server provider, it is likely that the server will be inoperative for the duration of the attack because, being saturated, it will stop responding to the requests made by the rest of the nodes in the network.

If our node becomes inoperative, it means that we are no longer participating in the consensus rounds, our node will not be signing blocks or generating rewards for the delegators and therefore in a few minutes the node will be jailed and penalized.

In addition to being a risk for node operators due to the penalties involved in being jailed, it is also a risk for the network, since if an attack is carried out on several nodes at the same time, the stability and security of the network would be affected.

P2P networks

A p2p (peer-to-peer) network, such as Okp4's network, is a network where a set of computers (2, 10 or 130, no matter the number) are interconnected with each other. Unlike what happens when we visit a web page where there is a server to which we make a request, in a p2p network there is no central server, but all the machines are equal to each other and are continuously communicating to perform the validation of the blocks.

The problem with p2p networks is that in order for the different machines (nodes) that are part of the network to communicate with each other, an entry point is required to establish connections; this entry point is the IP address and port. Knowing the machine's IP address and p2p port, the rest of the nodes in the network can make requests and, in short, make it part of the p2p network, but it is also the entry point for an attacker's denial-of-service attacks.

Sentinel nodes, hiding our validator's IP from the world

As we discussed earlier, when we expose the IP of our validator node, the rest of the nodes in the network can connect to us, but we are also allowing someone to saturate our machine.

Using sentinel nodes is a solution to prevent the rest of the network from knowing the IP of our validator node, but allowing our validator node to continue communicating with other validator nodes in the Okp4 network, since if the node were 100% isolated, it would not be able to participate in the network and therefore would not generate rewards for the delegators.

A sentinel node is a bridge between our validator node and the rest of the network, so that the rest of the network does not know the IP of the validator node, but the IP of the sentinel nodes.

As can be seen in the previous image, the "Validator node" is only connected to our sentinel nodes, but not to the rest of the network. Thus, only the sentinel nodes will know the IP of our validator node.

Can sentinel nodes suffer denial of service attacks?

Yes, but as they are nodes that are not validating transactions and only act as a bridge between the network and the validating node, we could quickly deploy new sentinel nodes or even change the IP of the sentinel node being attacked.

How many sentinel nodes can there be?

There is really no maximum number, the more sentinel nodes we have, the more resistance to denial of service attacks our validator node will have. However, it must be taken into account that the more sentinel nodes we have, the more complex it will be to maintain our nodes when carrying out maintenance or upgrades, in addition to the increase in server costs. You should have at least two sentinel nodes and if possible have one of them in a different datacenter from where the validator node is deployed.

Where should the sentinel nodes be deployed?

If two sentinel nodes are going to be mounted, one of them could be deployed in the same datacenter where our validator node is, this will reduce the latency between both servers, and therefore, the connection between both servers will be quite fast. The other sentinel node could be located in a different datacenter; this way, in case the network of the datacenter where our validator node is down for any reason, we would always have a node with the current block available to synchronize our validator node.

Step by step guide

To follow this guide, we will use a node created in OKP4's okp4-nemeton-1 testnet network. In case you have not deployed the node yet, you can rely on the official OKP4 documentation.

Creating the sentinel nodes

Once we have contracted the two sentinel node servers and we have the access IPs, we must perform the same installation that we would perform as if it were a validator node on both servers.

🚀 Tip: If you use MobaXterm, you can use the MultiExec option to perform the same commands on both servers at the same time.

First, we will need to download and compile the okp4 binary.

git clone https://github.com/okp4/okp4d
cd okp4

Once downloaded, we will proceed to compile the binary:

make install

It will also be necessary to initialize the node so that the .okp4 directory is created, for this we can use the following commands, each one in the corresponding server:

  • On sentinel node A:

okp4d init "Huginn.tech" --chain-id okp4-nemeton-1
  • On sentry node B:

okp4d init "Huginn.tech" --chain-id okp4-nemeton-1

Once the previous step is done, the .okp4 folder will already exist, so we can download the genesis.json file:

wget https://raw.githubusercontent.com/okp4/networks/main/chains/nemeton-1/genesis.json -O $HOME/.okp4d/config/genesis.json

Finally, we will configure the okp4 service:

sudo nano /etc/systemd/system/system/okp4.service

Remember to replace the user you are using where it says <user here>.

[Unit] Description=Okp4 Daemon After=network-online.target

[Service] User=<user here> ExecStart=/home/<user here>/go/bin/okp4d start --p2p.laddr tcp://0.0.0.0.0:26656 --home /home/<user here>/.okp4 Restart=on-failure RestartSec=3 LimitNOFILE=4096

[Install] WantedBy=multi-user.target

Once we have finished editing, we will enable the service:

sudo systemctl enable okp4d

Base configuration of the sentinel nodes

For now we have not done anything different from what we would do when setting up a validator node, although we have stopped doing several things, such as creating the wallet or running the validator creation command "tx staking create-validator", since we do not want to create validator nodes, only nodes that synchronize with the rest of the nodes in the network and we can use to synchronize our validator node in a secure way without exposing our IP to the rest of the network.

The sentinel nodes (both), must have peers to be synchronized at all times, we will add the following peers to the config.toml file inside the config folder.

persistent_peers = "3ecbc8aa00b5dd8af88af7496489b0054e3b4d7f@138.68.182.247:26656,9c462b1c0ba63115bd70c3bd4f2935fcb93721d0@65.21.170.3:42656,2e85c1d08cfca6982c74ef2b67251aa459dd9b2f@65.109.85.170:43656,ee4c5d9a8ac7401f996ef9c4d79b8abda9505400@144.76.97.251:12656,affaad7c297b627020f63d5bc5b1c1a9d8842f44@152.32.192.192:26656,264256d32511c512a0a9d4098310a057c9999fd1@65.21.90.141:12234,e20b9048c220d4a8b7e7934fddb3c4fb20c20bdd@81.0.246.196:26656,0448864ede56d3c96d7d3bb8ea9f546b70cc722e@51.159.149.68:26656,fa04503a35476204861f06b75be4839562205527@65.109.85.226:6070,e3c602b146121c88d350bd7e0f6ce8977e1aacff@161.97.122.216:26656,da8e2423cb90fba519e685aa47669eb861ea18c4@65.108.249.79:36656,08c925f04cb7a324b1aa91b472faa99c7cccc6ab@65.108.56.126:36656,6bc178290d0773e244cf04598a3919d7a9391bf1@65.109.131.71:36656,61544968b65e34a59513b67613519cd37ace7ecb@161.97.151.109:26656,8cdeb85dada114c959c36bb59ce258c65ae3a09c@88.198.242.163:36656,ed52ad66f7c30b322c1e58d226791f1402883db3@23.88.72.246:36656,1e48c09a0f78070e90ed49b2e3d59f8fdc188e74@162.55.234.70:55156,e1635bec0e5a14dbbf1a41557714632627729ff9@95.217.144.44:36656,307fb25cd6998d0d5bd1d947571f6043c6bb4069@65.109.31.114:2280,5ed1edac2d35c91577b34f6002c85927027058b9@95.217.202.49:30656,1655cdc8fdfe1dc2209d47ff68c02a417ef9ed52@135.181.222.179:31656,4ea26ce893d8f4f89a7b49b9bd77e0fbd914e029@65.109.88.162:36656,d4305fcb7b20dc96481a6ae6ae84f281f3413a4e@65.109.37.58:13656,1f4fa23210cc1d086a928a3c6de7c24f6c8f17ba@202.61.226.120:16656,977373e6ff096d43c928e14724b8c6d9d7f48cb7@5.9.147.185:51656,84da5ad673d086c5c0b4a8da8b8b1c1c29e1d81e@142.132.130.196:36656,751d8d4bc73443aef9f95ddfac3572ddfc34e035@5.75.226.80:26656,370057fa4a5b3c835ea9eaf1a33d2d6e1e8820ee@65.108.234.126:24656,a009a02a23428538b57591f73ba5a6462c476a70@136.243.88.91:6040,c3db3a07493e8f04d93a9228998ae799fa89877f@5.78.48.118:26656,126dc25a6a5aa0cfa83010550dfb3c5a1a861755@65.108.201.15:21337"

Note: the peers were obtained from Discord in the nemeton-program channel.

It would also be advisable to add as persistent peer the sentinel nodes between them. That is to say, that the sentinel node B is persistent peer of the sentinel node A, in the same way that the sentinel node A is persistent peer of the sentinel node B; this will make us have more redundancy.

In the config.toml file of the config folder of the sentinel nodes (both), it is necessary to specify the id of the validator node in the private_peer_ids parameter. This is so that our sentinel nodes never share with the rest of the peers of the network the existence of our validator node.

private_peer_ids = "validator node".

The appearance should look something like this:

If you don't know how to get the id of your validator node, you can get it with the following command:

okp4d tendermint show-node-id

*Note: to the received id, we must concatenate the ip and the p2p port as shown in the image above.

In the same configuration file, we will also find the unconditional-peer-ids parameter to which we must add our validator node as we did with the private_peer_ids parameter. This step is necessary because the nodes have a limited number of peers to which they can connect.

To avoid the risk of leaving our validator node incommunicado, by setting its id in the unconditional-peer-ids parameter, we will make the sentinel nodes always connected to the validator node even if the limit of peers to which they can be connected has been exceeded. Optionally we can also add in this same parameter (separated by commas) the homologous sentinel node to guarantee that the sentinel nodes will always be connected to each other.

unconditional-peer-ids = "validator node, homologous sentinel node".

*Note: with homologous sentinel node we mean that if you are configuring the sentinel node A, the homologous would be the B, and in the case of editing the sentinel node B, the homologous would be the sentinel node A.

At this point, we could start our sentinel nodes and let them synchronize and be discovered by the rest of the network. For that we will use the following command:

sudo systemctl start okp4d

If we have done all the steps correctly, we should see how both sentinel nodes are synchronizing:

Validator node configuration

Once the sentinel nodes have been synchronized, we can configure the validator node with all certainty that our validator node is not going to stop being synchronized with the network. We will have to edit the config.toml file in the config folder, where we will find the following lines:

# Comma separated list of nodes to keep persistent connections to
# Do not add private peers to this list if you don't want them advertised
persistent_peers =[list of sentry nodes]

In persistent_peers we will add only the ids of the sentry nodes, that is to say that if the node was already mounted before, we will have to delete the content of this field before adding our sentry nodes.

The appearance should be similar to the following:

In the same configuration file we will find the pex parameter, which we must set to "false". This parameter does not discover other peers, it will only use the ones set in the persistent_peers parameter.

pex = false

If the validator has already been exposed to the network, we can delete the address book so that it only "knows" the sentinel nodes; if it is a validator that has never been started, this step is not necessary. Once inside the config folder and with the node stopped, perform the following command:

rm addrbook.json

At this point, we can start the node and it will synchronize using only the sentinel nodes.

To verify that we are really connected only to two peers and these are the sentinel nodes, we can write the following command in our validated node; the output is a JSON where it will show us the number and which peers we are connected to, where the number should be two and the peers should be our sentinel nodes.

curl -s localhost:26657/net_info

Here you can see the number of peers to which our validator node is connected, in this case it is two, which is correct.

And in the JSON object, if we continue observing, we will see that the two peers we have are "Sentry A" and "Sentry B".

Extra: Protecting the validator node through firewall

Right now the p2p port of our validator node is open and anyone can establish a connection. If we have just set up the validator node, with the configurations made, nobody would have to find our validator node, however, to add a plus of security it is advisable to close the p2p port and only allow traffic to the IP's of our sentinel nodes.

There are several ways to do this, it is possible that your server provider allows you to do it through a gui. Ufw is a simple to use alternative, you can read more about ufw here.

The commands to use with ufw are as follows:

sudo ufw allow from <sentry A IP> proto tcp to any port 26656
sudo ufw allow from <sentry B IP> proto tcp to any port 26656

Extra: Private networks

One possibility we have when our validator node is in the same datacenter as one of the sentry nodes, would be to use private addressing.

In case we want to use private addressing, we will have to edit the addr-book-strict parameter of the config.toml file and set it to false in both the validator node and the sentinel node that are communicating under private addressing. This parameter, when set to "true", will only add routable addresses to the address book, the private addresses defined in RFC-1918 are not routable, therefore, they would not be added to the address book, so we will have to change it to false to be able to use IP addresses from the private ranges.

addr-book-strict: boolean. By default, nodes with a routable address will be considered for connection. If this setting is disabled (false), non-routable IP addresses, such as addresses from a private network, can be added to the address book.

Conclusions

Having sentinel nodes will not only help our validator node not to fall victim to a denial of service attack, but will also make the Okp4 network more robust. The installation of the sentinel nodes does not differ much from that of a validator node, and the additional configurations to be performed are very simple and intuitive.

Now that Okp4 is doing the nemeton-1 testnet, it is a good time to try to set up sentinel nodes and once the mainnet is launched, to be able to replicate it with the experience of having been able to test it in nemeton-1. If you already have your node on nemeton-1 what are you waiting for to set up your sentinel nodes and protect yourself from unwanted attacks?

Last updated