Jonas Nick dbad828851
Merge #255: Improve netns-isolation and Tor config
b4b607dfa56eaa25a7af5eca55b3149322335db6 netns: simplify firewall setup (Erik Arvstedt)
25639cec427415a0e26d9ffcdc028edea1f11817 netns: fix error msg when starting netns (Erik Arvstedt)
67068afd6b92883df044678e18486e84d02761c5 netns: fix error when stopping netns (Erik Arvstedt)
4ff88efc500cdd7fd0a407c21087c4479390246a netns: add address binding test (Erik Arvstedt)
8da01fe8a65a7dacc9114b00a48432f2b93eea6b lightning-loop: allow RPC access from main netns (Erik Arvstedt)
d76b080b74e7f627ca7806398f716507932fc01a lightning-loop: add RPC and REST server options (Erik Arvstedt)
9ddf7864a4298df1dd996478f81a6a96d1a8af8f lightning-loop regtest: fix incorrectly succeeding test (Erik Arvstedt)
e66636ef0e2f35699516594acfb1b265377f4726 liquidd: use type str for rpcbind (Erik Arvstedt)
de23fdd37780406c9b09e9f0528d8f7ae7cf1a76 lnd: use type str for rpclisten, restlisten (Erik Arvstedt)
8b053326ccb9b08b585d65f54ad12ddbf86c1ff2 bitcoind: use type str for rpcbind (Erik Arvstedt)
6903e8afcce3af2689abe2a8c2454dc0c7774a5a netns-liquidd: allow RPC access from main netns (Erik Arvstedt)
82f4901880e5d8504c8f7d805f4597c0b2c2c6a9 netns-lnd: allow RPC access from main netns (Erik Arvstedt)
58d24e735de29fb76646b4032b53e82ae62ed9fa netns-bitcoind: allow RPC access from main netns (Erik Arvstedt)
0e2ff948d3223bf1ac9d6d6f7dbc22ab43aee60c test: add scenario 'netnsRegtest' (Erik Arvstedt)
e0675cb2564e5eeb41737554c27171c7bac0df1b move enforceTor logic to service modules (Erik Arvstedt)
0cc8caa737a6ac345af147d68f06cfa9d6bba262 lnd: only set tor.active on enforceTor (Erik Arvstedt)
9a931483b9a4be260b17b63e20eda829bad1281b netns test: remove strict dependency on clightning, electrs (Erik Arvstedt)
bae1b7f41331073d59a199cd1835e2c5a9889b49 netns test: improve ping test (Erik Arvstedt)
5e0e16529c573e8e377fe7ae87bb873a286db51b netns: fix default addressblock value type (Erik Arvstedt)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK b4b607dfa56eaa25a7af5eca55b3149322335db6
  nixbitcoin:
    ACK b4b607dfa56eaa25a7af5eca55b3149322335db6

Tree-SHA512: b290831d9a3fa4de56b0f19cf84a1998e830aa844532d7cba8cd8227c785a23bfa1514123a974652e8e61060e1297b6bfbcff9640580206a04c5292309b1daef
2020-11-02 16:11:34 +00:00
2020-10-20 11:18:43 +00:00
2020-10-29 22:36:20 +01:00
2020-10-29 21:21:30 +01:00
2020-10-29 21:21:27 +01:00
2020-01-09 10:43:29 +01:00
2019-01-02 14:03:52 +00:00
2020-01-09 10:43:29 +01:00
2020-03-30 10:49:15 +02:00

nix-bitcoin

Build Status

Nix packages and nixos modules for easily installing Bitcoin nodes and higher layer protocols with an emphasis on security. This is a work in progress - don't expect it to be bug-free, secure or stable.

The default configuration sets up a Bitcoin Core node and c-lightning. The user can enable spark-wallet in configuration.nix to make c-lightning accessible with a smartphone using spark-wallet. A simple webpage shows the lightning nodeid and links to nanopos letting the user receive donations. It also includes elements-daemon. Outbound peer-to-peer traffic is forced through Tor, and listening services are bound to onion addresses.

A demo installation is running at http://6tr4dg3f2oa7slotdjp4syvnzzcry2lqqlcvqkfxdavxo6jsuxwqpxad.onion. The following screen cast shows a fresh deployment of a nix-bitcoin node.

The goal is to make it easy to deploy a reasonably secure Bitcoin node with a usable wallet. It should allow managing bitcoin (the currency) effectively and providing public infrastructure. It should be a reproducible and extensible platform for applications building on Bitcoin.

Examples

The easiest way to try out nix-bitcoin is to use one of the provided examples.

git clone https://github.com/fort-nix/nix-bitcoin
cd nix-bitcoin/examples/
nix-shell

The following example scripts set up a nix-bitcoin node according to examples/configuration.nix and then shut down immediately. They leave no traces (outside of /nix/store) on the host system.

Run the examples with option --interactive or -i to start a shell for interacting with the node:

./deploy-qemu-vm.sh -i

Tests

The internal test suite is also useful for exploring features.
The following run-tests.sh commands leave no traces (outside of /nix/store) on the host system.

git clone https://github.com/fort-nix/nix-bitcoin
cd nix-bitcoin/test

# Run a Python test shell inside a VM node
./run-tests.sh debug
print(succeed("systemctl status bitcoind"))

# Run a node in a container. Requires systemd and root privileges.
./run-tests.sh container
c systemctl status bitcoind

# Explore a single feature
./run-tests.sh --scenario electrs container

See run-tests.sh for a complete documentation.

Available modules

By default the configuration.nix provides:

  • bitcoind with outbound connections through Tor and inbound connections through a hidden service. By default loaded with banlist of spy nodes.
  • clightning with outbound connections through Tor, not listening
  • includes "nodeinfo" script which prints basic info about the node
  • adds non-root user "operator" which has access to bitcoin-cli and lightning-cli

In configuration.nix the user can enable:

  • a clightning hidden service
  • liquid
  • lightning charge
  • nanopos
  • an index page using nginx to display node information and link to nanopos
  • spark-wallet
  • electrs
  • recurring-donations, a module to repeatedly send lightning payments to recipients specified in the configuration.
  • bitcoin-core-hwi.
    • You no longer need extra software to connect your hardware wallet to Bitcoin Core. Use Bitcoin Core's own Hardware Wallet Interface with one configuration.nix setting.

The data directories of the services can be found in /var/lib on the deployed machines.

Installation

See install.md for a detailed tutorial.

Security

  • Simplicity: Only services you select in configuration.nix and their dependencies are installed, packages and dependencies are pinned, most packages are built from the nixos stable channel, with a few exceptions that are built from the nixpkgs unstable channel, builds happen in a sandboxed environment, code is continuously reviewed and refined.
  • Integrity: Nix package manager, NixOS and packages can be built from source to reduce reliance on binary caches, nix-bitcoin merge commits are signed, all commits are approved by multiple nix-bitcoin developers, upstream packages are cryptographically verified where possible, we use this software ourselves.
  • Principle of Least Privilege: Services operate with least privileges; they each have their own user and are restricted further with systemd options, there's a non-root user operator to interact with the various services.
  • Defense-in-depth: nix-bitcoin is built with a hardened kernel by default, services are confined through discretionary access control, Linux namespaces, and seccomp-bpf with continuous improvements.

Note that nix-bitcoin is still experimental. Also, by design if the machine you're deploying from is insecure, there is nothing nix-bitcoin can do to protect itself.

Hardware requirements

  • Disk space: 300 GB (235GB for Bitcoin blockchain + some room)
    • Bitcoin Core pruning is not supported at the moment because it's not supported by c-lightning. It's possible to use pruning but you need to know what you're doing.
  • RAM: 2GB of memory. ECC memory is better. Additionally, it's recommended to use DDR4 memory with targeted row refresh (TRR) enabled (https://rambleed.com/).

Tested hardware includes pcengine's apu2c4, GB-BACE-3150, GB-BACE-3160. Some hardware (including Intel NUCs) may not be compatible with the hardened kernel turned on by default (see https://github.com/fort-nix/nix-bitcoin/issues/39#issuecomment-517366093 for a workaround).

Usage

For usage instructions, such as how to connect to spark-wallet, electrs and the ssh Tor Hidden Service, see usage.md.

Troubleshooting

If you are having problems with nix-bitcoin check the FAQ or submit an issue. There's also a #nix-bitcoin IRC channel on freenode. We are always happy to help.

Docs

Languages
Nix 84.4%
Shell 11.7%
Python 3.5%
C 0.4%