Repository navigation
Description
What's the problem
The Rust refresh (#717) will run as root every 15 seconds. It reads files that an operator edits, text from firmware, a reply from a local port and lines from the journal, starts a few system programs, and writes four feed files. It needs one place that does each of these safely. The repository has no such layer and no plan issue covers it, although #716 and #717 need it first.
What the layer must get right, found by a design review with two rounds of attack on the design:
- The test suite steers the code through environment variables and through stand-ins found by
PATH(curl,systemctl,journalctl,ip), so programs must be started by name and the environment read as it is. Rust'sstd::env::varspanics on a value that is not valid UTF-8. - A child whose own child keeps the output pipe open can hold a reader long after the child was killed.
- A FIFO where a file is expected blocks a plain read forever.
- The shell writes each feed file to a temporary name in the same folder and renames it. A planted link at the temporary name must not be followed.
- An error or a panic message must never carry the miner token or a pool password.
What it impacts
Every later Rust piece that touches the system: revision and identity (#716), the refresh (#717) and the verbs after them. Rigs are untouched by this issue, because nothing calls the new code yet.
How I found it
- A design for the refresh was written three times independently, merged, and then attacked by two reviewers. Twenty-five weaknesses were found in the first design; the points above are the ones that belong to this layer.
- The test stack was read for how it steers the shell: which variables, which stand-ins, and what each stand-in matches on.
- Nothing was built or run for this issue. The statements about the standard library come from its documentation.
How important is it
It blocks #716 and #717. It carries no product risk by itself: nothing ships from it and the default implementation stays bash.
Acceptance criteria
- The environment and the argument list are read without a panic on any byte sequence.
- Files are read with a size cap, and only regular files are read, so a FIFO, a socket or a device counts as unreadable at once. A table says for each path whether a link is followed.
- A child program is started by name through
PATH, in its own process group, with a deadline and an output cap. At the deadline the whole group is ended and the caller returns without waiting for the output reader. A test with a stand-in whose own child holds the pipe returns within the deadline plus one second. - A child gets no standard input unless the caller passes bytes.
- A file is published by writing a new temporary file in the same folder, created so that an existing name or link is refused, and renaming it. A stale temporary name left by an earlier run is removed first.
- A panic cannot print a config value: the panic mode is pinned and tested, and the hook prints a fixed text and the source location only. The lints deny
unwrap,expect, indexing that can panic, and the print macros. - A wrapper type for secrets prints a fixed placeholder in every format, with a test that formats it and searches for the planted value.
- Each limit has a test at its edge, and each new branch has a test that fails when the branch is changed.
- No existing file under
tests/changes.make lintandmake test-suitestill need no cargo.
Possible solutions
- A small layer in the library crate, about 600 lines, on the standard library only:
vars_osandargs_os,metadatabefore a read,Commandwithprocess_group, a reader thread that hands chunks to the caller over a channel, andcreate_newfor the temporary file. - A crate for process handling or temporary files. It would shorten the code, and it adds dependencies to a tool that runs as root.
Release: PR rigforge#880 merged
Who: operator
Activity