- Rust 97.5%
- Shell 2.5%
|
|
||
|---|---|---|
| .woodpecker | ||
| docs | ||
| packaging | ||
| src | ||
| tests | ||
| .gitignore | ||
| build.rs | ||
| Cargo.lock | ||
| Cargo.toml | ||
| LICENSE | ||
| README.md | ||
Shaker
Shaker is a small node agent. It runs on a load-balancer host, keeps one outgoing connection to Salt (the DNS and certificate service), receives certificates, a routing table, backends and a generated HAProxy configuration, and applies them to the local HAProxy. One static Rust binary, no OpenSSL, no dependencies on the host.
The wire contract is in docs/protocol.md. Salt's side (enrolment, proxy groups,
routes, address records and health checks, the console) is described in Salt's guide "Shaker and
routing" (docs/shaker.md in the Salt repository).
Contents: Status · Security model · Install · Enrolment · Commands · Keeping the status true · The operator's own HAProxy files · What HAProxy must contain · Strategies · Configuration reference · Metrics · Build and test · Release binaries
Status
Version 0.1.0. What has been run, and where:
- Automated tests. Unit and end-to-end tests against a fake Salt run in the pipeline on every
push. The integration test against a real HAProxy 3.4 container (
tests/haproxy_integration.rs, needs Docker, run by hand) passed on 13 November 2026: a certificate served, renewed without a reload, a name and a backend added on the socket, a bad configuration refused. Salt's own pipeline runs the published x86-64 binary against Salt in an exchange test. - On real hosts. On 13 November 2026 the x86-64 binary was installed with
packaging/install-debian.shon two Debian load balancers of Shaker's authors, with HAProxy 3.4.7. One host was set up with the offline bootstrap, the other with online enrolment. A route added in Salt reached both running HAProxy processes without a reload. A renewed certificate was served by both without a reload. After Salt was redeployed both agents reconnected by themselves. - Not run, as far as any record shows. The aarch64 binary is built and checked to be a static
aarch64 executable by the pipeline; it has not been run on an ARM host. The Docker layout described
under Install has not been run on a host. The
filesandcommandstrategies are covered by tests only. Nobody outside the authors has run Shaker.
Security model in plain words
- Three keys. Shaker makes two key pairs on the host: an age (X25519) pair that Salt encrypts to, and an Ed25519 pair it signs with. The private halves never leave the host. Salt has one Ed25519 signing key; its public half is stored on the host at enrolment.
- Everything Salt sends is encrypted to this host and signed by Salt. Shaker checks Salt's signature, the node id and a rising sequence number first, and only then decrypts. A forged, misdirected or replayed message is dropped and reported in the next status. Because the content is encrypted to the host, a private key is not readable by the load balancer in front of Salt.
- No shared password. On every connection Salt sends a random challenge and Shaker signs it. A one-time token is used once, at enrolment.
- Shaker never logs private keys or plaintext payloads. Private files are mode 0600, files that HAProxy must read are mode 0640 with a shared group. Names that end up in file names or socket commands (certificate ids, backend and server names, hosts) are checked against a strict alphabet.
- Outgoing only. Shaker listens on nothing (the optional metrics endpoint is off by default and
bound to localhost). It refuses to run as root unless
--allow-rootis given. - Whoever controls Salt controls where web traffic goes. That is why every message is signed and why Salt keeps an audit trail.
Install
On Debian 13, packaging/install-debian.sh /path/to/shaker-binary does all of the steps below and
also installs HAProxy 3.4 from haproxy.debian.net and points HAProxy's unit at the configuration that
Salt generates. It does not enrol the host, start Shaker, start HAProxy or open the firewall, and it
is safe to run again. By hand:
# user and group: Shaker has its own user; the shared group is the one thing it shares with HAProxy
groupadd --system haproxy-certs
useradd --system --home-dir /var/lib/shaker --shell /usr/sbin/nologin shaker
usermod -aG haproxy-certs shaker
usermod -aG haproxy-certs haproxy # the user HAProxy runs as
install -m 0755 shaker-x86_64-unknown-linux-musl /usr/local/bin/shaker
install -d -o shaker -g shaker -m 0700 /var/lib/shaker
install -d -o root -g shaker -m 0750 /etc/shaker
install -d -o shaker -g haproxy-certs -m 0750 /etc/haproxy/salt /etc/haproxy/salt/certs
install -d -o root -g haproxy-certs -m 0770 /run/haproxy # or via tmpfiles.d
install -m 0640 -g shaker packaging/shaker.toml.example /etc/shaker/shaker.toml
install -m 0644 packaging/shaker.service /etc/systemd/system/shaker.service
systemctl daemon-reload
Then enrol (below), start HAProxy with the generated configuration, and systemctl enable --now shaker. Add After=shaker.service to HAProxy's unit so the host comes up with current
certificates; a restart of HAProxy never needs Salt, because the files are on disk.
In Docker: run Shaker as a second container sharing two volumes with HAProxy (the Salt directory and
the socket directory), mounted at the same paths in both. The official haproxy:3.4 image runs
as user haproxy (uid 99) and has no group haproxy-certs, so the generated configuration uses a
numeric gid on the socket line; put the same number in [haproxy] socket_gid. Set check_command
to something like docker exec haproxy haproxy -c -f {file} -f {confdir}.
Enrolment
Online, with a one-time token from the Salt console or CLI:
sudo -u shaker shaker enrol --url https://salt.example.org --token <token>
It makes the key pairs, sends the public halves, stores the node id, Salt's signing key and the socket
URL, and prints the fingerprints of both public keys. Compare them with the console before
trusting the node (shaker fingerprint prints them again).
Offline (the very first load balancer, which cannot reach Salt yet, because Salt is reached through it) is the bootstrap flow:
- On the host:
shaker initmakes the keys, writesidentity.json(0600) and prints the enrolment request. - On a Salt host:
bin/salt_dns eval 'SaltDns.Release.shaker_bootstrap("<request>", "<proxy group>")'registers the node and prints a bootstrap file. - Copy the file to the host, then
shaker bootstrap <file>. It verifies and decrypts the envelopes, writes the certificates, maps and configuration, and (if HAProxy runs) loads them. It can be repeated. If the file's state was accepted before (a first run that failed its configuration check, a host that was repaired afterwards) the same file applies the state again, with the certificates from the file, instead of being refused as a replay. A file older than the state the host holds is still refused, and nothing from the network is ever accepted twice. shaker runconnects normally from then on.
Without any file, shaker apply re-applies the last known state from state.json and the files on
disk (no contact with Salt) and prints the result: generation, ok, whether the software runs, each
certificate's served serial, errors. Exit status 0 means applied without errors. Use it after fixing
something on the host. It runs as the shaker user (it refuses root without --allow-root). To do
it before HAProxy starts, a drop-in for haproxy.service can say
ExecStartPre=-/usr/sbin/runuser -u shaker -- /usr/local/bin/shaker apply (the unit's own
ExecStartPre lines run as root, hence runuser; the - lets HAProxy start even when there is no
state yet). The install script does not add this: shaker run already re-applies at start.
Commands
| Command | Does |
|---|---|
shaker init [--hostname H] [--show] |
make both key pairs, print the offline enrolment request (--show: print it again) |
shaker enrol --url U --token T |
online enrolment |
shaker bootstrap <file> |
apply a bootstrap file; the same file again re-applies the state it holds |
shaker apply [--allow-root] |
re-apply the last known state from disk, without Salt; print the result |
shaker run [--allow-root] |
connect, authenticate, receive, apply, report; reconnect with backoff (1 s doubling to 60 s, jitter). At start it re-applies the last state from disk, so the host is right before Salt is reachable. |
shaker status [--json] |
node id, generation, certificates with expiry, last errors |
shaker fingerprint |
fingerprints of the public keys |
--config <file> (default /etc/shaker/shaker.toml) works with every command. A missing default
file means defaults; a missing explicit file is an error.
Keeping the status true
Shaker does not report only when it applies something. Every [check] interval_secs (default 60,
each wait 20% shorter or longer at random) it asks the strategy what the software uses now. For
haproxy: whether the admin socket answers, the version, the served serial of every certificate,
whether the maps in memory equal the state and the files, and which backends and servers exist. Then:
- A status is sent when anything in it differs from the last one sent (HAProxy started or stopped, another serial served, a backend gone).
- A status is sent at least every
[check] heartbeat_secs(default 900 = 15 minutes) even when nothing differs. Salt alerts on a missing heartbeat. - If HAProxy runs but its memory disagrees with the files (started from older files, a map or
certificate changed on the socket), Shaker re-applies the current state through the normal
apply path and reports the result. Repairs are at least
[check] repair_gap_secs(300) apart, so a difference that cannot be repaired does not make Shaker reload in a loop; it stays in the log and inshaker_memory_matches_disk. - The check goes on while the connection to Salt is down; the status is sent after reconnecting.
The status format is unchanged. interval_secs = 0 switches the check and the heartbeat off. The
files and command strategies only report whether the software runs (always true for them).
The operator's own HAProxy files and local backends
HAProxy can read more than Salt's file. The Debian package starts it as
haproxy -Ws -f /etc/haproxy/salt/haproxy.cfg -f /etc/haproxy/conf.d ..., so sites that Salt does not
manage can live in /etc/haproxy/conf.d/*.cfg. A backend there can be the target of a Salt route: the
state then carries the backend as {"name":"my_local","local":true} (no servers). Shaker never creates,
changes or deletes such a backend on the socket and the periodic check never "repairs" it. It only
looks in show backend: when no backend of that name exists in the running HAProxy it reports the error
{"what":"backend","id":"my_local","message":"local backend not found in HAProxy"}, and the route is
written anyway (the error clears by itself once the backend exists, at the next check). The files and
command strategies pass the flag on (command gets it in backends).
The configuration check sees the operator's files too. Otherwise a route to a local backend could
never pass haproxy -c. check_command has two placeholders: {file} (the candidate generated file)
and {confdir} ([haproxy] conf_dir, default /etc/haproxy/conf.d). The default command is
haproxy -c -f {file} -f {confdir}. When the directory does not exist, the argument that holds
{confdir} and the -f before it are left out, so a host without the directory checks the generated
file alone. A shaker.toml that sets its own check_command without {confdir} (as written by the
0.1.0 install script) keeps checking only the generated file; add -f {confdir} to it to get the new
behaviour.
Permissions. HAProxy is started by root and reads conf.d as root, but the check runs as the user
shaker. The directory and every file in it, and every file those refer to (crt, errorfile, lua
and so on), must be readable by it. With the layout of the install script (shaker is in the group
haproxy-certs):
chgrp haproxy-certs /etc/haproxy/conf.d /etc/haproxy/conf.d/*
chmod 0750 /etc/haproxy/conf.d; chmod 0640 /etc/haproxy/conf.d/*
A file the check cannot read does not fail with HAProxy's message; Shaker looks first and reports
config error "the operator's configuration file cannot be read by this user ...", keeps the old
configuration and changes nothing else about the apply.
Certificates nobody routes to
Every certificate in the state is written, put in crt-list.txt, loaded in HAProxy and reported, whether
or not a route uses it, so the operator's own files can rely on it. A certificate that leaves the state
is taken out of the list, unloaded and its file deleted. Names are not interpreted: files are named by
certificate id, so a certificate for a.b.c.example.org, with or without *.a.b.c.example.org, needs
nothing special (tests: unrouted_deep_certificates_are_written_listed_and_removed and the HAProxy
integration test haproxy_34_local_backend_and_unrouted_certificate).
What HAProxy must contain
Salt generates the configuration, so normally nobody writes this by hand; packaging/haproxy-example.cfg shows it (tested with 3.4.7). The points Shaker depends on, as proven by the integration test:
| Requirement | Why |
|---|---|
stats socket <admin.sock> mode 660 group <shared group> level admin in global (container: gid <n> instead of group). Local file, never a TCP address. |
The socket has no login. Shaker's group access is what lets it change HAProxy at run time. |
Start HAProxy with -W -S <master.sock>,mode,660 |
The reload fallback goes through the master socket, without root. |
bind ... ssl crt-list <crt-list.txt> strict-sni, never a single crt file |
Only a list can grow while running. strict-sni lets HAProxy start with an empty list (a warning only; no placeholder certificate needed). |
A named defaults salt_http section with mode http |
add backend <name> from salt_http copies its settings. |
Frontends named differently from any defaults section (salt_https, salt_http_redirect, both from salt_http) |
HAProxy 3.3+ refuses a frontend with the same name as a defaults section. |
Routing through map(<hosts.map>) and map_end(<hosts-wildcard.map>) with the file paths Shaker uses |
show map/prepare map/commit map address a map by its file name. |
One backend section per backend in the state, except local ones |
A restart then gives what the socket commands gave. Local backends are in the operator's file. |
http-request return with a payload needs a content-type |
Found while testing; HAProxy refuses the section otherwise. |
| Only Shaker writes the files in the Salt directory | Disk and memory must stay equal. |
Things the integration test showed that the design document did not say:
a certificate committed with new ssl cert + set ssl cert + commit ssl cert stays Unused
until add ssl crt-list runs; show ssl cert prints the serial in upper case without 0x; the
reply to add backend on an existing name is "name is already used", which Shaker treats as "exists,
reconcile its servers"; HAProxy has no status codes on its command line, so Shaker checks replies
for error words and then verifies with a show command.
What the haproxy strategy does
Order for one state: certificates (files, list, socket), backends, routes, then removals in the opposite order (routes, backends, certificates), then the configuration file.
- Certificates. Chain then key, one file per certificate, written to a temporary name and
renamed. Known certificate:
set ssl certwith the whole bundle,commit ssl cert(a key that does not fit makes the commit fail, the old one keeps serving, the transaction is aborted). New certificate:new ssl cert,set,commit,add ssl crt-list.crt-list.txtis rewritten first. Removal:del ssl crt-list,del ssl cert, delete the file. Verified withshow ssl cert <file>; the served serial is reported. - Routes.
hosts.map(exact) andhosts-wildcard.map(*.example.orgbecomes the key.example.org, looked up withmap_end). Files are rewritten, then the running maps are replaced atomically withprepare map,add map @<ver>,commit map @<ver>and verified withshow map. - Backends.
experimental-mode on; add backend <name> from salt_http mode <mode>,add server,enable server,publish backend; changed or removed servers withdisable server/del server; removed backends withunpublish backend,del backend. - Configuration. Written beside the old one (
haproxy.cfg.new), checked withcheck_command, the old file kept ashaproxy.cfg.previous, then renamed over. A file that fails the check is never used, the old one stays, the error is reported. A reload through the master socket happens only when the new file differs from the old one in more than backend sections that the socket commands already created, changed or removed, or when a socket step failed, or when the previous apply had errors. If HAProxy refuses the reload the previous file is restored. - Socket trouble falls back to a reload (the files are already right). HAProxy not running
(admin socket not answering and no master socket to reload through): files only, said once in the
log, no reload is considered; this counts as success; the status says
running: false, andloaded: falsefor each certificate.
Other strategies
files: writes<id>.pem(chain then key),<id>.crt(chain) and<id>.keyto[files] dir, removes files of certificates that left the state, and runs[files] commandonce afterwards (no shell; split like a shell line). For Postfix, Dovecot, nginx: anything that only reads files.command: starts[command] program args...and writes one JSON object to its standard input:version,restore,generation,certificates(id, version, names, not_after, andchain_pemandkey_pemonly for new or changed ones),removed(ids),routes,backends,default_backend,config. Exit status 0 means applied. The program is not given private keys when Shaker replays the last state at start-up.
Configuration reference
See packaging/shaker.toml.example; every key and its default is
there. Unknown keys are an error. Config::under(dir) in the library puts every path below one
directory, which is how the tests run without root.
Metrics
Off by default. [metrics] listen = "127.0.0.1:9199" serves GET /metrics; [metrics] file is a
text file for node_exporter's textfile collector. Series: shaker_connected,
shaker_last_apply_timestamp_seconds, shaker_applied_generation,
shaker_certificate_not_after_timestamp_seconds{id}, shaker_apply_errors_total,
shaker_reconnects_total, and from the periodic check shaker_software_running (0/1),
shaker_memory_matches_disk (0/1; 1 while the software is not running, there being nothing in
memory to differ) and shaker_last_status_sent_timestamp_seconds (0 until the first status).
Writing a new strategy
Implement shaker::strategy::Strategy (in src/strategy/mod.rs):
#[async_trait]
pub trait Strategy: Send + Sync {
fn name(&self) -> &'static str;
async fn software(&self) -> SoftwareInfo; // name, version, running
async fn apply(&self, req: &ApplyRequest<'_>) -> Outcome; // never panics; errors go in Outcome
}
ApplyRequest carries the desired state, the previous state, the bundles that are new or
changed (chain and key; certificates not in bundles were written by an earlier apply), restore
(replay at start) and previous_ok. Return an Outcome: one CertReport per certificate now in use
(loaded, served_serial as the software reports it), counts, errors (what: certificate,
route, backend, config; id; message), and missing for certificate ids whose files are gone
(Shaker then asks Salt for them again). Validate every identifier with State::validate() before using
it in a path or command, never log Bundle contents, and write files with fsutil::write_atomic.
Register the strategy in strategy::build.
Build and test
cargo build -j 6 && cargo test -j 6 # unit and end-to-end tests (fake Salt)
cargo test -j 6 --test haproxy_integration -- --ignored # needs docker and haproxy:3.4
# static release binary (x86_64, musl), built in an Alpine Rust image; SHAKER_COMMIT is what
# `shaker --version` prints (the image has no git; without it the version says "unknown"):
docker run --rm -v "$PWD":/src -w /src -e CARGO_TARGET_DIR=/src/target/musl \
-e SHAKER_COMMIT="$(git rev-parse --short=9 HEAD)" rust:1.96-alpine \
sh -c 'apk add --no-cache musl-dev gcc && cargo build --release --locked --target x86_64-unknown-linux-musl'
# result: target/musl/x86_64-unknown-linux-musl/release/shaker (copy to dist/shaker-x86_64-unknown-linux-musl)
The aarch64 binary is built by the pipeline on the same x86-64 runner (.woodpecker/ci.yml, step
static-build-aarch64): Alpine's zig package is the C compiler and linker for the target
aarch64-unknown-linux-musl (ring has C and assembly parts), with -C link-self-contained=no so that
zig supplies the C runtime. The step runs file on the result and fails unless it is a static aarch64
executable.
Release binaries
On every push to master the pipeline publishes both binaries and sha256sums.txt to Forgejo's generic
package registry, owner external, package shaker, under two versions: the full commit sha and latest
(deleted and uploaded again each time). It needs the Woodpecker secret forgejo_token; without it the step
prints that it is skipped. The same step runs on a manual pipeline started on master, so latest can
be republished from the current code without an empty commit.
BASE=https://git.shilohbv.com/api/packages/external/generic/shaker
curl -fLO $BASE/latest/shaker-x86_64-unknown-linux-musl # or shaker-aarch64-unknown-linux-musl
curl -fLO $BASE/latest/sha256sums.txt
sha256sum -c --ignore-missing sha256sums.txt
# a fixed build: $BASE/<full commit sha>/<file>
Downloading from a private registry takes a token: curl -fL -H "Authorization: token $TOKEN" ....
Licence
MIT, as Salt (see LICENSE).