Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Upgrading to config version 0.1.6

Operator access to Lightning onion addresses

services.lnd.lndconnect.onion and services.clightning.plugins.clnrest.lnconnect.onion now give the operator user access to the lnd-rest and clnrest onion addresses only when nix-bitcoin.operator.enable is set. This matches the access to the other onion addresses. Before, the operator user received this access whenever it existed, for example when nix-bitcoin.operator.name named an existing account and the operator role was disabled. When the operator user didn’t exist at all, the onion-addresses service failed and published no onion address for anyone.

lndconnect isn’t affected. It runs as the lnd user and reads the lnd user’s copy of the address. With the operator role disabled, only lnconnect-clnrest reads the address from the operator user’s directory. nodeinfo reads it too, but it enables the operator role itself. So with clnrest.lnconnect.onion enabled, evaluation fails unless the operator user has clnrest access. If you use it with the operator role disabled, choose one of the following:

  • Enable the operator role. It declares users.users.<operator name> as a normal user and merges into an existing declaration under that attribute, but also adds the operator’s groups and its permission to run commands as service users. Don’t use it if the account is declared under another attribute or comes from outside users.users, since NixOS would then manage it with its defaults:
    nix-bitcoin.operator.enable = true;
    
  • Keep the role disabled and grant only the onion address access:
    nix-bitcoin.onionAddresses.access.<operator name> = [ "clnrest" ];
    
    lnconnect-clnrest also reads the admin rune, which only the clightning group can read. Without the role, run lnconnect-clnrest as root, or add the user to this group:
    users.users.<operator account>.extraGroups = [ "clightning" ];
    
    <operator account> is the users.users attribute that defines the account. It’s usually the operator name. Members of this group can read the admin rune and use the clightning RPC socket, so they have full control over the node.
  • If the operator account is disabled in users.users, enable it and use one of the options above. If it comes from outside users.users, for example from LDAP, and you can’t declare it (see below), set nix-bitcoin.operator.name to an enabled account in users.users and use one of the options above for it, or disable clnrest.lnconnect.onion.

Onion address access requires declared users

nix-bitcoin.onionAddresses.access now accepts only users that are defined and enabled in users.users, and evaluation fails if it names any other user. Before, it also accepted accounts created outside the configuration, for example with useradd or via LDAP, because the onion-addresses service looked the names up at runtime. For each such user, either remove it from nix-bitcoin.onionAddresses.access, or declare the account in users.users. NixOS then manages the account and applies its defaults to anything you leave out, so declare its current settings: isNormalUser or isSystemUser, uid, the primary group and its users.groups entry with the current gid, extraGroups, description, home, homeMode and shell. With users.mutableUsers = false, NixOS also manages the password, so declare it too if the account uses one.

Secret file validation

setup-secrets now fails when a declared secret file is empty or isn’t a regular file, as it does when one is missing. Then services can’t read any secret until setup succeeds. Before deploying, check the secrets dir for empty files, for example with find /etc/nix-bitcoin-secrets -maxdepth 1 -type f -empty:

  • Write the secret to each empty file that a service needs. With nix-bitcoin.generateSecrets = true, setup regenerates empty passwords.
  • Secret generation (nix-bitcoin.generateSecrets = true) doesn’t replace an empty TLS key (lnd-key), WireGuard private key or replication SSH key, or a symlink to a missing file in their place, because a new key breaks the clients that trust the old one. Setup fails and names the file: restore it from a backup, or delete it to generate a new key.
  • For a secret that may be empty, set nix-bitcoin.secrets.<name>.allowEmpty = true. bitcoinix sets it for backup-encryption-env.
  • With the bitcoind-remote.nix preset and nix-bitcoin.generateSecrets = false, the local bitcoin-HMAC-* files are unused, but setup checks them too. Write the HMAC of the matching password to each one: the <salt>$<hmac> part of its rpcauth= line, as printed by Bitcoin Core’s share/rpcauth/rpcauth.py. Or set allowEmpty for them.

lnd seed validation and wallet creation

lnd now stops with an error when wallet.db in lnd’s network dir isn’t a regular file, for example a symlink to a moved or unmounted wallet. Before, lnd tried to create a new wallet there. Restore the wallet, or remove the entry if lnd never ran a wallet from it.

While lnd has no wallet.db, a symlink to a missing file at lnd-seed-mnemonic in lnd’s data dir now stops lnd with an error. An empty lnd-seed-mnemonic, which a failed seed creation of an earlier version could leave, already stopped lnd with an lndinit error. Now the error names the file. In both cases, if lnd never ran a wallet from that seed, delete it, and lnd creates a new seed. Otherwise, restore it from a backup.

lnd now creates its wallet in a temporary directory. Before, a failed wallet creation could leave a partial wallet.db, and lnd then never started: every start skipped wallet creation, and the lnd log shows an lndinit error such as private passphrase may not be empty. If your node is stuck like this and lnd never ran with this wallet, fix the cause, keep lnd-seed-mnemonic in lnd’s data dir, and move the partial wallet aside. lnd then creates the wallet from the same seed. With the default data dir on mainnet:

systemctl stop lnd
mv /var/lib/lnd/chain/bitcoin/mainnet/wallet.db /var/lib/lnd/chain/bitcoin/mainnet/wallet.db.failed
systemctl start lnd

Separate root keys for custom lnd macaroons

Each custom lnd macaroon (services.lnd.macaroons, also used by BTCPay Server and charge-lnd) now has its own root key, with an ID from 7953919891889717248 to 7954201366866427903 (0x6e62000000000000 to 0x6e62ffffffffffff). Each time lnd starts, bitcoinix deletes the root key of every ID in this range that no configured macaroon uses. Before deploying, check that lncli listmacaroonids lists no ID in this range. If it does, bake the macaroons that use such an ID again with an ID outside the range.

bitcoinix now uses lnd’s admin macaroon and gRPC each time lnd starts, also without custom macaroons. Keep lnd’s macaroons enabled: the no-macaroons option isn’t supported.

When lnd restarts during the deployment, bitcoinix creates the custom macaroons with their new root keys. BTCPay Server and charge-lnd read their new macaroons without a restart. Restart other services that read a custom macaroon only at startup; see Custom macaroons. Copies of custom macaroons created before this change use root key 0, like the admin macaroon, and stay valid. To revoke them, see Revoke all macaroons.

Custom lnd macaroon file permissions

Each custom lnd macaroon is now readable only by its user, with mode 0400. Before, the user’s primary group could read it too. For a user like operator, that’s the group users, which normal users get by default. So other normal users could read the macaroon. If other users log in to your node, they could have copied it, and such copies stay valid. To revoke them, see Revoke all macaroons. If a program reads a custom macaroon as another user, through the group, give the program its own macaroon in services.lnd.macaroons.

RTL stops with its backends

RTL is now bound to the units of its enabled backends, lnd for services.rtl.nodes.lnd and clightning for services.rtl.nodes.clightning. It now stops when a backend’s unit stops, crashes or exits, instead of polling the port of a stopped backend, which another local user could take over. A backend’s start starts RTL again once all of RTL’s backends run. Deploying this change restarts each backend that RTL uses once, because its unit changes.

With both backends enabled:

  • Stopping one backend, for example clightning for maintenance, also stops RTL for the other one.
  • Starting RTL starts a stopped backend too. Leave RTL stopped until the maintenance is done. The backend’s own start starts RTL again afterwards.

RTL verifies its backends’ certificates

RTL now checks TLS certificates. A connection to a backend’s address and port must present that backend’s pinned certificate: services.lnd.certPath for lnd, or server.pem in clnrest’s cert dir (clightning’s network dir, or clnrest-certs). Every other HTTPS connection gets the normal certificate and hostname checks against the system CAs. These setups no longer work:

  • LN_SERVER_URL or LND_SERVER_URL in RTL’s environment. RTL doesn’t start.
  • Another URL in Settings.lnServerUrl in services.rtl.nodes.<node>.extraConfig. Evaluation fails.
  • A proxy in RTL’s environment without a no_proxy entry for the backend address. RTL then reaches the backend through the proxy, where it has no pin, and the system CAs don’t trust the backend’s certificate.
  • A server with a self-signed certificate set through extraConfig, for example a swap server. To use it, add its certificate with systemd.services.rtl.environment.NODE_EXTRA_CA_CERTS.

RTL two-factor authentication persists across restarts

RTL now keeps the two-factor authentication (2FA) that you set up in its web interface across restarts. Before, each restart turned 2FA off without a warning. If you lose the authenticator, delete RTL-Config.json in RTL’s data dir (/var/lib/rtl by default) and restart RTL. RTL-Config.json holds the 2FA secret and is now readable only by RTL’s user. Before, members of group rtl could read it too.

Tor enforcement allows only local addresses

Services with Tor enforcement (services.<service>.tor.enforce, set by the secure-node preset and enable-tor.nix), charge-lnd, and custom units that use nix-bitcoin.lib.allowLocalIPAddresses or allowTor have a narrower network restriction:

  • Without network namespace isolation they reach localhost only. With it, they also reach the namespace subnet 169.254.<addressblock>.0/24. To let a service reach a further address, allow it for that service, for example for electrs:
    systemd.services.electrs.serviceConfig.IPAddressAllow = [ "10.10.0.2" ];
    
    With netns-isolation, services with tor.enforce are also limited by the namespace firewall, so IPAddressAllow alone doesn’t widen them there; see that section. charge-lnd and custom units have no tor.enforce and no such namespace firewall, so IPAddressAllow does widen them, with or without netns-isolation.
  • They can’t use the local name-resolution sockets (nscd, systemd-resolved, D-Bus, Avahi). glibc resolves names itself, from /etc/hosts. If a service connects to an allowed address by host name, use the address directly or add the name to networking.hosts.
  • A resolver on 127.0.0.1 or ::1 stays reachable without netns-isolation; see Services for what that means and how to avoid it.
  • netns-isolation no longer accepts addressblock 169 or 170, because those subnets hold cloud metadata addresses. Evaluation fails with a message. Pick another block, and update any addresses you derived from it.

Evaluation reports this change for services with tor.enforce and for charge-lnd, but not for custom units. If one of your units uses allowLocalIPAddresses or allowTor, check it against the points above before you deploy.

After migrating your configuration, set nix-bitcoin.configVersion = "0.1.6";.