Skip to content

emfor 0.8.0

Latest

Choose a tag to compare

@vanillahsu vanillahsu released this 25 Nov 10:04
· 29 commits to main since this release

Breaking. Interfaces that docs/compatibility.md lists as stable and that
change in this release:

  • Credential files must be regular files of bounded size. A
    password_file, a RADIUS secret_file, a tls_key_file, a tls_cert_file
    or a ca_file that is a FIFO, a device or a directory, or larger than the
    limit (64 KiB; tls_cert_file and tls_key_file 1 MiB; ca_file 8 MiB),
    is refused now (a directory already failed with a read error; only its
    message changed). A link to a regular file still works. Details below.
  • A heartbeat far in the future counts as stale. Clients stop taking the
    store for fresh when the host clock was set back by more than
    EMFOR_MAX_STALENESS. emfor status does the same with a fixed 3 s, and
    its exit status is 1 now where it was 0. A lookup in such a store sees
    every backend as unknown, in emfor lookup and in the client of every
    language: a closed service gives ALL_DOWN (exit status 1 of emfor lookup) where it gave an address, and an open service may give a backend
    that is unhealthy. Exit statuses and answers are stable interfaces. Details
    below.
  • heartbeat_age_ms can be negative. In emfor status --json and in
    emfor lookup --explain --json (store.heartbeat_age_ms), when the
    heartbeat is later than the clock of the reader. A parser that expects a
    number of at least 0 has to accept a negative one.
  • Rust API: Explanation.heartbeat_age_ms in emfor-client is an i64
    now (it was a u64).

Upgrading.

  • libemfor is libemfor.so.0.8 now (it was libemfor.so.0.7). A program
    linked against the C library has to be built again, and the Python, Perl,
    PHP and Go clients of this release load the new name. Install the new
    library next to the old one and move the programs one by one; the old file
    stays until the last one is moved.

  • Upgrade every member of a peer group before setting [peers] cipher = "aes-256-gcm": an earlier version counts EMP4 as malformed.

  • A config that uses a key added here ([log] format, [peers] cipher,
    [metrics] allow, an http check's ca_file) fails emfor check-config
    on an earlier version, so take it out before a downgrade.

  • A reload now writes up to 51 lines about what it changed (50 and one for
    the rest), and every start
    and reload logs the SHA-256 of each config file it reads.

  • After the upgrade, emfor status and /metrics have new lines and series
    (clock offsets and silent checkers of peer members, emfor_clock_jumps_total).

  • Three small fixes around the clock of peer members and the log, and a
    threat-model note.
    None of them is a stable interface.

    • A clock offset state that ends because no measurement of the member
      arrived for 10 s now logs no clock offset of peer … measured for 10 s; the clock offset state is cleared (info). It used to say within limits again, which is kept for a member that is back below the limit.
    • emfor status shows clock of this host differs from every member only
      when every member is off in the same direction (all ahead or all
      behind). With members on both sides of this host, it lists the members one
      by one.
    • With [log] format = "json", the config file read lines of a start are
      JSON, like those of a reload. Lines before the format is known (plugin
      start, config errors, warnings about the config files) stay text.
    • docs/threat-model.md says what the clock measurement does not cover: a
      recorded datagram sent again with the source address of a member from
      which nothing was accepted yet can make that member look off in
      monitoring. Votes are not affected.
  • The daemon logs a jump of the host clock. At each heartbeat (once a
    second) it compares how far the wall clock moved with how far a monotonic
    clock moved; when they differ by more than 2 seconds it writes a warn
    line with event=clock_jumped, direction (forward or backward) and
    jump_ms, and emfor_clock_jumps_total counts it. A busy or late tick
    moves both clocks alike and is not reported. At most one line is written
    every 10 seconds; every jump is still counted. The fields of this line are
    not stable. Nothing else changed: the heartbeat, the store and the client's
    staleness decision are the same. Chapters 12 and 16 (en and zh_TW) say how
    to alert on it. Measured on FreeBSD 15.1 (arm64 VM): 6 busy yes loops and
    a looping dd for 11 minutes (about 675 ticks) gave a largest difference
    of 1 ms and no line; setting the clock +30 s, -45 s (3 s later) and +15 s
    (12 s later) gave three counts and two lines (forward 29.7 s, forward
    15.0 s), the -45 s step being counted but not logged inside the 10 s
    period. A second run stepped the clock +30 s, then -45 s 12 s later, then
    +15 s 3 s after that: two lines (forward 29.1 s, backward 45.0 s) and three
    counts. The same load for 10 minutes in a Debian container on Linux 7.2 (arm64,
    597 ticks) also gave a largest difference of 1 ms and no line; the clock
    was not stepped there, because a container shares the host's clock. Not
    measured: x86-64, a host that suspends and resumes. The 2-second threshold
    and the 10-second period are choices, not tuned values.

  • A threat model page. New docs/threat-model.md says what emfor
    protects, which boundaries an attacker can reach (backends, plugins, DNS,
    /metrics, the peer UDP port, local users), where each defense is and which
    gaps are open; SECURITY.md links to it. It comes from reading the code,
    not from a penetration test. It records that the peers check the sender
    against the UDP source address only, and what that allows: one member that
    holds the secret cannot turn a backend down (2 of its 3 assigned checkers
    must say down), two colluding members can. Nothing in the code changed.

  • The manual says how to read emfor with Vector. Chapter 14 (en and
    zh_TW) has a Vector section: the prometheus_scrape source for /metrics,
    and the JSON log through a remap with parse_json!, from a file, from
    the journal (journald needs a data_dir) or, on FreeBSD, through a sed
    that cuts the syslog prefix into the stdin source. New
    examples/vector/ has the three configs, and tests/vector/run.sh and
    tests/vector/journald.sh (docker, by hand, not by the CI) ran them with
    Vector 0.62.0. Vector itself was not run on FreeBSD: the 15.1 arm64
    package repository has no Vector package. Nothing in emfor changed.

  • The manual says how to keep emfor on some CPU cores. Chapter 12 (en and
    zh_TW): CPUAffinity= in a drop-in, tried on Rocky Linux 9.9 (the daemon and
    its exec checks follow it). docs/performance.md reports that pinning
    threads with taskset did not raise lookup speed. No change to the program.

  • The manual says what was run for ping and SCTP checks. Chapter 6 (en and
    zh_TW), "Ping and SCTP": the exec recipes were run under the packaged unit
    on Rocky Linux 9.9 and Ubuntu 24.04 (arm64, virtual machines). On Ubuntu the
    ping check failed for every backend until net.ipv4.ping_group_range
    included the emfor group (runuser -u emfor -- ping works there and is no
    proof); Rocky allows every group. SCTP through a Python script worked on both,
    after installing kernel-modules-extra and lifting the module blacklist on
    Rocky. Use a check timeout longer than ping -W. We still do not plan a
    built-in ICMP or SCTP check. Not tried on x86-64 or with IPv6.

  • examples/snmp/emfor-snmp-trap.sh sent nothing when a service went all
    down.
    emfor status --json exits 1 then (and when the daemon is stale or
    stopped) but still prints the history; the script treated every non-zero
    exit as a failure and stopped, so the trap for the last backend going down
    came only after something recovered. It now stops only on exit 2 or no
    output. Chapter 14 (en and zh_TW) now says the script and the snmpd extend
    line were run against snmptrapd and snmpd 5.9.3 in a Debian 12
    container, that every backend sends an unknown to healthy trap after a
    daemon restart, and that snmpd caches the output for 5 seconds. New
    tools/snmp-test.sh repeats the run (docker, by hand, not by the CI).

  • The manual says what happens under SELinux enforcing. Chapters 4, 13
    and 16 (en and zh_TW): the rpm was run on Rocky Linux 9.9 (aarch64, a
    virtual machine, targeted policy, enforcing). The daemon ran as
    unconfined_service_t and, with tcp, http and exec checks, DNS,
    /metrics, an encrypted peer group, the store and a reload, raised no AVC
    denial. We do not ship a policy module: a module that confines the daemon is
    extra hardening, not a need. The deb was run the same way on Ubuntu 24.04
    (arm64, a virtual machine, AppArmor enabled): no profile applies to the
    daemon and the kernel log has no apparmor="DENIED" line. x86-64 is still
    untested.

  • The manual says what EMP3 and EMP4 cost. Chapter 11 (en and zh_TW),
    "Choosing AES-GCM": on one arm64 machine a datagram of 150 to 500 bytes took
    0.7 to 1.5 microseconds to seal or open in EMP3 and 0.8 to 1.0 in EMP4
    (EMP4 derives a key per datagram: slightly slower for a heartbeat, about
    30 % faster for 490 bytes). New tools/bench-peer-crypto.sh repeats it;
    not run on x86-64. Nothing in the daemon changed.

  • The manual says when two name servers make HAProxy answer 503. Chapter
    14 (en and zh_TW), row "Name servers": with two name servers that disagree
    and several backends on one IP (one host, several ports), HAProxy 3.4.8
    answered a few requests with 503 (a slot with port 0). Six runs of 400
    requests each all had some (1 to 21 per run); six runs with a separate IP
    per backend had none. HAProxy 2.8 with the same setup (three runs) and
    HAProxy 3.4.8 with one name server (three runs) had none while the
    backends stayed up. With one backend stopped and started every 1.5 s, one
    name server was not enough when the backends share an IP: 7 runs of 100
    requests had 0 to 12 requests of 503 after about 3 s each (6 runs had
    some); with a separate IP per backend, 3 runs had 1 failed request each.
    On FreeBSD 15.1 (HAProxy 3.4.4) the same test gave 14 to 38 requests of
    503 per 100 with a shared IP and 1 to 2 with a separate IP per backend (4
    runs each): the 503 that 0.6.0 listed as unexplained there is this case.
    The 503s were not checked for port 0 directly. Nothing in emfor changed;
    the advice to use one name server stays, with a separate IP per backend.

  • Credential files must be regular files of bounded size. emfor-check
    and the TLS options of the daemon read password_file, a RADIUS
    secret_file, tls_key_file, tls_cert_file and ca_file without
    waiting for a writer, and refuse a FIFO, a device or a directory (a link to
    a regular file is fine) and a file larger than 64 KiB (tls_cert_file and
    tls_key_file: 1 MiB; ca_file: 8 MiB). Before, a path pointed at a FIFO
    stopped the thread that read it. Compatibility: systemd LoadCredential,
    Docker secrets and Kubernetes secrets end up as regular files, so none of
    them is affected as far as we know (not tried on each). A Debian
    ca-certificates.crt is 224019 bytes, far below the limit. The daemon's
    [peers] secret_file shares the same code; its checks and messages are
    unchanged. The mode of these files is still only a warning; their owner is not checked.

  • A peer secret rotation is logged with a stable line. When the content of
    [peers] secret_file changes (no reload needed), the daemon logs one info
    line with change=peers_secret_rotated and secret_file=<path>; the message
    text is unchanged. It never holds the secret or a hash of it. Chapters 11 and
    12 (en and zh_TW) describe it.

  • How to scrape /metrics over TLS. /metrics still has no TLS of its
    own. Chapter 12 (en and zh_TW) has a section "Metrics over TLS": listen
    stays on loopback, nginx in front terminates TLS and asks the scraper for a
    certificate, and Prometheus uses tls_config. Chapter 13 and
    docs/deploy/daemon.md point to it. tools/metrics-proxy-test.sh tries the
    recipe in a container with nginx and a throwaway CA; Prometheus, HAProxy and
    stunnel were not tried.

  • The repository has a Nix flake. It builds emfor (the daemon and
    emfor-check) and libemfor, and its NixOS module services.emfor writes
    emfor.toml from Nix settings and runs the daemon under the hardened unit of
    the deb and rpm packages. Chapter 4 (en and zh_TW) has a Nix section. Built
    and tested in a container on aarch64 Linux; not started on a NixOS machine.

  • A peer member whose clock is off is now shown before its messages are
    dropped.
    The daemon measures, from every message of a member that passes
    the checks up to site (also one dropped as stale), the member's
    timestamp minus its own clock. When the last three messages are all at
    least 2 seconds off in one direction, emfor status has a line peers: clock of <member> is <n.n> s behind this host (or ahead of; one line
    about this host when every member of a group of three or more differs),
    emfor status --json has peers.clock_offsets, and the log has a warn
    and later an info. New metric emfor_peer_clock_offset_seconds{peer}
    (seconds, negative when the member is behind) for every measured member. The
    5 second limit, the votes and the protocol are unchanged. Chapters 11, 12
    and 16 (en and zh_TW) say so; tools/peer-clock-test.sh checks it with
    three containers and libfaketime.

  • The manual says what to do with several data centres. Chapter 11
    ("Several data centres", en and zh_TW): one peer group per data centre, each
    with its own site, members and secret; why members of two sites do not
    belong in one group (single datagrams, 3-second liveness, 5-second clock
    limit); how backends in another data centre are checked and preferred.
    New tools/peer-wan-test.sh (run by hand in docker) measured it: a delay of
    1.5 s ± 0.5 s or 30 % loss on the peer messages did not make members leave;
    50 % loss did, for 6 of 60 seconds.

  • The FreeBSD port is in the ports tree. net-mgmt/emfor (0.7.1) is now
    part of the FreeBSD ports tree. Chapters 1 and 4 (en and zh_TW) say
    pkg install emfor or make -C /usr/ports/net-mgmt/emfor install clean, and
    call packages/freebsd/ a copy of the port. RELEASING.md adds the step of
    sending each new version to the ports tree.

  • The manual says how big the store gets, from a measurement. New
    tools/scale-test.sh (run by hand in docker, not by the CI) starts up to
    8,000 tcp backends in 80 services and reports the store size, memory, CPU
    and the time to switch. Chapter 12 ("Sizing the store") has the table and a
    rule: 6 KB per backend, map_size at least twice that; the default 64 MiB
    fits about 5,000 backends. Nothing in the daemon changed.

  • A peer member that sends no results is now shown. When a member is an
    assigned checker of a backend, is live and does not leave the service out,
    but sends no fresh result for it (it lacks the service or the backend, its
    check keeps giving error, or its packets do not arrive), the other members
    now report it after 10 seconds or 6 intervals of the service, whichever is
    longer: a line peers: no results from <member> for <service> (<n> backends)
    in emfor status, peers.silent_checkers in emfor status --json, the
    metric emfor_peer_silent_checkers, and a warn and an info log line.
    Nothing changes in the votes or on the wire. Chapter 11 ("When members
    differ", "Silent checkers"), chapter 12 and chapter 16 say so, and
    tools/peer-mismatch-test.sh runs three members in docker to check it.

  • The rpm has a test under systemd, and RHEL 8 is stated as unsupported.
    New tools/rpm-release-test.sh (run before a release, not by the CI) starts
    Rocky Linux 9 with systemd as PID 1 in docker and checks install, start,
    reload, stop, rpm -V, removal, reinstall, and with the previous rpm an
    upgrade and a downgrade. RELEASING.md says how to run it. The rpm and the
    deb do not run on RHEL 8 (glibc 2.28; the binary needs 2.30): the manual
    (chapter 4) and packages/README.md now say so, and list what was tested.

  • The log can be JSON, and the fields of a state change are stable. New
    [log] format = "json" (default "text") writes one JSON object per line
    once the daemon has started with it (the lines before that, such as plugin
    start lines, config errors and the warnings about the config files, are
    text), with the fields of the event at the top level and
    timestamp, level, target and message. A reload that changes format
    is rejected like any restart-only setting. The state change line gains
    event=backend_state_changed (also in text, at the end of the line), and
    event, service, backend, from, to, reason and the JSON
    timestamp and level are now stable. Chapter 14 says why emfor has no SNMP
    or hook, and has an example script (examples/snmp/emfor-snmp-trap.sh; the
    entry on what was run is above) and net-snmp extend; chapter 12 describes the
    history of emfor status --json. New crate tracing-serde.

  • Peer messages can use AES-256-GCM (EMP4). New [peers] cipher
    ("chacha20-poly1305", the default, changes nothing; "aes-256-gcm"
    sends EMP4 to every member; it needs encrypt = true and is reloadable).
    The nonce is a counter that restarts with each daemon start, under a key
    derived per start. Every daemon reads EMP4; an earlier version counts it
    as malformed, so upgrade all members before setting cipher. The audit
    log gains field=cipher. Chapter 13 has a FIPS section that says
    emfor has no FIPS mode: this is a different cipher, not a validated
    module.

  • The manual shows how to check ping and SCTP with exec. emfor has no
    ICMP or SCTP checker; chapter 6 gives a wrapper script for ping (with
    what the unit's sandbox and net.ipv4.ping_group_range mean for it) and
    describes what an SCTP check program needs. The entry above says what was
    run. No code change.

  • The manual says which releases get fixes. Only the latest one, with no
    backports before 1.0, no support contract and no promised response time
    (chapter 15). No code change.

  • The manual says where emfor stands on SELinux and AppArmor. emfor ships
    no policy; the entry above says what was run under SELinux enforcing and
    AppArmor. Chapter 13
    lists what the daemon reads, writes, listens on and starts, for anyone who
    writes a policy; chapter 16 has a short way to find a denial. No code
    change.

  • emfor status no longer calls an empty store a version problem. A store
    the daemon never wrote to (it exited at start, for example because the DNS
    port was taken) gives store is empty: the daemon has not written to it yet; if it should be running, check its log instead of store format version (missing). A store with a heartbeat or services but no version keeps the
    old message.

  • A reload logs what it changed. After an accepted reload the log has one
    line per difference (services and backends added, removed or changed,
    drain, a changed check definition by digest only, peer group settings),
    at most 50 per reload and then one line for the rest, before config reloaded. A change of site, of [dns], of [log] level or a whole
    [peers] table added or removed has no line. The daemon also logs the
    SHA-256 of every config file it reads, at start and at each reload, with or
    without include_dir. Field names (change, service, backend, ...) are
    stable; the wording is not. Check options and secrets are never logged. The
    log cannot say who changed the files: use auditd for that.

  • [metrics] allow limits who can read /metrics. A list of networks
    ("10.0.0.0/8", "fd00::/8"); a connection from any other source gets
    403 Forbidden and no metrics. Loopback is not exempt once allow is set.
    Without allow nothing changes, except a warning at start and after a
    reload when listen has a non-loopback address and allow is not set. A changed allow needs a
    restart.

  • http checks take a ca_file. For a server whose certificate a private
    CA signed, set ca_file to the CA's PEM file instead of installing it
    system-wide or turning off tls_verify. Only that file is trusted, not the
    system's CA certificates, as with the other checks that have a ca_file.
    A replaced file takes effect at the next check without a reload.

  • The manual says how far peer clocks may differ. A peer message whose
    timestamp is more than 5 seconds from the receiver's clock, in either
    direction, is dropped as stale; chapters 11 and 16 now say so. No code
    change.

  • A heartbeat far in the future counts as stale. When the clock of the
    host is set back by more than EMFOR_MAX_STALENESS (3 s by default) and
    the daemon then stops writing, clients no longer take the store for fresh
    until the clock catches up; a lookup sees every backend as unknown, so
    on_all_down decides (closed: ALL_DOWN, exit status 1 of emfor lookup;
    open: every backend, healthy or not). emfor status applies the same rule with a
    fixed limit of 3 s (it does not read EMFOR_MAX_STALENESS) and exits with 1
    in that case, where it exited with 0 before. With a live daemon the
    clients see a stale store for up to about a second, until its next
    heartbeat. emfor status says heartbeat <age> in the future, and
    heartbeat_age_ms in --json is negative in that case.

  • emfor lookup --explain agrees (without --dns; --dns explains the
    DNS server, which still takes a future heartbeat for fresh). For a heartbeat later than now it says
    heartbeat <age> in the future and, when that is stale, the heartbeat is more than <max> ahead of the clock, instead of an age of 0 that is
    "older than" the limit; store.heartbeat_age_ms in --json is negative.
    In the Rust crate Explanation.heartbeat_age_ms is now an i64 (it was a
    u64).