Upgrading to config version 0.2.1
netns-isolation forwards only namespace traffic
netns-isolation turns on IPv4 forwarding for the NAT of the service namespaces. Before, it added no forwarding rules, so the host forwarded traffic between all its interfaces. On a node with two networks, for example a LAN and a VPN, a host on one side could reach the other side through the node.
Now the unit nb-netns-forward adds the iptables chain nb-netns-forward and appends a
jump to it to the FORWARD chain. The chain accepts the connections that a namespace
opens and their replies, and drops all other forwarded IPv4 traffic.
Evaluation fails when boot.kernel.sysctl."net.ipv4.conf.all.forwarding" is on.
networking.nat, Docker and Tailscale with useRoutingFeatures set to server or
both turn it on. Other tools can route through the node without this setting, for
example libvirt, Podman, Incus or systemd-networkd with IPMasquerade. Their forwarded
traffic is now dropped too, unless their own rules accept it before the jump. If this
node routes for other networks, set this.
nix-bitcoin.netns-isolation.restrictForwarding = false;
netns-isolation then adds no forwarding rules, and the host forwards between all its interfaces like before, unless you filter forwarded traffic yourself.
To keep the rules and allow some forwarded traffic, insert your ACCEPT rules at the
top of FORWARD. A rule that’s appended after the jump has no effect. An accept in an
nftables table of its own doesn’t help either, because the packet still passes the
FORWARD chain of iptables. For example, this lets hosts on wg0 reach the LAN on
eth0. The firewall runs the stop commands before the start commands on each reload,
also before the rule exists, so the delete must not fail.
networking.firewall.extraCommands = ''
iptables -w -I FORWARD -i wg0 -o eth0 -j ACCEPT
iptables -w -I FORWARD -i eth0 -o wg0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
'';
networking.firewall.extraStopCommands = ''
iptables -w -D FORWARD -i wg0 -o eth0 -j ACCEPT 2>/dev/null || true
iptables -w -D FORWARD -i eth0 -o wg0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 2>/dev/null || true
'';
To list the rules and count the dropped packets, run this as root.
iptables -vnL nb-netns-forward
netns-isolation rejects an nftables ruleset flush
With networking.nftables and iptables-nft, the NAT rule of the namespace bridge, the
forwarding rules of nb-netns-forward and the host firewall live in the nftables ruleset.
netns-isolation now fails evaluation when networking.nftables.flushRuleset is on. With
the flush, each start, reload or stop of nftables.service deletes these rules. NixOS
turns the flush on by default when networking.nftables.ruleset or rulesetFile is set
or system.stateVersion is older than 23.11.
Evaluation also fails when networking.nftables.tables has a table that iptables-nft
uses. nftables.service deletes and creates such a table again on each start or reload, and deletes it on stop,
so it replaces the iptables table of the same name. These tables count.
ip natholds the NAT rule of the bridge.ip filterholds the host firewall and the forwarding rules. It counts whilenetworking.firewall.enableornix-bitcoin.netns-isolation.restrictForwardingis on.ip6 filterholds the host firewall for IPv6. It counts withnetworking.firewall.enableandnetworking.enableIPv6.ip mangleandip6 manglehold the reverse path check of the host firewall. They count withnetworking.firewall.enablewhilenetworking.firewall.checkReversePathisn’tfalse. The default is"loose".ip6 manglecounts only withnetworking.enableIPv6.
A firewall that runs pkgs.iptables-legacy as networking.firewall.package is exempt,
since its rules live outside the nftables ruleset.
Put your nftables rules in networking.nftables.tables and turn the flush off. Rename
such a table or use the inet family.
networking.nftables.flushRuleset = false;
networking.nftables.tables.my-rules = {
family = "inet";
content = ''
# Your chains and rules
'';
};
nftables.service keeps the deletions of the config it loaded last and runs them on its
next reload or stop. So the first deploy after such a fix still runs the old flush or
deletes the old table once. This also happens when you fix the config in the same deploy
as this update, so that evaluation doesn’t fail, and when you turn off
networking.nftables. Reboot once after that deploy. Or run these commands as root in
this order.
systemctl reload-or-restart firewall.service
systemctl reload-or-restart nb-netns-forward.service
systemctl restart nb-netns-bridge.service
Skip the first command without networking.firewall.enable and the second without
nix-bitcoin.netns-isolation.restrictForwarding. A reload adds the rules again in place.
A restart of firewall.service or nb-netns-forward.service removes the rules that are
still there before it adds them again, so the host accepts or forwards all traffic for a
moment. The restart of nb-netns-bridge.service also restarts every service in a
namespace.
Empty LND RPC host
If you set services.lnd.rpcAddress to "" or "[]", choose the address LND
should listen on. Remove the setting to use the default loopback address
(127.0.0.1). Set "::" to keep the previous IPv6-only wildcard listener, or
"0.0.0.0" for an IPv4-only wildcard listener. If you supply LND’s TLS
certificate yourself, include the chosen IP address in its subject alternative
names so local gRPC clients can verify it. In OpenSSL notation, the entries
for the two wildcards are IP::: and IP:0.0.0.0, respectively.
bitcoind data dir no longer writable by its group
The bitcoind data dir (services.bitcoind.dataDir, /var/lib/bitcoind by default)
now has mode 0750 instead of 0770. Before, every member of the bitcoind group
(services.bitcoind.group, bitcoin by default) could create, rename and delete
entries in it. The group holds the operator user (with nix-bitcoin.operator.enable)
and the users that you add to it.
The deployment sets the new mode with tmpfiles, which doesn’t follow a symlink. So if
the data dir is a symlink, give its target the owner and mode that tmpfiles would set,
with chown bitcoin:bitcoin and chmod 750 on the target. Use your
services.bitcoind.user and services.bitcoind.group if you changed them.
Group members can still use bitcoin-cli, read the RPC cookie and read the files
they could read before, also the blocks dir with
services.bitcoind.dataDirReadableByGroup. A script that writes to the data dir as a
group member now fails. Run it as the bitcoind user (services.bitcoind.user,
bitcoin by default) or as root.
bitcoind creates its files as the bitcoind user. To list the entries in the data dir
that another user created, run this as root. Use your services.bitcoind.dataDir and
services.bitcoind.user if you changed them.
find /var/lib/bitcoind/ ! -user bitcoin
Stop bitcoind and move each entry that you didn’t create yourself out of the data dir before you start bitcoind again.
Core Lightning replication dirs no longer writable by its group
With services.clightning.replication, two dirs now have mode 0750 instead of
0770, like the Core Lightning data dir.
services.clightning.replication.local.directory, whenlocal.setupDirectoryis on. It holds the replica, or withencryptthe encrypted replica./var/cache/clightning-replication, withsshfs.destinationorencrypt. It holds the mount points of SSHFS and gocryptfs.
Before, every member of the clightning group (services.clightning.group,
clightning by default) could create, rename and delete entries in them. The group
can hold the operator user (with nix-bitcoin.operator.enable), BTCPay Server’s user
(with services.btcpayserver.lightningBackend = "clightning") and the users that you
add to it.
The deployment sets the new modes, and clightning removes write access of the group
and others from the local dir again when it starts. If the local dir belongs to
another user, for example on a share that you set up yourself, clightning can’t change
it. Then make the clightning user its owner and give it mode 0750, on the share’s
server or in its mount options if needed. A server needs the user’s numeric id, which
id -u clightning prints on this node. Check that clightning can still write there,
for example with runuser -u clightning -- test -w <local.directory> && echo writable.
Group members can still read these dirs. A script that writes there as a group member
now fails. Run it as the clightning user (services.clightning.user, clightning by
default) or as root.
clightning creates its files there as the clightning user. After you deploy, list the
entries that another user created. Stop the replication first, because root can’t look
into the mounts, but keep the replica’s disk or share mounted. Then run this as root.
Use your local.directory and services.clightning.user, and leave out what your
config doesn’t use.
systemctl stop clightning-replication-mounts clightning
find /var/backup/clightning /var/cache/clightning-replication ! -user clightning
On a share where root can’t read the local dir, run its find as the clightning user
with runuser -u clightning --, or on the share’s server with ! -uid <id> and the
numeric id from above. lost+found and the entries that you created as root are fine.
Move every other entry out of these dirs, on the share’s server if needed. Then start
clightning again with systemctl start clightning.
dhcpcd control socket
Nodes that use dhcpcd and bitcoinix’s nixpkgs now run dhcpcd 10.5.2.
Since 10.5, only root and dhcpcd’s own user can use its control socket, so commands
like dhcpcd -U and dhcpcd --dumplease fail for other users. Run them as root.
After migrating your configuration, set nix-bitcoin.configVersion = "0.2.1";.