Setting Up HashiCorp Vault + EthSigner
Page Contents
Run Vault Server & Import Private Key
Introduction
HashiCorp Vault (hereon called Vault) allows you to securely store secrets in one place. Docs: https://developer.hashicorp.com/vault/tutorials/getting-started
EthSigner allows you to sign transactions in an isolated environment using a private key secured by Vault. Docs: https://docs.ethsigner.consensys.io/
Security Notes
The connection between EthSigner and Vault is secured by TLS (the private key is passed along this connection). The connection between the NodeJS App and EthSigner is not TLS secured, which is not a major concern as the signed transaction object cannot be used in replay attacks. All traffic stays within the localhost loopback within your local server, so no messages are passed on your local network.
Install HashiCorp Vault
sudo apt updateupdates apt-installed packages
sudo apt install gpg wgetinstalls gpg (GNU Privacy Guard), which is a cryptography library, and wget, which is like curl but used mostly for downloading files
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpgThis downloads a "keyring" from HashiCorp and puts it into the file defined by the last part of the command (the pipe key "|" takes ouput of statement before and uses it as the input for the statement after)
If you get a certificate verification error, use
wget -O- https://apt.releases.hashicorp.com/gpg --no-check-certificate | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprintThis verifies the keyring
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.listThis writes the string in the quotes to the file after the pipe key ("|"). The string is a command to use the "deb" package manager to download a repo from the https url. The package is signed by the key ring you downloaded earlier. "$lsb_release -cs" prints the version of Ubuntu of your system.
sudo apt update && sudo apt install vaultThis installs Vault using the apt package manager
Check installation with
vaultandvault --version
Install EthSigner
sudo apt-get install openjdk-17-jdkInstalls Java 17 (must use Java 17, not Java 11); 500MB
Download ethsigner.tar.gz file (.tar.gz is like a .zip file) in link:
cd into the folder where you want the folder extracted
tar -xzvf filename.tar.gzextracts the files into a folder called "ethsigner-23.6.0"
Check installation
cd into "ethsigner-23.6.0" folder and run
./bin/ethsigner --helpSuccess shows a list of EthSigner commands
If it doesn't work, check the permissions of the "ethsigner" binary:
cd into "ethsigner-23.6.0" folder, cd into "bin" folder
run
ls, you should see the files "ethsigner" and "ethsigner.bat"run
ls -l ./ethsigner, ensure you have "x" (executable) permissions. If not, then runchmod +x ./ethsigner
Prepare Files To Enable TLS Between EthSigner and Vault
cd "ethsigner-23.6.0" folder,
mkdir tls, cd into "tls" folderGenerate the TLS private key and certificate
openssl req -x509 -sha256 -days 3560 -nodes -newkey rsa:2048 -subj "/CN=localhost" -addext "subjectAltName=IP:127.0.0.1" -keyout vault.key -out vault.crtthe command "-addext "subjectAltName=IP:127.0.0.1"" adds an Alternative Name to the certificate, which is usually not needed but is needed for HashiCorp Vault
Get SHA-256 fingerprint of vault.crt
openssl x509 -in vault.crt -noout -fingerprint -sha256Copy it to somewhere temporarily (we will use it in next step)
For TLS connections, EthSigner requires a "knownServers" file. From the perspective of EthSigner, HashiCorp Vault is a server
touch knownServers && vim knownServerspress
ito start editing, enter two lines:line 1:
localhost:8200 <sha256 fingerprint of vault.crt>line 2:
127.0.0.1:8200 <sha256 fingerprint of vault.crt>ctrl + c,:wq, thenEnterto save & exit
Run Vault Server & Import Private Key
cd into "ethsigner-23.6.0" folder (cd out of "tls" folder)
create config.hcl file
touch config.hcl && vim config.hclito start editing. Copy in the below:ctrl + c,:wq, thenEnterto save & exit
mkdir -p ./vault/datato create "vault/data" folderIf you previously created a Vault instance, be sure to delete all contents of old data folder
This is where encrypted secrets are stored using Raft, which is the Integrated Storage backend used to persist Vault's data
Run Vault server in tmux window
tmux new -s vault(you should be in "ethsigner-23.6.0" folder)vault server -config=config.hclctrl + b, thendto leave tmux
Initialize Vault
set env var
export VAULT_CAPATH="/home/brianhuang/ethsigner-23.6.0/tls/vault.crt"replace full path with one for your system
vault operator initSuccess shows five "Unseal Keys" and one "Initial Root Token"
Save the "Initial Root Token" somewhere temporarily
This token is used for authenticating a terminal session
Save the "Unseal Keys" somewhere extremely safe, possibly in separate locations
3 of 5 Unseal Keys can unseal the Vault and reveal the secrets inside
EthSigner requires you save the Initial Root Token into a file
cd into "ethsigner-23.6.0" folder, cd into "bin" folder
touch authFile && vim authFileito edit, paste Initial Root Token into first linectrl + c,:wq, thenEnterto save & exit
Unseal the Vault to import your private key and initialize EthSigner (you will seal it back up later)
vault operator unsealcopy in one Unseal Key (characters will not show), then press
EnterRepeat the above two steps two more times with the 2nd and 3rd Unseal Keys (you need 3/5 keys to unseal the Vault)
Authenticate your terminal
must have VAULT_CAPATH env var in this terminal
export VAULT_CAPATH="/home/brianhuang/ethsigner-23.6.0/tls/vault.crt"
vault loginpaste in the Initial Root Token
Success shows: "Success! You are now authenticated."
Import private keys (see Static Secrets: Key/value secrets engine for more info)
Enable storage path with
vault secrets enable -path=secret kvSuccess shows: "Success! Enabled the kv secrets engine at: secret/"
Upgrade Key/Value Secrets Engine from v1 to v2 with
vault kv enable-versioning secret/Success shows: "Success! Tuned the secrets engine at: secret/"
Add private key with
vault kv put secret/ethsignerSigningKey value=<privateKeyWithout0x>
Run EthSigner Server
cd into "ethsigner-23.6.0" folder (you may be in "bin" folder right now)
create new tmux window called "ethsigner" with
tmux new -s ethsigner./bin/ethsigner --chain-id=137 --downstream-http-port=443 hashicorp-signer --host=127.0.0.1 --port=8200 --auth-file=./bin/authFile --signing-key-path=/v1/secret/data/ethsignerSigningKey --tls-known-server-file=./tls/knownServersReplace above with correct chain ID (137 = "Polygon")
Leave tmux window with
ctrl + b, thendCheck EthSigner is running
test1:
curl -X GET http://127.0.0.1:8545/upcheckSuccess should show "I'm up!"
test2:
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' http://127.0.0.1:8545Success should show your address
Seal the Vault with
vault operator sealSuccess shows: "Success! Vault is sealed."
View all active ports with sudo lsof -i -P -n | grep LISTEN
Test
Send a Trading View alert or mimic one using sendAlert.js.
If you already set up Ngrok, use the Ngrok URL as the webhook URL. If not, your NodeJS App should be listening on http://localhost:8080/. If using the "localhost" URL, you must run node sendAlert.js on the same machine.
A successful test should show transaction details the the swap hash in the console.
Last updated