@mark1russell7/harness 0.16.3 → 0.16.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/schema.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as ImageSource, Mt as Subject, i as Client, o as ClientImage } from "./cell-CXxqXp1q.js";
1
+ import { M as ImageSource, Mt as Subject, i as Client, o as ClientImage } from "./cell-Ckoqr7Xc.js";
2
2
  import { z } from "zod";
3
3
  /**
4
4
  * This schema accepts the source of an image (`ImageSource`). It is a pinned image with its digest,
package/build/schema.js CHANGED
@@ -1,4 +1,4 @@
1
- import { D as subjectProblems, a as SHIPPED_NAMES, h as imageProblems, t as CLIENT_NAMES, z as CLIENT_CAPABILITIES } from "./image-D509StXX.js";
1
+ import { B as CLIENT_CAPABILITIES, O as subjectProblems, a as SHIPPED_NAMES, h as imageProblems, t as CLIENT_NAMES } from "./image-Bs5hV85M.js";
2
2
  import { z } from "zod";
3
3
  // src/schema.ts
4
4
  /** This function adds each problem that a check finds as an issue of a schema. */
@@ -0,0 +1,54 @@
1
+ # LazyFS of the commit 3edad01, the disk tier of the harness. LazyFS is a FUSE file system that keeps
2
+ # each write in its own cache until an fsync. The command lazyfs::clear-cache loses each write after
3
+ # the last fsync: the state of the disk after a power cut. The build gets the tarball of the commit and
4
+ # the two sources that libpcache fetches (toml11 v3.7.1 and spdlog v1.10.0), and checks the SHA-256 of
5
+ # each before it builds. Thus the build fetches nothing that the file does not pin.
6
+ #
7
+ # The runtime stage has Node.js 24, thus a subject writes its files with node:sqlite or with node:fs.
8
+ # The container needs /dev/fuse and the capability of a mount: the disk tier starts it privileged.
9
+ FROM node:24.21.0-bookworm-slim@sha256:d6aa754f16b3197301076f047b5def2f02ea1dbbc2ca920407d46d7ec7f87b20 AS build
10
+ RUN apt-get update \
11
+ && apt-get install -y --no-install-recommends g++ make cmake libfuse3-dev curl ca-certificates \
12
+ && rm -rf /var/lib/apt/lists/*
13
+ ARG LAZYFS=3edad01aa936b81fed9bd64e47e725fc5ef6c977
14
+ ARG LAZYFS_SHA256=9c5004c4f704f059120daa2934a38a45002bda67ebd9e2d16a066a3499f5959d
15
+ ARG TOML11_SHA256=afeaa9aa0416d4b6b2cd3897ca55d9317084103077b32a852247d8efd4cf6068
16
+ ARG SPDLOG_SHA256=697f91700237dbae2326b90469be32b876b2b44888302afbc7aceb68bcfe8224
17
+ WORKDIR /src
18
+ RUN curl -fsSL -o /tmp/lazyfs.tar.gz "https://codeload.github.com/dsrhaslab/lazyfs/tar.gz/${LAZYFS}" \
19
+ && curl -fsSL -o /tmp/toml11.tar.gz "https://codeload.github.com/ToruNiina/toml11/tar.gz/refs/tags/v3.7.1" \
20
+ && curl -fsSL -o /tmp/spdlog.tar.gz "https://github.com/gabime/spdlog/archive/v1.10.0.tar.gz" \
21
+ && echo "${LAZYFS_SHA256} /tmp/lazyfs.tar.gz" | sha256sum -c - \
22
+ && echo "${TOML11_SHA256} /tmp/toml11.tar.gz" | sha256sum -c - \
23
+ && echo "${SPDLOG_SHA256} /tmp/spdlog.tar.gz" | sha256sum -c - \
24
+ && tar -xzf /tmp/lazyfs.tar.gz --strip-components=1 \
25
+ && mkdir -p libs/libpcache/build/_deps/toml-src libs/libpcache/build/_deps/spdlog-src \
26
+ && tar -xzf /tmp/toml11.tar.gz -C libs/libpcache/build/_deps/toml-src --strip-components=1 \
27
+ && tar -xzf /tmp/spdlog.tar.gz -C libs/libpcache/build/_deps/spdlog-src --strip-components=1
28
+ # The CMake file of lazyfs reads the headers of spdlog from build/_deps/spdlog-src of libpcache. Thus
29
+ # the sources go to the folders that FetchContent uses, and FetchContent gets them from there.
30
+ RUN cd libs/libpcache/build \
31
+ && cmake -DFETCHCONTENT_SOURCE_DIR_TOML=/src/libs/libpcache/build/_deps/toml-src \
32
+ -DFETCHCONTENT_SOURCE_DIR_SPDLOG=/src/libs/libpcache/build/_deps/spdlog-src .. \
33
+ && cmake --build . -j2 \
34
+ && mkdir -p /src/lazyfs/build \
35
+ && cd /src/lazyfs/build \
36
+ && cmake -DLAZYFS_BUILD_TESTS=OFF .. \
37
+ && cmake --build . -j2 \
38
+ && mkdir -p /out/bin /out/lib \
39
+ && install -m 0755 lazyfs /out/bin/lazyfs \
40
+ && cp -a /src/libs/libpcache/build/libpcache.so* /out/lib/
41
+
42
+ FROM node:24.21.0-bookworm-slim@sha256:d6aa754f16b3197301076f047b5def2f02ea1dbbc2ca920407d46d7ec7f87b20
43
+ RUN apt-get update \
44
+ && apt-get install -y --no-install-recommends fuse3 \
45
+ && rm -rf /var/lib/apt/lists/* \
46
+ && sed -i 's/^#user_allow_other/user_allow_other/' /etc/fuse.conf \
47
+ && mkdir -p /etc/lazyfs /run/lazyfs /var/disk /mnt/disk /opt/subject
48
+ COPY --from=build /out/bin/ /usr/local/bin/
49
+ # A copy of a folder keeps the links of the library (libpcache.so to libpcache.so.0)
50
+ COPY --from=build /out/lib/ /usr/local/lib/
51
+ RUN ldconfig
52
+ COPY harness/image/lazyfs/config.toml /etc/lazyfs/config.toml
53
+ COPY harness/image/lazyfs/start.mts /usr/local/lib/lazyfs/start.mts
54
+ CMD ["node", "--disable-warning=ExperimentalWarning", "/usr/local/lib/lazyfs/start.mts"]
@@ -0,0 +1,16 @@
1
+ # The configuration of LazyFS in the disk tier. The cache holds each write until an fsync, and it does
2
+ # not evict a page: thus lazyfs::clear-cache loses each write after the last fsync, and no other write.
3
+ [faults]
4
+ fifo_path="/run/lazyfs/faults.fifo"
5
+ fifo_path_completed="/run/lazyfs/done.fifo"
6
+
7
+ [cache]
8
+ apply_eviction=false
9
+
10
+ [cache.simple]
11
+ custom_size="1gb"
12
+ blocks_per_page=1
13
+
14
+ [filesystem]
15
+ log_all_operations=false
16
+ logfile=""
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The command of the image `lazyfs`. It starts LazyFS in the foreground: `/mnt/disk` is the mount, and `/var/disk`
3
+ * holds the files. Node.js 24 of the image strips the types of this file.
4
+ *
5
+ * LazyFS opens `done.fifo` to write, and that open waits for a reader. LazyFS gets a reader of `done.fifo` as its
6
+ * descriptor 3, and this process keeps the reader open. Thus LazyFS starts at once, and a write after a reader went away
7
+ * does not stop it.
8
+ *
9
+ * This process is PID 1 of the container. It gives `SIGTERM` and `SIGINT` to LazyFS, and it ends with the exit of LazyFS.
10
+ */
11
+ import { execFileSync, spawn } from "node:child_process";
12
+ import { constants, openSync } from "node:fs";
13
+ import { constants as os } from "node:os";
14
+
15
+ const FAULTS = "/run/lazyfs/faults.fifo";
16
+ const DONE = "/run/lazyfs/done.fifo";
17
+
18
+ execFileSync("mkfifo", [FAULTS, DONE], { stdio: "inherit" });
19
+ // On Linux, an open of a FIFO to read and write does not wait for the other end, the same as `exec 3<>` of a shell
20
+ const reader = openSync(DONE, constants.O_RDWR);
21
+ const lazyfs = spawn(
22
+ "/usr/local/bin/lazyfs",
23
+ ["/mnt/disk", "--config-path", "/etc/lazyfs/config.toml", "-o", "allow_other", "-o", "modules=subdir", "-o", "subdir=/var/disk", "-f"],
24
+ { stdio: ["inherit", "inherit", "inherit", reader] },
25
+ );
26
+ for (const signal of ["SIGTERM", "SIGINT"] as const) process.on(signal, () => lazyfs.kill(signal));
27
+ lazyfs.on("error", (error) => {
28
+ console.error(`LazyFS did not start: ${error.message}`);
29
+ process.exit(1);
30
+ });
31
+ lazyfs.on("exit", (code, signal) => {
32
+ process.exit(code ?? (signal === null ? 1 : 128 + os.signals[signal]));
33
+ });
@@ -13,9 +13,10 @@
13
13
  //! what comes from the peer, `out` what goes to it: a simplex partition.
14
14
  //! - `rst PEER [--handshake pass]` / `clear-rst PEER […]`: the peer's next segment is answered with
15
15
  //! a reset, so its next send fails at once. A REJECT resets only the sender of the matched
16
- //! segment: the target's process never hears of it. With `--handshake pass` a SYN passes
17
- //! (`! --syn`), so a connect succeeds and the first segment after the SYN gets the reset: the
18
- //! last ACK of the handshake, or the first data.
16
+ //! segment: the process of the target does not see the reset. With `--handshake pass` each
17
+ //! SYN and each segment with no data passes, and the first segment with data gets the reset.
18
+ //! Thus the handshake completes, the target accepts the connection, and the first send of the
19
+ //! peer fails.
19
20
  //! - `reject PEER --code host|net|port|admin [--direction in|out|both] [--protocol …]` /
20
21
  //! `clear-reject PEER --code …`: each segment from the peer is answered with that ICMP
21
22
  //! unreachable. On an established socket Linux keeps it as a soft error (tcp_v4_err) and goes on
@@ -139,11 +140,25 @@ struct Options {
139
140
  via: Option<String>,
140
141
  }
141
142
 
142
- /// The match of the handshake in a reset: nothing, or ` ! --syn` when the SYN passes.
143
- fn handshake_match(handshake: Option<&str>) -> Result<&'static str, Box<dyn Error>> {
143
+ /// The u32 test of a segment with data: one byte or more after the TCP header. The connection
144
+ /// tracker gives the last ACK of a handshake the state ESTABLISHED, thus a match of the state cannot
145
+ /// tell that ACK from data. A u32 read takes 4 bytes and fails past the end of the packet. Thus the
146
+ /// test reads the 4 bytes that start 3 bytes before the end of the headers.
147
+ ///
148
+ /// - `0>>24&0xF1=0x41`: IPv4, and an IP header of an odd number of words. A header with no options
149
+ /// has 5 words. An IP header of an even number of words does not match: the labs send no options.
150
+ /// - `0>>22&0x38`: the length of the IP header less 4 bytes. The mask clears bit 2, and an odd
151
+ /// number of words always sets that bit.
152
+ /// - `@16>>26&0x3C`: the length of the TCP header, from the word of the data offset (TCP byte 12).
153
+ /// - `@1&0=0`: the read at the end of the headers less 3 bytes. It gets 4 bytes only when data follows.
154
+ const DATA: &str = "0>>24&0xF1=0x41&&0>>22&0x38@16>>26&0x3C@1&0=0";
155
+
156
+ /// The match of the handshake in a reset: nothing, or, when the handshake passes, ` ! --syn` and the
157
+ /// test of data. The last ACK of the handshake has no data, thus it passes too.
158
+ fn handshake_match(handshake: Option<&str>) -> Result<String, Box<dyn Error>> {
144
159
  Ok(match handshake {
145
- None => "",
146
- Some("pass") => " ! --syn",
160
+ None => String::new(),
161
+ Some("pass") => format!(" ! --syn -m u32 --u32 {DATA}"),
147
162
  Some(other) => return Err(format!("unknown handshake {other}: say pass").into()),
148
163
  })
149
164
  }
@@ -217,8 +232,8 @@ fn rules(action: &str, peer: Ipv4Addr, opts: &Options) -> Result<String, Box<dyn
217
232
  format!("{op} {to}{p} -j DROP\n"),
218
233
  )?
219
234
  }
220
- // with the handshake that passes, a SYN goes through and the reset answers the segment
221
- // after it: the connect succeeds, and the first exchange on it fails
235
+ // with the handshake that passes, the SYN and each segment with no data go through, and the
236
+ // reset answers the first segment with data: the target accepts, and the first send fails
222
237
  "rst" | "clear-rst" => {
223
238
  let op = op("rst");
224
239
  let syn = handshake_match(opts.handshake.as_deref())?;
@@ -798,7 +813,7 @@ mod tests {
798
813
  }
799
814
 
800
815
  #[test]
801
- fn a_reset_after_the_handshake_lets_each_syn_pass() {
816
+ fn a_reset_after_the_handshake_lets_each_syn_and_each_segment_with_no_data_pass() {
802
817
  let peer: Ipv4Addr = "10.0.0.2".parse().unwrap();
803
818
  let pass = Options { handshake: Some("pass".into()), ..Options::default() };
804
819
  // without the option, the rule is the one from before: the SYN gets the reset too
@@ -806,15 +821,17 @@ mod tests {
806
821
  rules("rst", peer, &Options::default()).unwrap(),
807
822
  "-I INPUT -s 10.0.0.2/32 -p tcp -j REJECT --reject-with tcp-reset\n"
808
823
  );
824
+ // one token for iptables-restore: the test has no space
825
+ assert!(!DATA.contains(' '));
809
826
  assert_eq!(
810
827
  rules("rst", peer, &pass).unwrap(),
811
- "-I INPUT -s 10.0.0.2/32 -p tcp ! --syn -j REJECT --reject-with tcp-reset\n"
828
+ format!("-I INPUT -s 10.0.0.2/32 -p tcp ! --syn -m u32 --u32 {DATA} -j REJECT --reject-with tcp-reset\n")
812
829
  );
813
830
  assert_eq!(rules("clear-rst", peer, &pass).unwrap(), rules("rst", peer, &pass).unwrap().replace("-I ", "-D "));
814
831
  let via = Options { handshake: Some("pass".into()), via: Some("eth0".into()), ..Options::default() };
815
832
  assert_eq!(
816
833
  rules("rst", peer, &via).unwrap(),
817
- "-I FORWARD -i eth0 -s 10.0.0.2/32 -p tcp ! --syn -j REJECT --reject-with tcp-reset\n"
834
+ format!("-I FORWARD -i eth0 -s 10.0.0.2/32 -p tcp ! --syn -m u32 --u32 {DATA} -j REJECT --reject-with tcp-reset\n")
818
835
  );
819
836
  // the one value is pass, and only a reset takes it
820
837
  assert!(options(&["--handshake".into(), "drop".into()]).is_err());
@@ -825,6 +842,93 @@ mod tests {
825
842
  }
826
843
  }
827
844
 
845
+ /// The match of xt_u32 (net/netfilter/xt_u32.c, u32_match_it) on the bytes of one IP packet. A
846
+ /// read of 4 bytes past the end of the packet fails the match, as in the kernel.
847
+ fn u32_matches(expression: &str, packet: &[u8]) -> bool {
848
+ let len = packet.len() as u64;
849
+ let word = |at: u64| u32::from_be_bytes(packet[at as usize..at as usize + 4].try_into().unwrap());
850
+ let number = |text: &str| match text.strip_prefix("0x") {
851
+ Some(hex) => u32::from_str_radix(hex, 16).unwrap(),
852
+ None => text.parse().unwrap(),
853
+ };
854
+ expression.split("&&").all(|test| {
855
+ let (location, values) = test.split_once('=').unwrap();
856
+ // the numbers of the location, each after its operator: the first one has none
857
+ let mut steps: Vec<(&str, u32)> = Vec::new();
858
+ let mut rest = location;
859
+ let mut op = "";
860
+ while !rest.is_empty() {
861
+ let end = rest.find(|c: char| "&@<>".contains(c)).unwrap_or(rest.len());
862
+ steps.push((op, number(&rest[..end])));
863
+ rest = &rest[end..];
864
+ op = ["<<", ">>", "&", "@"].into_iter().find(|each| rest.starts_with(each)).unwrap_or("");
865
+ rest = &rest[op.len()..];
866
+ }
867
+ let first = u64::from(steps[0].1);
868
+ if len < 4 || first > len - 4 {
869
+ return false;
870
+ }
871
+ let mut at = 0u64;
872
+ let mut val = word(first);
873
+ for &(op, n) in &steps[1..] {
874
+ match op {
875
+ "&" => val &= n,
876
+ "<<" => val <<= n,
877
+ ">>" => val >>= n,
878
+ _ => {
879
+ at += u64::from(val);
880
+ if at + 4 > len || u64::from(n) > len - at - 4 {
881
+ return false;
882
+ }
883
+ val = word(at + u64::from(n));
884
+ }
885
+ }
886
+ }
887
+ values.split(',').any(|range| {
888
+ let (low, high) = range.split_once(':').unwrap_or((range, range));
889
+ number(low) <= val && val <= number(high)
890
+ })
891
+ })
892
+ }
893
+
894
+ /// An IPv4 packet of TCP: `ihl` and `doff` are the lengths of its headers in words of 4 bytes,
895
+ /// and `data` bytes follow them.
896
+ fn segment(ihl: usize, doff: usize, data: usize) -> Vec<u8> {
897
+ let len = 4 * ihl + 4 * doff + data;
898
+ let mut bytes = vec![0xA5u8; len];
899
+ bytes[0] = 0x40 | ihl as u8;
900
+ // a TOS with each bit set: its 2 high bits are in the word of the IP length, and the masks drop them
901
+ bytes[1] = 0xFF;
902
+ bytes[2..4].copy_from_slice(&(len as u16).to_be_bytes());
903
+ bytes[9] = 6;
904
+ // the reserved bits and AE after the data offset, each set: the mask drops them
905
+ bytes[4 * ihl + 12] = (doff as u8) << 4 | 0x0F;
906
+ bytes
907
+ }
908
+
909
+ #[test]
910
+ fn the_test_of_data_needs_one_byte_after_the_tcp_header() {
911
+ // the model agrees with the rule of the MTU drop, a test that the kernel also applies
912
+ assert!(u32_matches("0&0xFFFF=1201:65535", &segment(5, 8, 1149)));
913
+ assert!(!u32_matches("0&0xFFFF=1201:65535", &segment(5, 8, 1148)));
914
+ // a header with no options (5 words), with timestamps (8), with each option (15), and an IP
915
+ // header with options (7 and 15 words)
916
+ for (ihl, doff) in [(5, 5), (5, 8), (5, 15), (7, 8), (15, 15)] {
917
+ assert!(!u32_matches(DATA, &segment(ihl, doff, 0)), "{ihl} {doff}, with no data");
918
+ for data in [1, 2, 3, 4, 5, 1448] {
919
+ assert!(u32_matches(DATA, &segment(ihl, doff, data)), "{ihl} {doff}, with {data} bytes");
920
+ }
921
+ }
922
+ // an IP header of an even number of words does not match, with data or with none
923
+ for data in [0, 1, 100] {
924
+ assert!(!u32_matches(DATA, &segment(6, 8, data)), "6 8, with {data} bytes");
925
+ }
926
+ // a packet of IPv6 does not match
927
+ let mut six = segment(5, 8, 10);
928
+ six[0] = 0x65;
929
+ assert!(!u32_matches(DATA, &six));
930
+ }
931
+
828
932
  #[test]
829
933
  fn a_fin_takes_one_step_of_the_mark_and_only_the_first_ack_drops() {
830
934
  let peer: Ipv4Addr = "10.0.0.2".parse().unwrap();
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/harness",
4
- "version": "0.16.3",
5
- "description": "Network labs in Docker, declared as data. A cell builds a topology of networks, routers and proxies around a stock target. It injects a fault at layer 3 or 4 from a NET_ADMIN sidecar, measures the records of the kernel and judges a prediction. The faults are black holes, resets, ICMP unreachable, one-way and MTU drops, tc netem, the toxics of Toxiproxy and frozen processes. Its replicated groups are Redis with Sentinels, MongoDB replica sets, PostgreSQL standbys, Kafka, RabbitMQ and BGP fabrics with BFD. A lab can also operate in a QEMU guest. Its first use is connection timers: keep-alive, TCP retransmission, heartbeats and reconnects.",
4
+ "version": "0.16.5",
5
+ "description": "Network labs in Docker, declared as data. A cell builds a topology of networks, routers and proxies around a stock target. It injects a fault at layer 3 or 4 from a NET_ADMIN sidecar, measures the records of the kernel and judges a prediction. The faults are black holes, resets, ICMP unreachable, one-way and MTU drops, tc netem, the toxics of Toxiproxy and frozen processes. Its disk tier cuts the power of a program on LazyFS: the disk loses each write after the last fsync. Its replicated groups are Redis with Sentinels, MongoDB replica sets, PostgreSQL standbys, Kafka, RabbitMQ and BGP fabrics with BFD. A lab can also operate in a QEMU guest. Its first use is connection timers: keep-alive, TCP retransmission, heartbeats and reconnects.",
6
6
  "keywords": [
7
7
  "fault-injection",
8
8
  "chaos-engineering",
@@ -18,7 +18,9 @@
18
18
  "toxiproxy",
19
19
  "replica-set",
20
20
  "bgp",
21
- "qemu"
21
+ "qemu",
22
+ "lazyfs",
23
+ "power-loss"
22
24
  ],
23
25
  "homepage": "https://mark1russell7.github.io/systems/",
24
26
  "repository": {
@@ -105,6 +107,9 @@
105
107
  "image/pgbouncer/Dockerfile",
106
108
  "image/pgpool/Dockerfile",
107
109
  "image/docker-proxy/Dockerfile",
110
+ "image/lazyfs/Dockerfile",
111
+ "image/lazyfs/config.toml",
112
+ "image/lazyfs/start.mts",
108
113
  "README.md",
109
114
  "LICENSE"
110
115
  ],
@@ -115,8 +120,9 @@
115
120
  "@mark1russell7/prober": "^0.3.4",
116
121
  "@mark1russell7/quantity": "^0.4.1",
117
122
  "@mark1russell7/rigor-bench": "^0.2.10",
118
- "@mark1russell7/rigor-chaos": "^0.2.2",
123
+ "@mark1russell7/rigor-chaos": "^0.3.3",
119
124
  "@mark1russell7/rigor-statistics": "^0.2.1",
125
+ "@mark1russell7/rigor-testkit": "^0.1.14",
120
126
  "testcontainers": "12.2.1"
121
127
  },
122
128
  "peerDependencies": {