Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix systemd leak #213

Merged
merged 2 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions modules/dbus.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{ config, lib, pkgs, ... }:

with lib;

let
inherit (config) nix-bitcoin-services;
dataDir = "/var/lib/dbus-hardening";
# Mitigates a security issue that allows unprivileged users to read
# other unprivileged user's processes' credentials from CGroup using
# `systemctl status`.
dbus-hardening = pkgs.writeText "dbus.conf" ''
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->

<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">

<busconfig>
<policy user="root">
<allow send_destination="org.freedesktop.systemd1"
send_interface="org.freedesktop.systemd1.Manager"
send_member="GetUnitProcesses"/>
</policy>

<policy context="mandatory">
<deny send_destination="org.freedesktop.systemd1"
send_interface="org.freedesktop.systemd1.Manager"
send_member="GetUnitProcesses"/>
</policy>
</busconfig>
'';
in {
config = {
systemd.tmpfiles.rules = [
"d '${dataDir}/etc/dbus-1/system.d' 0770 messagebus messagebus - -"
];

services.dbus.packages = [ "${dataDir}" ];

systemd.services.hardeneddbus = {
description = "Install hardeneddbus";
wantedBy = [ "multi-user.target" ];
script = ''
cp ${dbus-hardening} ${dataDir}/etc/dbus-1/system.d/dbus.conf
chmod 640 ${dataDir}/etc/dbus-1/system.d/dbus.conf
'';
serviceConfig = nix-bitcoin-services.defaultHardening // {
PrivateNetwork = "true";
Type = "oneshot";
User = "messagebus";
ReadWritePaths = "${dataDir}";
};
};
};
}
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
./lnd.nix
./secrets/secrets.nix
./netns-isolation.nix
./dbus.nix
];

disabledModules = [ "services/networking/bitcoind.nix" ];
Expand Down
3 changes: 3 additions & 0 deletions modules/presets/secure-node.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ in {

networking.firewall.enable = true;

# hideProcessInformation even if hardened kernel profile is disabled
security.hideProcessInformation = true;

# Tor
services.tor = {
enable = true;
Expand Down
7 changes: 7 additions & 0 deletions test/scenarios/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
machine.wait_until_succeeds(log_has_string("bitcoind-import-banlist", "Importing node banlist"))
assert_no_failure("bitcoind-import-banlist")

# test that `systemctl status` can't leak credentials
assert_matches(
"sudo -u electrs systemctl status clightning 2>&1 >/dev/null",
"Failed to dump process list for 'clightning.service', ignoring: Access denied",
)
machine.succeed("grep -Fq hidepid=2 /proc/mounts")

### Additional tests

# Current time in µs
Expand Down
7 changes: 7 additions & 0 deletions test/scenarios/withnetns.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@
# test that netns-exec can not be executed by users that are not operator
machine.fail("sudo -u clightning netns-exec nb-bitcoind ip a")

# test that `systemctl status` can't leak credentials
assert_matches(
"sudo -u electrs systemctl status clightning 2>&1 >/dev/null",
"Failed to dump process list for 'clightning.service', ignoring: Access denied",
)
machine.succeed("grep -Fq hidepid=2 /proc/mounts")

### Additional tests

# Current time in µs
Expand Down