diff --git a/.github/actions/build-fork/action.yml b/.github/actions/build-fork/action.yml index 2cedf93..cf069d4 100644 --- a/.github/actions/build-fork/action.yml +++ b/.github/actions/build-fork/action.yml @@ -38,6 +38,10 @@ runs: git -C /tmp/core/libntech checkout -q FETCH_HEAD echo "core=$core" >> "$GITHUB_OUTPUT" echo "libntech=$libntech" >> "$GITHUB_OUTPUT" + # In the job log, not only the summary: the libntech commit core's + # submodule pointer names exists on the fork, not on the upstream URL + # in .gitmodules, and is fetched from `libntech.repo` above. + echo "build-fork: core $core, libntech $libntech (from $libntech_repo)" - name: Build dependencies (core's own script; Debian/Ubuntu branch) shell: bash diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 7c7139d..df32dde 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -42,6 +42,7 @@ jobs: - name: Generic-bundle tests (systemd lifecycle in enforce mode) env: TENDCF_TEST_SYSTEMD: "1" + TENDCF_REQUIRE_FORK_LOADER: "1" run: tests/policy/run.sh --bindir /opt/tendcf/bin # Schema v5 S1 (schema-v5-dpkg-reconciliation-2026-11-02.md section 6): # the read-only unit classifier against the real manager and real @@ -92,6 +93,7 @@ jobs: - name: Generic-bundle tests (plus the NixOS-shape refusal) env: TENDCF_TEST_NIXOS_SHAPE: "1" + TENDCF_REQUIRE_FORK_LOADER: "1" run: tests/policy/run.sh --bindir /opt/tendcf/bin # librsync (and its libb2) is a build-time pick of core's configure # and not part of a minimal Debian; pastebin lacked it (2026-10-29). diff --git a/AGENTS.md b/AGENTS.md index c6ab9a2..7ef43d2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -242,7 +242,19 @@ a book: `site-private/AGENTS.md` ("Book knowledge base"). - `tests/policy/run.sh --bindir DIR` runs the generic bundle against a real `cf-agent`/`cf-promises` (Mac dev build: `~/opt/cfengine-dev/bin`); it is - platform-independent and is the test CI runs on Linux. Run it through + the test CI runs on Linux. Policy-layer assertions that hold on any loader + (most of the file) run against any `cf-agent`. Two kinds hold only with the + pinned fork's all-or-nothing, strict-parse loader: loader assertions (its log + strings, "this container was not installed") and loader+policy integration + assertions (9b: the cross-check's refusal and no actuation for a repeated + member, a repeated `vars`, trailing input; a lenient loader and the lenient + `readjson` see the same surviving data, so there is nothing to refuse). A + probe in check 4b decides once; on any other build each of those prints + `SKIP (loader not all-or-nothing): `, never passes silently, and the + run is expected to pass with SKIP lines and a count (not yet run on the Mac: + derived from the parser behaviour). The Mac dev build stays a target + (operator, 2026-11-14, "keep Mac, SKIPs"). The Linux CI legs set + `TENDCF_REQUIRE_FORK_LOADER=1`, which makes a skip a failure. Run it through `~/ops/site-private/bin/bg`. Two checks are opt-in because they reshape the host and need root: `TENDCF_TEST_SYSTEMD=1` (check 6, the real-systemd lifecycle; the ubuntu VM jobs) and `TENDCF_TEST_NIXOS_SHAPE=1` (check 7, diff --git a/bin/projector.py b/bin/projector.py index c8ad5f4..67b69ea 100755 --- a/bin/projector.py +++ b/bin/projector.py @@ -409,10 +409,15 @@ def flag(rule: str, msg: str) -> None: # E-6/E-7: these are LEGAL to CFEngine, which is exactly why the # negative exists — `variables` loads after `vars` and overwrites # the same name, so a checker that only asks "is `vars` right?" - # never sees the document that replaced it. + # never sees the document that replaced it. (The fork pinned in + # overlay/fork.json instead refuses a file in which `variables` + # names a variable `vars` already names; upstream replaces it.) extra = ( - " — legal to CFEngine, loaded after `vars` and overwriting the " - "same names, which is why envelope-shape checking misses it" + " — legal to upstream CFEngine, which loads it after `vars` and " + "lets it overwrite the same names, which is why envelope-shape " + "checking misses it; the fork pinned in overlay/fork.json " + "instead refuses a file in which `variables` or `classes` is " + "invalid or names a variable `vars` already names" ) flag( RULE_PROJECTION, diff --git a/docs/architecture/tendcf-validate-proposal-2026-11-03.md b/docs/architecture/tendcf-validate-proposal-2026-11-03.md index 5e5aeb0..e7ef2c9 100644 --- a/docs/architecture/tendcf-validate-proposal-2026-11-03.md +++ b/docs/architecture/tendcf-validate-proposal-2026-11-03.md @@ -15,8 +15,9 @@ TUF); map §11 (timeout is deny); [`change-process.md`](change-process.md) of [`projector-reconciliation-2026-08-16.md`](projector-reconciliation-2026-08-16.md). How the CFEngine claims were checked: the fork source at the commit -`overlay/fork.json` pins (`b8abf28408b1b54e285d372a9bc5f2d850c960ad`, -read with `git show` in `~/src/cfengine-core`). The book (*Learning +`overlay/fork.json` pinned when this was written +(`b8abf28408b1b54e285d372a9bc5f2d850c960ad`, read with `git show` in +`~/src/cfengine-core`; PR #41 later moved the pin, see §13). The book (*Learning CFEngine*, 3.12) was searched first. It covers cf-execd's role and five-minute default schedule (ch. 23) and `cf-runagent` (ch. 35). `book-kb query` finds neither `host_specific` nor `exec_command` in it: both postdate or @@ -33,8 +34,9 @@ Each was read in the pinned fork source or in this repository on (`libpromises/generic_agent.c:1234`) logs a failed load ("Failed to load CMDB data") and the run continues. `cf-agent --no-host-specific-data` skips the load entirely. -2. **On the pinned fork, a bad entry is skipped on its own, not with the - whole file.** `ReadCMDBVars` `continue`s past an entry carrying an +2. **On the fork at the pin of the time (`b8abf28408b1`), a bad entry is + skipped on its own, not with the whole file.** (Superseded: the pin + now carries an all-or-nothing loader, PR #41, §13.) `ReadCMDBVars` `continue`s past an entry carrying an unexpanded variable reference or an invalid key, and still installs the others. The cause is fork commit `8f0076b81` ("Fixed one bad CMDB entry discarding every entry in its section"), merged into @@ -981,8 +983,9 @@ that hold the stale text, per its brief. a function of. 5. **Map §12 item 1** ("deleting or withholding the projection is not a demonstrated fail-closed launch protocol") is right, and fact 2 - strengthens it: on the pinned fork, a *malformed* projection is not - even all-or-nothing. + strengthens it: on the fork pinned when this was written (`b8abf28408b1`), + a *malformed* projection was not even all-or-nothing (the pin has since + moved to the fail-closed loader, §13). 6. **`deploy/linux/tendcf-install.sh` `put_data`** is not atomic against a concurrent cf-agent (fact 8). This matters once a scheduler runs, which stage B enables. @@ -1022,8 +1025,11 @@ projection that `tendcf-install.sh install --data` puts on pastebin (deploy/linux/README.md) carries both containers: its `vars` keys are `tendcf_interlock` and `tendcf_service`, checked 2026-11-02. Any skip of the first leaves the second ungated. No skip is known to happen with the -current bytes, which pass the N-series. It is flagged for djbclark, not -decided here. +current bytes, which pass the N-series. It was flagged for djbclark. +**Ruled 2026-11-02:** option 3 (Q10), implemented in PR #42, which records it +below; and option 5 (R13, Q49), the fork's all-or-nothing loader pinned by PR +#41 ([`upstream-register.md`](upstream-register.md) B-5b note). Each holds +without the other. **(a) Question.** When the CMDB loader installs `tendcf_service` but not `tendcf_interlock` (fact 2), how does the policy refuse, instead of @@ -1143,9 +1149,11 @@ cannot differ on a consistent file; a `vars` value that is not an object is refused when it reads back differently: the loader installs a scalar as a string, which `storejson()` cannot read, and a list of numbers as an slist of strings, while a list of strings reads back equal and is accepted.) It -also refuses any top-level key of the file other than `vars` (the fork's -loader also applies `variables`, loaded after `vars`, and `classes`, which can -define `interlock_ok_*`; the projector emits neither, N-2), any `vars` key that +also refuses any top-level key of the file other than `vars` (the loader also +applies `variables`, loaded after `vars` (the fork at the pin refuses a file +in which `variables` names a variable `vars` already names; upstream replaces +it), and `classes`, which can define `interlock_ok_*`; the projector emits +neither, N-2), any `vars` key that is not a plain identifier `[A-Za-z0-9_]+` (the loader reads a key as a variable reference, `GetCMDBVariableRef`, so `default:tendcf_services.service_ids` presets a variable of the policy's own bundles), a loaded `data:variables.*` @@ -1204,8 +1212,8 @@ rvalue does redefine a preset, a function call does not), and the two no pre_action, no service, no tombstone. The vars and classes of a `bundle common` are pre-evaluated before the vars of any non-common bundle, whatever `bundlesequence` says (`PolicyResolve` and `BundleResolve`, -`libpromises/expand.c` lines 846-871 and 1145-1177 at the pinned fork commit -`b8abf28408b1`, [expand.c](https://github.com/djbclark/core/blob/b8abf28408b1b54e285d372a9bc5f2d850c960ad/libpromises/expand.c#L846)), +`libpromises/expand.c` lines 846-871 and 1145-1177 at fork commit +`b8abf28408b1` (the pin when this was written), [expand.c](https://github.com/djbclark/core/blob/b8abf28408b1b54e285d372a9bc5f2d850c960ad/libpromises/expand.c#L846)), so `tendcf_cmdb_refused` is decided before a gate is first read. That is a statement about vars and classes only, not that every promise type of a common bundle completes first, and the classes inside the check rely on their written @@ -1213,9 +1221,21 @@ order within the one pass. `bundlesequence` guard classes in `promises.cf` are not needed for this check. This is a consistency check, not a sandbox: a CMDB author (root) already chooses each pre_action executable, `/bin/sh` included, and the unit commands, so it does not stop a hostile but self-consistent file. -The fork-side all-or-nothing loader (PR #41) and this check are independent: -with the loader failing closed, the file's keys are not loaded and the check -refuses and reports it, which is correct and louder. +The fork-side all-or-nothing loader (PR #41) and this check hold each without +the other: with the loader failing closed, the file's keys are not loaded and +the check refuses and reports it, which is correct and louder. The independence +is limited, not complete: the loader's strict parse (a repeated member or +trailing input refuses the file; fork `6505f488a`) belongs to the CMDB loader +only, while this check's `readjson` stays lenient and sees the last of a +repeated member or `vars` section, so an earlier container the loader refused +is not named by the check. The check reports a refusal when that lenient view +still lists variables the loader did not install (or another feature it refuses +on its own); when the lenient view is empty (`{"vars":{},"vars":{}}`, or +`{"vars":{}}` followed by non-whitespace) nothing is installed and nothing +actuates, but the check has nothing to report, so no actuation is not a refusal +report and the loader's own error is the only trace (`run.sh` 9b, empty-view +controls). The check does not detect such a file when the loader is lenient and +the repeated member is invisible to both parsers. Two findings from the implementation, both about the proof above. (1) The Mac dev build (`3.29.0a.086d27749`) does not carry the per-entry loader @@ -1224,9 +1244,15 @@ makes it install nothing at all, so the fail-open cannot be reproduced there with a file. `tests/policy/sim-loader.cf` therefore installs `data:variables.*` in the loader's place, from the same file, to emulate the per-entry skip; the original policy was run against it first and did -process the service with its interlock skipped. The Linux CI legs build the -pinned fork and so also exercise the real per-entry skip with the literal -fixture (`tests/policy/fixtures/interlock-malformed.json`). (2) The check +process the service with its interlock skipped. When this was written the +Linux CI legs built the fork at `b8abf28408b1` and so also exercised the real +per-entry skip with the literal fixture +(`tests/policy/fixtures/interlock-malformed.json`). That no longer holds: PR +#41 moved the pin to the all-or-nothing loader, which installs nothing from +that fixture, so check 9 sees both keys missing and the partial states stay +tested only through the stand-in (check 10), which remains valid because the +check compares the file with what was installed whatever the loader's policy. +(2) The check needs `readjson` and `variablesmatching` to compose on the loader's installed variables; they do on the dev build (checks 9-10 of `tests/policy/run.sh`), so option 4 stays unneeded. The policy-tree digest diff --git a/docs/architecture/upstream-overlay.md b/docs/architecture/upstream-overlay.md index 8722cb5..5ea36ab 100644 --- a/docs/architecture/upstream-overlay.md +++ b/docs/architecture/upstream-overlay.md @@ -220,6 +220,17 @@ drops it. | `retired --strict` against upstream master | nothing to retire | nothing to retire | | `self-test` | 13/13 | | +**Since 2026-11-02 (R13, PR #41) the core column's B-5b is not what the fork +the tests run does.** The pin in `overlay/fork.json` carries an all-or-nothing +CMDB loader that replaces B-5b's per-entry skip (a skipped interlock leaves the +services it guards unguarded). The manifest entry still reproduces `8f0076b81` +and carries a `superseded_on_fork` note; the table above is the 2026-10-09 +state and is not updated. Upstream plus this overlay skips a bad entry; the +pinned fork installs nothing from the file. The operator ruled on 2026-11-14 +to replace the patch: a later, separate PR makes the overlay carry the +all-or-nothing loader in its place ([`upstream-register.md`](upstream-register.md) +B-5b note). + So the overlay reproduces exactly the inputs whose build was verified on 2026-08-19, from this repository alone, and would still apply to a build cut from today's upstream. diff --git a/docs/architecture/upstream-register.md b/docs/architecture/upstream-register.md index 697eda2..c757715 100644 --- a/docs/architecture/upstream-register.md +++ b/docs/architecture/upstream-register.md @@ -344,6 +344,33 @@ unmerged-libntech submodule dependency, and [#1](https://github.com/djbclark/core/issues/1) is the investigation trail behind P-1/P-2 and is not itself a defect. +**B-5b reversed on the integration branch, 2026-11-02 (operator ruling R13).** +`8f0076b81` made the CMDB loader skip one bad entry and install the rest. For +tendcf that is fail-open: an interlock entry dropped at load leaves the +services it guards actuated unguarded. `tendcf-integration` now carries +`cmdb-fail-closed` (`a750b1dfe`, `dbf9dede6`, `61065e551`, `736becc07`, merged +`d32cade13`; hardened by djbclark/core PR #98 and a strict libntech JSON parse, +the pin now `6505f488a`): `LoadCMDBData()` validates every entry of +`vars`/`variables`/`classes` first and installs nothing from +`host_specific.json` if any one is invalid (also an unknown top-level key, a +null section, a key with index brackets, a frame-dependent special scope, two +entries naming one variable, a variable that exists already, a class name with +whitespace at either end), logging each by name and returning false; the agent +then runs with no CMDB variables. It reads the file with a strict parse +(`JsonParseFileStrict`, libntech `cc892efae`): a repeated object member and +anything but whitespace after the document refuse the file before validation. +A class that exists already is left as it is and the rest is installed. Strict +parsing is the CMDB loader's alone: `readjson` and `def.json` stay lenient. +Upstream PRs #6315/#6320 +stay closed unmerged. The overlay manifest's B-5b entry (`overlay/overlay.json`) +still describes and reproduces `8f0076b81`, not this behaviour; it now carries +a `superseded_on_fork` note saying so, and +[`upstream-overlay.md`](upstream-overlay.md) section 7 repeats it. Whether the +overlay keeps, retires or replaces that patch was ruled on 2026-11-14 (Replace: +the overlay will carry the all-or-nothing loader instead of the per-entry skip), +and is done in a later, separate PR because it changes what the overlay +reproduces. + B-2 through B-7 are described, measured and sourced in [`cfengine-upstream-candidates-2026-08-16.md`](cfengine-upstream-candidates-2026-08-16.md); B-1's full evidence is in diff --git a/overlay/fork.json b/overlay/fork.json index 56cb7a0..d96ed95 100644 --- a/overlay/fork.json +++ b/overlay/fork.json @@ -3,7 +3,7 @@ "core": { "repo": "https://github.com/djbclark/core", "branch": "tendcf-integration", - "commit": "b8abf28408b1b54e285d372a9bc5f2d850c960ad" + "commit": "6505f488a80ab3e18b089c7d8e32571c88128866" }, "libntech": { "repo": "https://github.com/djbclark/libntech" diff --git a/overlay/overlay.json b/overlay/overlay.json index 3670b7e..2716b5b 100644 --- a/overlay/overlay.json +++ b/overlay/overlay.json @@ -32,6 +32,7 @@ "retire_when": "an upstream commit carries the same change (`bin/overlay.py retired` says RETIRE), or the code it protects is no longer shipped", "role": "load-bearing", "subject": "Fixed one bad CMDB entry discarding every entry in its section", + "superseded_on_fork": "2026-11-02, operator ruling R13 (PR #41): the fork's tendcf-integration branch, which overlay/fork.json pins, replaces this patch's per-entry skip with an all-or-nothing loader (branch cmdb-fail-closed: a750b1dfe, dbf9dede6, 61065e551, 736becc07; merged d32cade13, hardened by djbclark/core PR #98 and a strict libntech parse, pin 6505f488a). A skipped interlock entry leaves the services it guards unguarded. This entry still describes, and apply reproduces, commit 8f0076b81 exactly, so upstream plus the overlay skips a bad entry and does NOT behave like the pinned fork. Operator ruling 2026-11-14: Replace. A later, separate PR makes the overlay carry the all-or-nothing loader instead of this per-entry skip, because that changes what the overlay reproduces (upstream-overlay.md section 7); this PR leaves the patch and its manifest entry as they are.", "upstream_pr": "https://github.com/cfengine/core/pull/6320", "upstream_pr_state": "closed unmerged 2026-08-19" } diff --git a/policy/tendcf_services.cf b/policy/tendcf_services.cf index 29f0508..ac9d854 100644 --- a/policy/tendcf_services.cf +++ b/policy/tendcf_services.cf @@ -62,15 +62,33 @@ # # CMDB cross-check (`tendcf_cmdb`, proposal 2026-11-03 section 13, option 3, # operator ruling Q10 2026-11-02). Everything above assumes CFEngine's loader -# installed what host_specific.json says. It does not promise that: the fork's -# loader skips a bad entry on its own and still returns success, so a skipped -# `tendcf_interlock` leaves every service ungated (services are gated -# negatively, on `!interlock_blocked_*`, and that class only exists for an -# interlock that loaded). The check does not model WHY an entry was dropped. It -# reads the file itself and compares it with what the loader installed: +# installed what host_specific.json says. Nothing promises that for every +# engine: the fork before 2026-11-02 (`8f0076b81`, B-5b) skipped a bad entry on +# its own and still returned success, and a skipped `tendcf_interlock` leaves +# every service ungated (services are gated negatively, on +# `!interlock_blocked_*`, and that class only exists for an interlock that +# loaded). The fork at the pin (overlay/fork.json, PR #41, operator ruling R13) +# loads all-or-nothing instead: an invalid entry, a repeated object member +# anywhere, non-whitespace after the document, a class name with whitespace at +# either end, a variable that exists already, and it installs none of the file, +# so this check then sees every `vars` key missing and refuses. That strict parse +# is the CMDB loader's only: `readjson`, which this check reads the file with, +# and def.json stay lenient, so after a repeated member or a repeated `vars` +# section the check sees the LAST one only (an earlier container is not named). +# It reports a refusal when that lenient view still lists variables the loader +# did not install (or another feature it refuses on its own). When the lenient +# view is EMPTY (`{"vars":{},"vars":{}}`, or `{"vars":{}}` plus non-whitespace +# after it) nothing is installed and nothing actuates, but the check has nothing +# to report: no actuation is not a refusal report, and the loader's own error is +# then the only trace (tests/policy/run.sh 9b, empty-view controls). The two are +# not fully independent for that reason, and each holds for a loader that fails +# closed, for one that does not, and for a gap in either, to the extent the +# other does not share the gap. The check does not model WHY an entry was +# dropped. It reads the file itself and compares it with what the loader installed: # - the file's top-level keys must be exactly `vars`. The loader also applies -# a `variables` section (loaded AFTER `vars`, replacing a same-named -# variable) and a `classes` section (which can define `interlock_ok_*`); +# a `variables` section (after `vars`; upstream CFEngine lets it replace a +# same-named variable, the fork at the pin refuses a file that names one +# variable twice) and a `classes` section (which can define `interlock_ok_*`); # the projector emits neither (N-2, bin/projector.py check_projection), so # any other top-level key is refused rather than compared; # - every key under `vars` must be a plain identifier ([A-Za-z0-9_]+). The @@ -89,7 +107,8 @@ # a scalar as a string (storejson() fails) and a list of primitives as an # slist of strings (numbers read back as strings; a list of strings reads # back equal and is accepted). Equal ids with changed values, as a -# `variables` entry would give, are caught. A comparison that cannot be +# loader that replaced a container (upstream's `variables` section) would +# give, are caught. A comparison that cannot be # computed is a problem of its own (`..._problem_uncomparable_`, or # `..._problem_noverdict_` when both texts exist but neither equality # nor a difference could be evaluated), not the absence of a difference; @@ -133,8 +152,9 @@ # Presets. The loader installs a `vars` key under any name, so a key such as # `default:tendcf_cmdb.doc` or `default:tendcf_services.interlock_ids` presets # that variable before any policy runs. What a preset does then depends on the -# promise (verify_vars.c VerifyVarPromise, commit b8abf28408b1 pinned in -# overlay/fork.json): a promise with a LITERAL rvalue (`slist => { }`) always +# promise (verify_vars.c VerifyVarPromise, read at commit b8abf28408b1; the +# pin in overlay/fork.json is now 6505f488a, which differs from it only in +# libpromises/cmdb.c, cmdb.h, tests and the libntech submodule pointer): a promise with a LITERAL rvalue (`slist => { }`) always # redefines it, so the policy's value stands. A promise whose rvalue is a # FUNCTION CALL is skipped when the variable exists ("Already did this") if the # call was not already evaluated to a value when the promise runs, and @@ -544,7 +564,7 @@ bundle agent tendcf_interlocks "tendcf: CMDB cross-check: $(tendcf_cmdb.file) does not exist but CFEngine loaded data:variables.$(tendcf_cmdb.loaded_clean)"; "tendcf_cmdb_problem_missing":: - "tendcf: CMDB cross-check: key '$(tendcf_cmdb.missing_clean)' is under 'vars' in $(tendcf_cmdb.file) but CFEngine did not load data:variables.$(tendcf_cmdb.missing_clean) (the loader skipped it)"; + "tendcf: CMDB cross-check: key '$(tendcf_cmdb.missing_clean)' is under 'vars' in $(tendcf_cmdb.file) but CFEngine did not load data:variables.$(tendcf_cmdb.missing_clean) (the loader did not install it)"; "tendcf_cmdb_problem_unlisted":: "tendcf: CMDB cross-check: CFEngine loaded data:variables.$(tendcf_cmdb.unlisted_clean), which is not a key under 'vars' in $(tendcf_cmdb.file)"; diff --git a/tests/policy/fixtures/cmdb-probe.cf b/tests/policy/fixtures/cmdb-probe.cf new file mode 100644 index 0000000..1cfb8e3 --- /dev/null +++ b/tests/policy/fixtures/cmdb-probe.cf @@ -0,0 +1,24 @@ +# Reports whether the two goal-file containers the generic bundle reads are +# installed as CMDB data. Run alone by tests/policy/run.sh, after a load that +# must have installed everything or nothing; it actuates nothing. +body common control +{ + bundlesequence => { "cmdb_probe" }; +} + +bundle agent cmdb_probe +{ + classes: + "interlock_present" expression => isvariable("data:variables.tendcf_interlock"); + "service_present" expression => isvariable("data:variables.tendcf_service"); + + reports: + interlock_present:: + "cmdb-probe: tendcf_interlock present"; + !interlock_present:: + "cmdb-probe: tendcf_interlock absent"; + service_present:: + "cmdb-probe: tendcf_service present"; + !service_present:: + "cmdb-probe: tendcf_service absent"; +} diff --git a/tests/policy/fixtures/interlock-malformed-key.json b/tests/policy/fixtures/interlock-malformed-key.json new file mode 100644 index 0000000..c54abcb --- /dev/null +++ b/tests/policy/fixtures/interlock-malformed-key.json @@ -0,0 +1 @@ +{"vars":{"tendcf_interlock":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/false"],"expect_exit":0,"timeout_seconds":5},"report":true,"state":"present"}},"tendcf_interlock[":[],"tendcf_service":{"demo-runit":{"bundle":"demo","command":["/bin/sleep","1"],"run_as":"nobody","state":"present","unit":{"runit":{"enabled":true}},"working_dir":"/"}}}} diff --git a/tests/policy/fixtures/loader-class-exists.json b/tests/policy/fixtures/loader-class-exists.json new file mode 100644 index 0000000..df3940e --- /dev/null +++ b/tests/policy/fixtures/loader-class-exists.json @@ -0,0 +1 @@ +{"vars":{"tendcf_interlock":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/false"],"expect_exit":0,"timeout_seconds":5},"report":true,"state":"present"}},"tendcf_service":{"demo-runit":{"bundle":"demo","command":["/bin/sleep","1"],"run_as":"nobody","state":"present","unit":{"runit":{"enabled":true}},"working_dir":"/"}}},"classes":{"default:linux":"any::"}} diff --git a/tests/policy/fixtures/loader-class-space.json b/tests/policy/fixtures/loader-class-space.json new file mode 100644 index 0000000..b3596c9 --- /dev/null +++ b/tests/policy/fixtures/loader-class-space.json @@ -0,0 +1 @@ +{"vars":{"tendcf_interlock":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/false"],"expect_exit":0,"timeout_seconds":5},"report":true,"state":"present"}},"tendcf_service":{"demo-runit":{"bundle":"demo","command":["/bin/sleep","1"],"run_as":"nobody","state":"present","unit":{"runit":{"enabled":true}},"working_dir":"/"}}},"classes":{"default: ":"any::"}} diff --git a/tests/policy/fixtures/loader-dup-member.json b/tests/policy/fixtures/loader-dup-member.json new file mode 100644 index 0000000..761bc84 --- /dev/null +++ b/tests/policy/fixtures/loader-dup-member.json @@ -0,0 +1 @@ +{"vars":{"tendcf_interlock":null,"tendcf_interlock":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/false"],"expect_exit":0,"timeout_seconds":5},"report":true,"state":"present"}},"tendcf_service":{"demo-runit":{"bundle":"demo","command":["/bin/sleep","1"],"run_as":"nobody","state":"present","unit":{"runit":{"enabled":true}},"working_dir":"/"}}}} diff --git a/tests/policy/fixtures/loader-dup-vars.json b/tests/policy/fixtures/loader-dup-vars.json new file mode 100644 index 0000000..588c1fb --- /dev/null +++ b/tests/policy/fixtures/loader-dup-vars.json @@ -0,0 +1 @@ +{"vars":{"tendcf_interlock":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/false"],"expect_exit":0,"timeout_seconds":5},"report":true,"state":"present"}},"tendcf_service":{"demo-runit":{"bundle":"demo","command":["/bin/sleep","1"],"run_as":"nobody","state":"present","unit":{"runit":{"enabled":true}},"working_dir":"/"}}},"vars":{"tendcf_service":{"demo-runit":{"bundle":"demo","command":["/bin/sleep","1"],"run_as":"nobody","state":"present","unit":{"runit":{"enabled":true}},"working_dir":"/"}}}} diff --git a/tests/policy/fixtures/loader-empty-dup-vars.json b/tests/policy/fixtures/loader-empty-dup-vars.json new file mode 100644 index 0000000..a249200 --- /dev/null +++ b/tests/policy/fixtures/loader-empty-dup-vars.json @@ -0,0 +1 @@ +{"vars":{},"vars":{}} diff --git a/tests/policy/fixtures/loader-empty-trailing.json b/tests/policy/fixtures/loader-empty-trailing.json new file mode 100644 index 0000000..dc98d6a --- /dev/null +++ b/tests/policy/fixtures/loader-empty-trailing.json @@ -0,0 +1,2 @@ +{"vars":{}} +not json after the document diff --git a/tests/policy/fixtures/loader-trailing.json b/tests/policy/fixtures/loader-trailing.json new file mode 100644 index 0000000..6e83efb --- /dev/null +++ b/tests/policy/fixtures/loader-trailing.json @@ -0,0 +1,2 @@ +{"vars":{"tendcf_interlock":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/false"],"expect_exit":0,"timeout_seconds":5},"report":true,"state":"present"}},"tendcf_service":{"demo-runit":{"bundle":"demo","command":["/bin/sleep","1"],"run_as":"nobody","state":"present","unit":{"runit":{"enabled":true}},"working_dir":"/"}}}} +not json after the document diff --git a/tests/policy/run.sh b/tests/policy/run.sh index fa233fc..09a8f5d 100755 --- a/tests/policy/run.sh +++ b/tests/policy/run.sh @@ -1,9 +1,26 @@ #!/usr/bin/env bash # Generic-bundle tests for policy/tendcf_services.cf against a real cf-agent. # -# Platform-independent on purpose: nothing here touches launchd or -# /Library/LaunchDaemons, so the same run passes on a Linux CI runner and on -# the Mac dev build. Three checks: +# Nothing here touches launchd or /Library/LaunchDaemons. Two kinds of +# assertion hold only with the pinned fork's all-or-nothing, strict-parse loader +# (overlay/fork.json), and go through fork_only(): +# - loader assertions: its log strings, the duplicate-variable message, "this +# container was not installed", the probe-absent lines; +# - loader+policy integration assertions: the cross-check's refusal and the +# absence of actuation for a repeated member, a repeated `vars` and trailing +# input (9b dup-member, dup-vars, trailing). A lenient loader and the lenient +# readjson see the same surviving data, so the cross-check has no difference +# to refuse and the interlock or service guard acts instead. +# Everything else is policy-layer and holds on any cf-agent (the Linux CI +# legs, the Mac dev build). A one-time capability probe in check 4b (a file with +# a repeated member of `vars`) decides whether the loader is the fork's; on a +# non-fork run (the Mac dev build, retained as a target by the operator, +# 2026-11-14) each fork_only assertion prints `SKIP (loader not all-or-nothing): +# ` and the run is expected to pass with those SKIP lines and a final +# count, never a silent pass. The Linux CI legs set TENDCF_REQUIRE_FORK_LOADER=1, +# which turns a non-fork loader (so, any skip) into a failure. The non-fork +# outcome has been derived from the parser behaviour, not yet run on the Mac. +# Checks: # # 1. wiring: cf-promises parses the bundle with the example projection # (examples/host_specific.json) installed as CMDB data, so every @@ -26,6 +43,19 @@ # (darwin) and systemd (Linux booted by systemd), so the entry must be # refused by name and nothing rendered, on every host (linux-targets.md # step 3: the fail-closed guard, with this as its negative test). +# 4b. malformed CMDB entries, enforce mode: a host_specific.json with one +# malformed entry (an unresolved variable reference in the interlock; +# then a key 'tendcf_interlock[' that the variable parser reads as the +# interlock container) beside a valid interlock and a present service. +# The policy layer must refuse and report it (refusal_reported, +# refusal_once) and actuate nothing on any loader. On the pinned fork's +# all-or-nothing loader the file also installs nothing (loader log +# strings; a probe policy finds neither data:variables.tendcf_interlock +# nor ...tendcf_service): those assertions are fork_only. A loader that +# skipped only the bad entry would let the service through unguarded, +# which the policy-layer assertions would catch. +# The same block holds the capability probe (fork_loader) and the +# TENDCF_REQUIRE_FORK_LOADER=1 assertion. # 5. host guard, enforce mode, non-Darwin only: a satisfied interlock and # two present launchd services. launchd exists only on darwin, so a # Linux host must refuse both, write nothing under /Library and run no @@ -57,8 +87,10 @@ # actuates nothing; the consistent files of checks 2-4 raise no report; no # file at all, and a file with no vars, are the normal empty case. Also # refused and reported, each actuating nothing: a `variables` section that -# replaces a container under the same ids with another command (the -# comparison is of the whole container, not of key names and ids), a +# names a container of `vars` again (the fork at the pin refuses the file +# as a duplicate variable and installs none of it; the whole-container +# comparison that would catch the same ids with another command is tested +# in checks 10 and 11), a # `classes` section, and a `vars` key that is not a plain identifier, which # the loader would file under another scope (a preset of the policy's own # id lists), and a `vars` value that is not an object (not comparable as @@ -72,14 +104,49 @@ # container that is a list of strings is the positive control: accepted, # actuates. A plain-identifier key longer than 64 characters is refused and # its report line shows only the first 64. Every file of checks 2-8 and 6 is also a no-report control. -# NB: the fork's loader skips a bad entry and installs the rest, but the -# Mac dev build rejects the whole `vars` instead (the same fixture refuses -# on both, as "nothing loaded"), so only the fork's CI legs see the -# per-entry skip. +# NB: the fork at the pin (overlay/fork.json, core 6505f488a) loads +# all-or-nothing (PR #41, operator ruling R13): a file in which an entry is +# invalid, a class cannot be inserted, a `vars` member or section is +# repeated, or non-whitespace follows the document, installs none of its +# contents (libpromises/cmdb.c, strict libntech parse; the strict parse is +# the CMDB loader's alone, readjson and def.json stay lenient). On the +# Linux legs this check sees every `vars` key missing, as the Mac dev build +# does when it rejects the whole `vars`. The same fixture refuses the same +# way on both ("nothing loaded"). No loader this check runs against skips +# one entry and installs the rest; the fork did before R13 (`8f0076b81`, +# B-5b), which is the 2026-11-02 fail-open. +# 9b. the loader's strict-parse and class refusals, one fixture each in +# tests/policy/fixtures/loader-*.json, each beside a valid interlock and a +# present service: a repeated member of `vars` (dup-member), a repeated +# top-level `vars` whose later section drops the interlock (dup-vars), +# non-whitespace after a valid document (trailing), a whitespace-only +# default-namespace class name (class-space). Each must be refused and +# reported once by PR 42's cross-check and actuate nothing (fork_only for +# the first three, the integration assertions above; unconditional for +# class-space, whose `classes` section the cross-check refuses on any +# loader); on the fork each also loads nothing, logs the loader's reason and +# reports each key as not loaded (fork_only). A class that already exists (class-exists, +# the host's own hard class) is not an error: the fork leaves it as it is +# and installs the rest, so no refusal is expected; the case asserts that +# `classes` beside good vars is still refused by the cross-check's own +# `classes` rule. In dup-vars the lenient readjson sees only the last +# `vars` section, so the report names only what that section holds +# (tendcf_service), not the interlock the loader dropped: the +# cross-check's independence from the loader is limited (proposal 13). +# Two empty-view controls (empty-dup-vars `{"vars":{},"vars":{}}`, +# empty-trailing `{"vars":{}}` plus trailing input) are refused by the +# strict loader but read as an empty `vars` by readjson: nothing installs, +# nothing actuates and no cross-check report is made (asserted on any +# loader; only the loader's refusal is fork_only). No actuation is not a +# refusal report. # 10. the same cross-check against a loader that skips ONE container, which -# the Mac dev build cannot do: tests/policy/sim-loader.cf installs -# data:variables.* in the loader's place (cf-agent --no-host-specific-data) -# from the very file the policy reads. Each case must report what differs +# neither the Mac dev build nor the pinned fork does: tests/policy/sim-loader.cf +# installs data:variables.* in the loader's place (cf-agent +# --no-host-specific-data) from the very file the policy reads. It stays +# valid after R13: the check compares the file with what is installed +# whatever the loader's policy, and this is the only way to test the +# partial states (a fork before the pin, another engine, a gap in the +# loader's validation). Each case must report what differs # and run nothing; the control case (everything installed) must run as # before, so the others cannot pass because the stand-in installed nothing. # A skipped interlock container with the services loaded is the 2026-11-02 @@ -165,6 +232,24 @@ check() { # check NAME COND... if "$@"; then echo "ok $name"; else echo "FAIL $name"; fail=1; fi } +# Assertions that hold only on the pinned fork's CMDB loader (overlay/fork.json: +# all-or-nothing, strict parse): its log strings, "this container was not +# installed", and the loader+policy integration assertions of 9b (the +# cross-check's refusal and no actuation for a repeated member, a repeated +# `vars`, trailing input). Policy-layer assertions that hold on every loader +# stay on `check`. fork_loader is set once, by the +# probe in check 4b. A loader that is not the fork's makes fork_only print a +# SKIP line, never pass silently; TENDCF_REQUIRE_FORK_LOADER=1, which the Linux +# CI legs set because they build the pinned fork, turns "not the fork's loader" +# into a failure, so CI cannot pass by skipping. +fork_loader=unknown +skipped=0 +fork_only() { # fork_only NAME COND... + if [ "$fork_loader" = 1 ]; then check "$@"; return 0; fi + echo "SKIP (loader not all-or-nothing): $1" + skipped=$((skipped + 1)) +} + # The cross-check's report. "refusing to actuate anything" is the summary line # tendcf_interlocks prints once; no_actuation is what a refused run must not do: # run any command (-I logs every one, pre_action included), render, or process @@ -224,6 +309,79 @@ check "nothing rendered for the runit entry" \ check "no launchctl invocation" \ bash -c "! grep -q launchctl '$out'" +echo "# 4b. malformed CMDB entries: the loader fails closed" +# Each fixture is a host_specific.json with one malformed entry next to a +# valid interlock and a present service. The interlock's pre_action would +# fail if it ran, so a loader that dropped only the bad entry (or let it take +# the place of another) would let the service through unguarded: the service +# would be processed and reported (the runit flavour is refused by name on +# every host, check 4). The fork's all-or-nothing CMDB loader installs +# nothing from a file it finds invalid (this one is), so no service and no +# interlock exists to act on. +# Besides what the agent did, the probe policy asks it directly whether either +# container exists, which a service-only or interlock-only leftover cannot hide +# from; its positive control is a file that loads. +cp "$repo/tests/policy/fixtures/cmdb-probe.cf" "$work/inputs/cmdb-probe.cf" +probe() { # probe FIXTURE OUT: run the probe policy over FIXTURE as CMDB data + cp "$repo/tests/policy/fixtures/$1" "$work/data/host_specific.json" + "$cf_agent" -K -f "$work/inputs/cmdb-probe.cf" >"$2" 2>&1 || true +} +probe interlock-refused.json "$work/probe-control.out" +check "probe control: a file that loads has tendcf_interlock" \ + grep -q "cmdb-probe: tendcf_interlock present" "$work/probe-control.out" +check "probe control: a file that loads has tendcf_service" \ + grep -q "cmdb-probe: tendcf_service present" "$work/probe-control.out" + +# Loader capability, once: a repeated object member in `vars` must install +# nothing (the fork's strict parse, LoadCMDBData reading with JsonParseFileStrict, +# cmdb.c:1171 at 6505f488a), where a lenient loader keeps the last member and +# installs both containers. Positive evidence only: both "absent" lines. +probe loader-dup-member.json "$work/probe-capability.out" +if grep -q "cmdb-probe: tendcf_interlock absent" "$work/probe-capability.out" && + grep -q "cmdb-probe: tendcf_service absent" "$work/probe-capability.out"; then + fork_loader=1 + echo "# loader capability: all-or-nothing with strict parse (the pinned fork)" +else + fork_loader=0 + echo "# loader capability: NOT the pinned fork's loader; fork-only assertions print SKIP" +fi +if [ "${TENDCF_REQUIRE_FORK_LOADER:-0}" = 1 ]; then + check "TENDCF_REQUIRE_FORK_LOADER=1: the loader is the pinned fork's (no skipping)" \ + test "$fork_loader" = 1 +fi + +malformed_case() { # malformed_case NAME FIXTURE ERROR-PATTERN + local name="$1" fixture="$2" pattern="$3" + out="$work/malformed-$name.out" + cp "$repo/tests/policy/fixtures/$fixture" "$work/data/host_specific.json" + "$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true + check "$name: the policy refuses and reports it" refusal_reported "$out" + check "$name: the policy reports it once" refusal_once "$out" + fork_only "$name: malformed entry named in the CMDB error" grep -q "$pattern" "$out" + fork_only "$name: loader reports that it installed none of the file" \ + grep -q "installing none of its contents" "$out" + check "$name: no service processed (the sibling service entry was not installed)" \ + bash -c "! grep -q \"tendcf: service 'demo-runit'\" '$out'" + check "$name: no interlock command executed" \ + bash -c "! grep -q \"Executing .*'/usr/bin/false'\" '$out'" + check "$name: nothing rendered" \ + bash -c "! grep -q 'Created file' '$out'" + check "$name: no launchctl or systemctl invocation" \ + bash -c "! grep -Eq 'launchctl|systemctl' '$out'" + probe "$fixture" "$work/probe-$name.out" + fork_only "$name: no tendcf_interlock variable" \ + grep -q "cmdb-probe: tendcf_interlock absent" "$work/probe-$name.out" + fork_only "$name: no tendcf_service variable" \ + grep -q "cmdb-probe: tendcf_service absent" "$work/probe-$name.out" +} +# an unresolved variable reference in the interlock's pre_action +malformed_case unresolved interlock-malformed.json \ + "offending value in entry 'tendcf_interlock'" +# a key the variable parser reads as the interlock container itself +# ('tendcf_interlock[' is 'tendcf_interlock' to it, with only a log message) +malformed_case index-key interlock-malformed-key.json \ + "Invalid variable specification in CMDB data: 'tendcf_interlock\\['" + if [ "$(uname)" != Darwin ]; then echo "# 5. host guard: launchd entries refused on $(uname)" cp "$repo/tests/policy/fixtures/launchd-present.json" "$work/data/host_specific.json" @@ -552,6 +710,11 @@ out="$work/xc-malformed.out" check "malformed interlock: refusal reported" refusal_reported "$out" check "malformed interlock: the container the loader did not install is named" \ key_not_loaded "$out" tendcf_interlock +# All-or-nothing: the valid sibling container is not installed either (the +# pre-R13 fork installed it, which was the fail-open; the Mac dev build rejects +# the whole `vars`, so it agrees). +fork_only "malformed interlock: the sibling tendcf_service is not installed either (all-or-nothing)" \ + key_not_loaded "$out" tendcf_service check "malformed interlock: refusal reported once" refusal_once "$out" check "malformed interlock: nothing actuated, no pre_action run, no service processed" \ no_actuation "$out" @@ -586,18 +749,28 @@ for f in noshell-or noshell-semi argv-alphabet argv-meta relative sysd1 sysd2 sy check "consistent file of the $f run: no cross-check report" no_crosscheck "$work/$f.out" done -# A `variables` section replaces `vars.tendcf_interlock` under the same id with -# a pre_action that passes (the file's own vars say /usr/bin/false). The loader -# applies `variables` after `vars` (cmdb.c LoadCMDBData), so the ids match and -# only the content differs. +# A `variables` section naming `tendcf_interlock` again, with a pre_action that +# passes (the file's own vars say /usr/bin/false). The fork at the pin refuses the +# whole file: two entries naming one variable are a duplicate (cmdb.c +# CMDBPendingCheckNoDuplicates, fork commit 61065e551), so the loader logs the +# duplicate, installs none of the file and the policy sees every `vars` key +# missing. (A loader that applied `variables` after `vars` and replaced the +# container, as upstream CFEngine does, would leave the same ids with another +# command; that content difference is the cross-check's whole-container +# comparison, tested in check 10 against the stand-in loader, "service|interlock +# value changed under the same id", and in check 11 against a replaced file.) cp "$repo/tests/policy/fixtures/cmdb-variables-collision.json" "$work/data/host_specific.json" out="$work/xc-collision.out" "$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true check "variables-section collision: refusal reported" refusal_reported "$out" -check "variables-section collision: the content difference is named" \ - grep -q "key 'tendcf_interlock' content differs between" "$out" -check "variables-section collision: not an id difference" \ - bash -c "! grep -q 'loaded differently' '$out'" +fork_only "variables-section collision: the loader refuses the duplicate variable" \ + grep -q "Invalid variable specification in CMDB data: 'tendcf_interlock' names the variable 'data:variables.tendcf_interlock' that another entry names too" "$out" +fork_only "variables-section collision: the loader installs none of the file" \ + grep -q "installing none of its contents" "$out" +fork_only "variables-section collision: tendcf_interlock is reported not installed" \ + key_not_loaded "$out" tendcf_interlock +fork_only "variables-section collision: nothing was loaded to differ in content" \ + bash -c "! grep -q 'content differs' '$out'" check "variables-section collision: the section is named" \ grep -q "has top-level section 'variables' besides 'vars'" "$out" check "variables-section collision: refusal reported once" refusal_once "$out" @@ -710,6 +883,122 @@ check "list of strings in vars: no cross-check report" no_crosscheck "$out" check "list of strings in vars: actuates normally (the pre_action ran)" \ grep -q "Executing .*'/usr/bin/true'" "$out" +echo "# 9b. the real loader's strict parse and class handling (fork 6505f488a), policy level" +# What the pinned loader does with each file is read from libpromises/cmdb.c at +# 6505f488a (line numbers there), and each case asserts it. The cross-check's +# refusal and the absence of actuation are asserted unconditionally only where +# the policy refuses on its own (class-space, class-exists: a `classes` section) +# or where nothing can actuate (the empty-view controls). For a repeated member, +# a repeated `vars` and trailing input they are loader+policy integration +# assertions (strict_case POLICY=fork): a lenient loader and the lenient readjson +# see the same surviving data, the cross-check has nothing to refuse, and the +# interlock or the service guard acts, so they SKIP on a non-fork loader. +# Where the loader refuses the file, `key_not_loaded` reports each key of the +# file the cross-check could read: it reads with readjson, which stays lenient, +# so after a repeated member or a repeated `vars` section it sees the LAST one +# only, and an earlier container (here the interlock of case b) is not named. +# That is the limit of the cross-check's independence from the loader's parser. +# POLICY is `any` when the cross-check refuses on any loader (the file has a +# `classes` section, which it refuses on its own), `fork` when the refusal and +# the absence of actuation depend on the strict loader: a lenient loader and the +# lenient readjson read the same surviving member, section or prefix, so the +# cross-check sees no difference, and the interlock (whose pre_action fails) or +# the service's own guard actuates or reports. Those are loader+policy +# integration assertions and SKIP on a non-fork loader. +strict_case() { # strict_case NAME FIXTURE LOADER-ERROR-PATTERN INSTALL-NONE POLICY KEY... + local name="$1" fixture="$2" pattern="$3" none="$4" policy="$5"; shift 5 + local pcheck=check + [ "$policy" = fork ] && pcheck=fork_only + out="$work/strict-$name.out" + cp "$repo/tests/policy/fixtures/$fixture" "$work/data/host_specific.json" + "$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true + "$pcheck" "$name: the policy refuses and reports it" refusal_reported "$out" + "$pcheck" "$name: the policy reports it once" refusal_once "$out" + fork_only "$name: the loader refuses the file" grep -q "$pattern" "$out" + if [ "$none" = yes ]; then + fork_only "$name: the loader installs none of the file" \ + grep -q "installing none of its contents" "$out" + fi + local k + for k in "$@"; do + fork_only "$name: $k reported not installed" key_not_loaded "$out" "$k" + done + "$pcheck" "$name: nothing actuated (no service, no interlock, no render)" no_actuation "$out" + probe "$fixture" "$work/probe-strict-$name.out" + fork_only "$name: no tendcf_interlock variable" \ + grep -q "cmdb-probe: tendcf_interlock absent" "$work/probe-strict-$name.out" + fork_only "$name: no tendcf_service variable" \ + grep -q "cmdb-probe: tendcf_service absent" "$work/probe-strict-$name.out" +} +dup_member="Could not parse JSON file .*host_specific\\.json: Unwilling to parse json data with a duplicate object member" +# (a) a repeated member: an invalid earlier value (null), then a valid interlock. +# The lenient parser keeps the last (valid) one; the strict parse the loader reads +# with (cmdb.c:59-84 ReadJsonFileMode, :1171-1177) refuses the file before any +# validation, so the first value is no longer discarded unseen. +strict_case dup-member loader-dup-member.json "$dup_member" no fork tendcf_interlock tendcf_service +# (b) `vars` twice at the top level, the later one without the interlock +strict_case dup-vars loader-dup-vars.json "$dup_member" no fork tendcf_service +# (c) a complete valid document, then more input (the lenient parser stops after +# the first document and ignores the rest) +strict_case trailing loader-trailing.json \ + "Could not parse JSON file .*host_specific\\.json: Unwilling to parse json data with trailing non-whitespace characters" \ + no fork tendcf_interlock tendcf_service +# (d) a default-namespace class whose name is whitespace only: refused in +# validation (CheckCMDBClassName, cmdb.c:776-), so nothing is installed, where it +# used to reach insertion, fail, and be taken for "a class that exists already" +strict_case class-space loader-class-space.json \ + "Invalid CMDB class 'default: ': the class name starts or ends with whitespace" yes any \ + tendcf_interlock tendcf_service +check "class-space: the classes section is named by the policy" \ + grep -q "has top-level section 'classes' besides 'vars'" "$out" + +# (e) a class that exists already, beside good vars. The loader leaves it as it +# is and goes on (InstallCMDBPending, cmdb.c:1095-1102: CMDBClassExists by +# canonical identity, logged at VERBOSE only), so both containers are installed; +# the policy refuses all the same, for the `classes` section. `linux` is a hard +# class on the Linux legs (`darwin` on a Mac), set before the loader runs +# (generic_agent.c:1234); a CMDB class of a name that is taken is not installed, +# so it is not reported as a class the CMDB defined. +hardclass=linux +[ "$(uname)" = Darwin ] && hardclass=darwin +exists_json=$(cat "$repo/tests/policy/fixtures/loader-class-exists.json") +printf '%s\n' "${exists_json//default:linux/default:$hardclass}" >"$work/data/host_specific.json" +out="$work/strict-class-exists.out" +"$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true +check "class-exists: the policy refuses and reports it" refusal_reported "$out" +check "class-exists: the policy reports it once" refusal_once "$out" +check "class-exists: the classes section is named by the policy" \ + grep -q "has top-level section 'classes' besides 'vars'" "$out" +check "class-exists: nothing actuated" no_actuation "$out" +fork_only "class-exists: the loader did not fail on the existing class" \ + bash -c "! grep -q 'Failed to add CMDB class' '$out'" +fork_only "class-exists: the loader did not refuse the rest of the file" \ + bash -c "! grep -q 'installing none of its contents' '$out'" +fork_only "class-exists: the good variables were installed" \ + bash -c "! grep -q 'but CFEngine did not load' '$out'" +fork_only "class-exists: the existing class was not redefined by the CMDB" \ + bash -c "! grep -q 'defined a class' '$out'" + +# (f) empty-view controls (Astra r2 C1, adversary r2 I1). The strict loader refuses +# each file, but the lenient readjson the cross-check reads with sees an EMPTY +# `vars` (the last of two, or the prefix before the trailing input), the same as +# `{"vars":{}}` in check 9: nothing is installed, nothing actuates, and the +# cross-check has nothing to report. So there is no refusal report here, and none +# is claimed: the loader's own ERR is the only trace. On any loader the file is +# empty or lenient-empty, so no report and no actuation hold everywhere; only the +# loader's refusal is fork-only. +for spec in "empty-dup-vars:loader-empty-dup-vars.json:Unwilling to parse json data with a duplicate object member" \ + "empty-trailing:loader-empty-trailing.json:Unwilling to parse json data with trailing non-whitespace characters"; do + name=${spec%%:*}; rest=${spec#*:}; fixture=${rest%%:*}; pattern=${rest#*:} + out="$work/strict-$name.out" + cp "$repo/tests/policy/fixtures/$fixture" "$work/data/host_specific.json" + "$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true + check "$name: the lenient view is empty, so no cross-check report" no_crosscheck "$out" + check "$name: nothing actuated" no_actuation "$out" + fork_only "$name: the loader refuses the file" \ + grep -q "Could not parse JSON file .*host_specific\\.json: $pattern" "$out" +done + echo "# 10. CMDB cross-check, a loader that skips one container (tests/policy/sim-loader.cf)" sim_run() { # sim_run FIXTURE|none CLASSES OUT if [ "$1" = none ]; then rm -f "$work/data/host_specific.json" @@ -879,6 +1168,9 @@ check "probe no verdict: nothing ran (neither the loaded nor the replaced pre_ac if [ "$fail" != 0 ]; then for f in refused satisfied noshell-or noshell-semi argv-alphabet argv-meta relative flavour host sysd-host sysd-host-tomb sysd1 sysd2 sysd3 sysd4 sysd5 sysd6 nixos-shape nixos-tombstone \ xc-malformed xc-nofile xc-novars xc-garbage xc-collision xc-classes xc-preset xc-preset-vars xc-uncomparable xc-checker-preset xc-checker-preset-keys xc-classes-hidden xc-augments xc-strlist xc-probe-before xc-probe-after xc-probe-noverdict xc-longkey \ + malformed-unresolved malformed-index-key probe-control probe-capability probe-unresolved probe-index-key \ + strict-dup-member strict-dup-vars strict-trailing strict-class-space strict-class-exists strict-empty-dup-vars strict-empty-trailing \ + probe-strict-dup-member probe-strict-dup-vars probe-strict-trailing probe-strict-class-space \ xc-sim-control xc-sim-nointerlock xc-sim-noservice xc-sim-partial xc-sim-stray xc-sim-nofile xc-sim-changed-service xc-sim-changed-interlock \ sysd-sim-present sysd-sim-tomb; do [ -f "$work/$f.out" ] || continue @@ -886,4 +1178,8 @@ if [ "$fail" != 0 ]; then done exit 1 fi -echo; echo "all policy tests passed" +echo +if [ "$skipped" != 0 ]; then + echo "NOTE: $skipped assertion(s) skipped (loader not all-or-nothing); see the SKIP lines" +fi +echo "all policy tests passed" diff --git a/tests/policy/sim-loader.cf b/tests/policy/sim-loader.cf index b35a30b..273dd08 100644 --- a/tests/policy/sim-loader.cf +++ b/tests/policy/sim-loader.cf @@ -1,7 +1,12 @@ # Test only (tests/policy/run.sh checks 9-10). Stands in for a CMDB loader that -# skipped, or half installed, a container of host_specific.json, which is the -# fork's behaviour on a bad `tendcf_interlock` entry (the Mac dev build rejects -# the whole `vars` instead, so it cannot be made to skip one container). Run +# skipped, or half installed, a container of host_specific.json. No loader the +# tests run does that: the fork at the pin (overlay/fork.json) is all-or-nothing +# (a file it finds invalid, by the reasons listed in policy/tendcf_services.cf +# tendcf_cmdb, installs nothing, since PR #41, operator ruling R13) and the Mac +# dev build rejects the whole `vars`. The fork before R13 +# (`8f0076b81`, B-5b) did skip one bad entry, which was the 2026-11-02 +# fail-open; this stand-in keeps that state testable, and the cross-check +# must refuse it however a loader came to leave it. Run # cf-agent with --no-host-specific-data so this is the only thing installing # data:variables.*, and list this file BEFORE tendcf_services.cf in `inputs`: # the data must exist before tendcf_cmdb reads it.