Skip to content

Commit 7b32a78

Browse files
committed
Merge #284: Fix containers
2bfb4ef make-container: fix usage comment (Erik Arvstedt) 3403795 tests: add example scripts (Erik Arvstedt) ff94985 tests: add test 'hardened' (Erik Arvstedt) c8e73c9 fix 'hardened' profile for NixOS 20.09 (Erik Arvstedt) 44b06ae extra-container: 0.5-pre -> 0.5 (Erik Arvstedt) a359cdf generate-secrets: use pwgen (Erik Arvstedt) a5a2fc7 make-container: fix renamed variable (Erik Arvstedt) Pull request description: ACKs for top commit: nixbitcoin: ACK 2bfb4ef jonasnick: utACK 2bfb4ef Tree-SHA512: 421b1fc5bf695d6815f060d129855ae0fecc06f7946ed8ac2bfe53895d7dc9529aad40099fc16844547791010232252f74b1ce32cbc9c6458e6d77f327450e94
2 parents 4195541 + 2bfb4ef commit 7b32a78

File tree

10 files changed

+54
-20
lines changed

10 files changed

+54
-20
lines changed

docs/faq.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,3 @@
3232
* **A:** Check your clightning logs with `journalctl -eu clightning`. Do you see something like `bitcoin-cli getblock ... false` failed? Are you using pruned mode? That means that clightning hasn't seen all the blocks it needs to and it can't get that block because your node is pruned. If you're just setting up a new node you can `systemctl stop clightning` and wipe your `/var/lib/clightning` directory. Otherwise you need to reindex the Bitcoin node.
3333
* **Q:** My disk space is getting low due to nix.
3434
* **A:** run `nix-collect-garbage -d`
35-
* **Q:** `nix-shell` takes too long and doesn't finish generating `/secrets`
36-
* **A:** This might be the result of low system entropy. Check your entropy with `cat /proc/sys/kernel/random/entropy_avail`. If necessary, take steps to increase entropy like performing some tasks on the system or acquiring a hardware true random number generator.

examples/configuration.nix

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
# FIXME: The hardened kernel profile improves security but
1010
# decreases performance by ~50%.
1111
# Turn it off when not needed.
12-
# Source: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/profiles/hardened.nix
13-
<nixpkgs/nixos/modules/profiles/hardened.nix>
12+
<nix-bitcoin/modules/presets/hardened.nix>
1413

1514
# FIXME: Uncomment next line to import your hardware configuration. If so,
1615
# add the hardware configuration file to the same directory as this file.
@@ -208,10 +207,6 @@
208207
# FIXME: Add custom options (like boot options, output of
209208
# nixos-generate-config, etc.):
210209

211-
# If the hardened profile is imported above, we need to explicitly allow
212-
# user namespaces to enable sanboxed builds and services.
213-
security.allowUserNamespaces = true;
214-
215210
# This value determines the NixOS release with which your system is to be
216211
# compatible, in order to avoid breaking some software such as database
217212
# servers. You should change this only after NixOS release notes say you

examples/deploy-qemu-vm.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ if [[ ! -v IN_NIX_SHELL ]]; then
1717
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
1818
fi
1919

20+
cd "${BASH_SOURCE[0]%/*}"
21+
2022
tmpDir=/tmp/nix-bitcoin-qemu-vm
2123
mkdir -p $tmpDir
2224

modules/presets/hardened.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
imports = [
3+
# Source: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/profiles/hardened.nix
4+
<nixpkgs/nixos/modules/profiles/hardened.nix>
5+
];
6+
7+
## Reset some options set by the hardened profile
8+
9+
# Needed for sandboxed builds and services
10+
security.allowUserNamespaces = true;
11+
12+
# The "scudo" allocator is broken on NixOS 20.09
13+
environment.memoryAllocator.provider = "libc";
14+
}

pkgs/extra-container/default.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
stdenv.mkDerivation rec {
66
name = "extra-container-${version}";
7-
version = "0.5-pre";
7+
version = "0.5";
88

99
src = builtins.fetchTarball {
1010
url = "https://github.com/erikarvstedt/extra-container/archive/${version}.tar.gz";
11-
sha256 = "0gdy2dpqrdv7f4kyqz88j34x1p2fpav04kznv41hwqq88hmzap90";
11+
sha256 = "12xqa11v583ajdv51g1833rxvrndmly9h4r62wc3llm8xs6k7ais";
1212
};
1313

1414
buildCommand = ''
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
1717
share=$out/share/extra-container
1818
install $src/eval-config.nix -Dt $share
1919
20-
# Use existing PATH for systemctl and machinectl (for nixos-container)
20+
# Use existing PATH for systemctl and machinectl
2121
scriptPath="export PATH=${lib.makeBinPath [ nixos-container openssh ]}:\$PATH"
2222
2323
sed -i \

pkgs/generate-secrets/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ let
1010
'';
1111
in
1212
writers.writeBash "generate-secrets" ''
13-
export PATH=${lib.makeBinPath [ coreutils apg openssl gnugrep rpcauth ]}
13+
export PATH=${lib.makeBinPath [ coreutils pwgen openssl gnugrep rpcauth ]}
1414
. ${./generate-secrets.sh} ${./openssl.cnf}
1515
''

pkgs/generate-secrets/generate-secrets.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ set -euo pipefail
55
opensslConf=${1:-openssl.cnf}
66

77
makePasswordSecret() {
8-
[[ -e $1 ]] || apg -m 20 -x 20 -M Ncl -n 1 > "$1"
8+
# Passwords have alphabet {a-z, A-Z, 0-9} and ~119 bits of entropy
9+
[[ -e $1 ]] || pwgen -s 20 1 > "$1"
910
}
1011
makeHMAC() {
1112
user=$1

test/lib/make-container.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# This args disables auto-destructing containers.
2929
#
3030
#
31-
# run-tests.sh container --run|-r c systemctl status bitcoind
31+
# run-tests.sh container --run c systemctl status bitcoind
3232
#
3333
# Run a command in the shell session environmentand exit.
3434
# Destroy the container afterwards.
@@ -39,7 +39,7 @@
3939
# run-tests.sh container --run c
4040
#
4141
#
42-
# run-tests.sh [--scenario|-s <scenario>] container --command|--c
42+
# run-tests.sh [--scenario|-s <scenario>] container --command|-c
4343
#
4444
# Provide a custom extra-container command.
4545
#
@@ -57,8 +57,8 @@ if [[ $EUID != 0 ]]; then
5757
# NixOS containers require root permissions.
5858
# By using sudo here and not at the user's call-site extra-container can detect if it is running
5959
# inside an existing shell session (by checking an internal environment variable).
60-
exec sudo scenario="$scenario" testDir="$testDir" NIX_PATH="$NIX_PATH" PATH="$PATH" \
61-
scenarioOverridesFile="${scenarioOverridesFile:-}" "$testDir/lib/make-container.sh" "$@"
60+
exec sudo scenario="$scenario" scriptDir="$scriptDir" NIX_PATH="$NIX_PATH" PATH="$PATH" \
61+
scenarioOverridesFile="${scenarioOverridesFile:-}" "$scriptDir/lib/make-container.sh" "$@"
6262
fi
6363

6464
export containerName=nb-test
@@ -79,11 +79,11 @@ done
7979
containerBin=$(type -P extra-container) || true
8080
if [[ ! ($containerBin && $(realpath $containerBin) == *extra-container-0.5*) ]]; then
8181
echo "Building extra-container. Skip this step by adding extra-container 0.5 to PATH."
82-
nix-build --out-link /tmp/extra-container "$testDir"/../pkgs -A extra-container >/dev/null
82+
nix-build --out-link /tmp/extra-container "$scriptDir"/../pkgs -A extra-container >/dev/null
8383
export PATH="/tmp/extra-container/bin${PATH:+:}$PATH"
8484
fi
8585

8686
read -d '' src <<EOF || true
87-
(import "$testDir/tests.nix" { scenario = "$scenario"; }).container
87+
(import "$scriptDir/tests.nix" { scenario = "$scenario"; }).container
8888
EOF
8989
exec extra-container $containerCommand -E "$src" "$@"

test/run-tests.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,27 @@ basic() {
202202
pkgsUnstable
203203
}
204204

205-
all() {
205+
# All tests that only consist of building a nix derivation.
206+
# Their output is cached in /nix/store.
207+
buildable() {
206208
basic
207209
scenario=full buildTest "$@"
208210
scenario=regtest buildTest "$@"
211+
scenario=hardened buildTest "$@"
212+
}
213+
214+
examples() {
215+
script="
216+
set -e
217+
./deploy-container.sh
218+
./deploy-qemu-vm.sh
219+
"
220+
(cd $scriptDir/../examples && nix-shell --run "$script")
221+
}
222+
223+
all() {
224+
buildable
225+
examples
209226
}
210227

211228
# An alias for buildTest

test/tests.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ let testEnv = rec {
165165
imports = with scenarios; [ netnsBase regtest ];
166166
};
167167

168+
hardened = {
169+
imports = [
170+
scenarios.secureNode
171+
../modules/presets/hardened.nix
172+
];
173+
};
174+
168175
netnsBase = {
169176
nix-bitcoin.netns-isolation.enable = true;
170177
test.data.netns = config.nix-bitcoin.netns-isolation.netns;

0 commit comments

Comments
 (0)