diff --git a/deploy/linux/tendcf-install.sh b/deploy/linux/tendcf-install.sh index 2555dc7..158de91 100755 --- a/deploy/linux/tendcf-install.sh +++ b/deploy/linux/tendcf-install.sh @@ -148,7 +148,15 @@ put_data() { # put_data FILE backup="$data.previous" cp -p "$data" "$backup" fi - install -m 0600 -o root -g root "$src" "$data" + # Write beside the live file, then rename over it: the agent (cf-execd runs + # it on a schedule) never reads a half-written host_specific.json, and the + # loader and the policy's cross-check cannot see two different halves. + local tmp="$data.new" + if ! install -m 0600 -o root -g root "$src" "$tmp"; then + rm -f "$tmp" + die "could not write $tmp" + fi + mv -f "$tmp" "$data" if ! "$cf_promises" -f "$entry" >/dev/null; then if [ -n "$backup" ]; then mv -f "$backup" "$data"; else rm -f "$data"; fi die "cf-promises rejected $src; previous data restored" diff --git a/docs/architecture/tendcf-validate-proposal-2026-11-03.md b/docs/architecture/tendcf-validate-proposal-2026-11-03.md index afb67d8..5e5aeb0 100644 --- a/docs/architecture/tendcf-validate-proposal-2026-11-03.md +++ b/docs/architecture/tendcf-validate-proposal-2026-11-03.md @@ -1127,6 +1127,113 @@ also bears on pastebin, which already is (see above). Run test 1 against the current policy first: it must actuate the service. That reproduces the fail-open before the fix. +**Implemented 2026-11-06: option 3, per djbclark's ruling Q10 (2026-11-02).** +`bundle common tendcf_cmdb` in `policy/tendcf_services.cf` reads +`$(sys.workdir)/data/host_specific.json` with `readjson` (5 MiB cap) and +compares it with the data the loader installed. For every `vars` key it +requires `data:variables.` to exist, the key's entry ids to equal the +loaded container's indices (a half-loaded container is caught), and the whole +container to be identical: `storejson()` of the file's `vars[]` against +`storejson()` of `data:variables.`, string-equal, with a comparison that +cannot be computed counted as a problem of its own (not as the absence of a +difference). (Ids alone were the first +version; same ids with another value, which a `variables` section gives, passed +it. Both texts come from the one parser, so key order and number formatting +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 +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.*` +that is not a `vars` key of the file, a file that exists but cannot be +parsed, and loaded data with no file. A missing file with nothing loaded is +the normal empty case and says nothing. + +Round 2 of the review (Astra A1, adversary M1) added the loaded-state check +and the single read. A preset reaches the checker itself: a `vars` key such as +`default:tendcf_cmdb.doc` or `default:tendcf_services.interlock_ids` is +installed before the policy runs. Whether it survives depends on the promise: a +promise whose rvalue is a function call is skipped when the variable exists +(`verify_vars.c`, "Already did this") if the call was not already evaluated, +and otherwise redefines it; the CI runs of check 9 saw presets of both kinds. +The policy does not rely on which: it reads the loaded state directly, in class +expressions that call the functions inline (no variable to preset), and refuses +any variable tagged `source=cmdb` or `source=augments_file` outside +`data:variables.` (`variablesmatching`) and any class with either +tag (`classmatch`). tendcf ships no `def.json`, so augments are refused too (a +host that needs one must be exempted in the policy, on purpose). The content +comparison no longer reads the negation of a class set once and never cleared +(`tendcf_cmdb_json_equal_*`); `tendcf_cmdb_problem_differs_` is defined +from the current texts, `..._uncomparable_` from a side that could not be +serialised, and `..._noverdict_` when both texts exist but neither +equality nor a difference could be evaluated (`strcmp()` is skipped when an +argument still holds `$(`, which a file replaced after the loader's read can +give; the positive `tendcf_cmdb_json_same_` it reads only silences that +one refusal and cannot hide a difference). Measured on the pinned fork (check +11, debug run of a real cf-agent, the replaced-file case, CI run 43626676907 +at 87a4b58): `tendcf_cmdb` was resolved 2 times, the `doc` promise visited 1 +time, `file_json[..]` 10 times and `tendcf_cmdb_refused` 2 times, and the +mutation script ran 1 time. A class is set once and never cleared; a class +still unset is evaluated again on the second resolution, from the same +snapshot. Its vars are visited on every resolution, so a later pass could have +read a file the classes never compared. `doc` is +therefore read once (its promise is skipped once it exists) and every +comparison input derives from that snapshot. Check 11 pins both timings of a +file replaced during the run: before the read the comparison refuses ("content +differs", nothing runs); after it the policy never sees the replacement and +acts on the loaded data it checked. Reports print file-derived text only with +characters outside `[A-Za-z0-9._:@/-]` replaced by `?` and cut to a fixed +length (64 characters for a key, section name or id, whether or not it is a +plain identifier). The check and the gated bundles share one file because the +fork resolves each file when it is loaded and the whole policy again after; +were they split, the literal empty id lists under a refusal would still +redefine the ids, so the split would fail closed. `tendcf-install.sh data` +installs by atomic rename. Not checked: a file +replaced after the last read (no check can see it). + +On any mismatch it defines the one +class `tendcf_cmdb_refused`, and `tendcf_interlocks` reports what differs +once. Both bundles then set `interlock_ids` and `service_ids` to explicitly +empty lists (an undefined list would leave a preset one in place; a literal +rvalue does redefine a preset, a function call does not), and the two +`daemon-reload` commands, which iterate no id, carry the refusal themselves: +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)), +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 +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. + +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 +(`8f0076b81` is not an ancestor): an unresolved `$(...)` anywhere in `vars` +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 +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 +changes with this change (§13(b) option 3, §13(c)). + +PR: https://github.com/frdminc/tendcf/pull/42 + ## 14. Review record Gemini 4 Argon reviewed commit `a7b7c31` (2026-11-02; verdict "sound diff --git a/policy/tendcf_services.cf b/policy/tendcf_services.cf index a993615..29f0508 100644 --- a/policy/tendcf_services.cf +++ b/policy/tendcf_services.cf @@ -59,12 +59,404 @@ # commands: daemon-reload, enable/disable, start, restart, teardown, # reload after removal. State probes are snapshots (see the classes # section), so one run converges and the next does nothing. +# +# 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: +# - 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_*`); +# 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 +# loader reads a key as a variable reference (cmdb.c GetCMDBVariableRef, +# VarRefParse): `a.b` lands in scope a, `ns:b.c` in another namespace, +# `a[i]` is an array element. Such a key can preset a variable of THIS +# policy (`default:tendcf_services.service_ids`), so it is refused; +# - for every key under `vars`, `data:variables.` must exist; +# - per key, the set of entry ids in the file must equal the set of +# indices of the loaded container (a half-loaded container is caught); +# - per key, the whole container the loader installed must equal the file's: +# storejson() of `doc[vars][]` against storejson() of +# `data:variables.`, string-equal (same parser and same bytes give the +# same text, key order and number formatting included). A value that is not +# an object is refused when it reads back differently: the loader installs +# 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 +# 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; +# - every `data:variables.*` the loader installed must be a key of `vars` +# in the file; +# - nothing the loader installed may lie outside `data:variables.`: +# no CMDB-installed variable of any other name, and no CMDB-installed class. +# This is read from the loaded state (the variable table and the class +# table, by the tag the loader puts on everything it installs, +# `source=cmdb`), not from the file, in class expressions that call +# variablesmatching() and classmatch() inline, so it names no variable that +# a CMDB key could preset. It is what keeps the checker's own variables and +# the gates' id lists out of reach (see "Presets" below). It also covers the +# augments file (`def.json`, tag `source=augments_file`, loaded after the +# CMDB): tendcf ships none, and a variable or class from one is refused +# the same way (a host that needs a `def.json` must be given an exemption +# here, deliberately); +# - a file that exists but cannot be parsed (or exceeds the loader's own +# 5 MiB cap), and loaded data with no file at all, are mismatches. +# A missing file with nothing loaded is the normal empty case: no class, no +# report. A key the loader files elsewhere (`a.b`, `ns:b.c`) cannot match +# `data:variables.`, so it reads as a mismatch: refused, never ignored. +# The data directory is `$(sys.workdir)/data` here; the loader uses +# GetDataDir() (CF_DATADIR, default /data). A build with another data +# dir would compare against the wrong file and mostly fail closed. +# +# On any mismatch the single class `tendcf_cmdb_refused` is defined and +# NOTHING is actuated: no interlock pre_action, no service, no tombstone. The +# gate is one place per bundle: `interlock_ids` and `service_ids` are set to +# empty lists under the refusal, and every promise that acts iterates one of +# them. The two daemon-reload commands, which iterate no id, carry +# `!tendcf_cmdb_refused` themselves (a `classes` section could otherwise define +# their trigger classes; it is refused as well, but a refusal must not depend on +# that). A new actuating promise MUST iterate those ids or carry +# `!tendcf_cmdb_refused` itself. The mismatch is reported once, by +# tendcf_interlocks. Reports print file-derived text (keys, entry ids, section +# names) only after replacing every character outside [A-Za-z0-9._:@/-] with `?` +# and cutting it to a fixed length; the refusal summary and the foreign +# variable and class reports are static text. +# +# 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 +# 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 +# otherwise redefines it; which of the two happens is not something this policy +# relies on (tests/policy/run.sh check 9 saw both: some presets of the checker's +# and the gates' variables stayed, some were replaced by the policy's value). +# So the check does not try to make each variable immune: any variable the CMDB +# (or an augments file) installed under a name other than +# `data:variables.` and still carrying the loader's tag when the +# classes are evaluated makes `tendcf_cmdb_problem_foreign_var`, read from the +# variable table, and a preset that was replaced is the policy's own value. The +# checker's `doc` is guarded to be read once, so a preset of it is never +# overwritten by a later pass and is refused by that class. Under the refusal +# the id lists are literal empty lists, which redefine a preset. +# +# Order and evaluation, as measured on the pinned fork (tests/policy/run.sh +# check 11, debug run of a real cf-agent, the replaced-file case): `tendcf_cmdb` +# was resolved 2 times, its vars `doc` promise was visited 1 time (skipped once +# `doc` exists), `file_json[..]` 10 times and the class `tendcf_cmdb_refused` 2 +# times; the mutation script ran 1 time. So the vars are visited on every +# resolution, and a class is set once and never cleared, while a class that is +# still unset is evaluated again on the second resolution, from the same +# snapshot. The fork evaluates the vars and the classes of every +# `bundle common` before the vars of any other bundle, independently of +# `bundlesequence` (PolicyResolve and BundleResolve, libpromises/expand.c:846-871 +# and 1145-1177), so `tendcf_cmdb_refused` is decided, on the first pass over +# the file, before the `!tendcf_cmdb_refused` on the agent bundles' `*_ids` is +# first read. A later vars pass that re-read the file would see a replacement +# the decision never compared, so `doc` is read ONCE: its promise is skipped +# once `doc` exists, every comparison input is derived from that one snapshot, +# and no later pass reads the file. The probe of check 11 replaces the file +# between the passes and shows that the loaded data are acted on and the +# replacement is not. Each problem class is defined from the current comparison, +# in positive form (a difference, an uncomputable side, a foreign variable), +# never as the negation of a class set once and never cleared: a promise for an +# already-set class is skipped (libpromises/promises.c), so "not equal" read +# from a sticky "equal" class would stay false after a later mismatch. The +# classes of the common bundle run in one pass in written order: +# `tendcf_cmdb_refused` comes after every `tendcf_cmdb_problem_*` class; do not +# reorder them. `tendcf_cmdb_json_same_` (the two texts are equal) is read +# only by `..._problem_noverdict_`, which refuses a comparison that gave +# neither "equal" nor "differs" (strcmp() is skipped when an argument still holds +# `$(`); it comes after the classes it reads and cannot hide a difference. +# +# One file on purpose: the fork resolves each file's bundles when it is loaded +# and the whole policy again afterwards (libpromises/loading.c), so `tendcf_cmdb` +# decides in the file it shares with the gated bundles, before their ids are +# first read. Were it split off, the literal empty `*_ids` lists under the +# refusal would still redefine the ids, so it would fail closed, but this is why +# the bundles live together. +# +# What is NOT guaranteed: the check compares the file with the loader's state at +# the evaluation. A file replaced after the last evaluation, or by a promise +# that changes `data:variables.*` afterwards, is not seen; and nothing here makes +# a publication atomic (`tendcf-install.sh data` installs by atomic rename, but +# the agent can still start between the loader's read and ours). Not a sandbox +# either: it is a consistency check between the file and what the loader +# installed. A CMDB author (root) already chooses each pre_action executable, +# `/bin/sh -c ...` included, and the unit commands, so it does not stop a hostile +# but self-consistent file; it stops a file and a loader that disagree, and the +# sections, keys, variables and classes through which a file could change what +# the policy reads without showing up as a `vars` difference. + +bundle common tendcf_cmdb +{ + vars: + "file" + string => "$(sys.workdir)/data/host_specific.json"; + + # 5242880 = the loader's HOST_SPECIFIC_DATA_MAX_SIZE (5 MiB). An absent + # file leaves `doc` undefined and is not an error. + # + # Read ONCE (see "Order and evaluation"): the engine visits this promise on + # every later pass, and a second read could return a file the classes never + # compared. `not(isvariable("doc"))` skips it once `doc` exists, a preset + # included (which is then refused as a foreign variable). + "doc" + data => readjson("$(file)", 5242880), + ifvarclass => and(fileexists("$(file)"), not(isvariable("doc"))); + + "file_keys" + slist => getindices("doc[vars]"), + ifvarclass => isvariable("doc[vars]"); + + "file_keys" + slist => { }, + ifvarclass => not(isvariable("doc[vars]")); + + # Top-level sections of the file. The loader applies `vars`, `variables` + # and `classes` (cmdb.c LoadCMDBData); the projector emits only `vars`, + # and anything else is refused (class `..._problem_sections`). A top-level + # array reads as indices "0", "1", ... here and is refused the same way. + "doc_sections" + slist => getindices("doc"), + ifvarclass => isvariable("doc"); + + "doc_sections" + slist => { }, + ifvarclass => not(isvariable("doc")); + + "allowed_sections" + slist => { "vars" }; + + "extra_sections" + slist => difference("doc_sections", "allowed_sections"); + + # Only a plain identifier is a `vars` key this policy will look up. The + # grep() pattern is anchored by CFEngine. Every other key is refused as a + # whole (`..._problem_badkey`) and is never used to build a variable name + # below. + "safe_keys" + slist => grep("[A-Za-z0-9_]+", "file_keys"); + + "bad_keys" + slist => difference("file_keys", "safe_keys"); + + "loaded_refs" + slist => variablesmatching("^data:variables\..*"); + + "loaded_keys" + slist => maplist(regex_replace("$(this)", "^data:variables\.", "", ""), + "loaded_refs"); + + "missing_keys" + slist => difference("file_keys", "loaded_keys"); + + "unlisted_keys" + slist => difference("loaded_keys", "file_keys"); + + # Printable forms for the reports: every character outside the safe set + # becomes `?`, then each name is cut to 64 characters (two steps, each the + # same maplist idiom as loaded_keys). Keys, ids and section names come + # from the file and may hold newlines or escape sequences. + "missing_san" + slist => maplist(regex_replace("$(this)", "[^A-Za-z0-9._:@/-]", "?", "g"), + "missing_keys"); + "missing_clean" + slist => maplist(string_head("$(this)", 64), "missing_san"); + + "unlisted_san" + slist => maplist(regex_replace("$(this)", "[^A-Za-z0-9._:@/-]", "?", "g"), + "unlisted_keys"); + "unlisted_clean" + slist => maplist(string_head("$(this)", 64), "unlisted_san"); + + "bad_san" + slist => maplist(regex_replace("$(this)", "[^A-Za-z0-9._:@/-]", "?", "g"), + "bad_keys"); + "bad_clean" + slist => maplist(string_head("$(this)", 64), "bad_san"); + + "sections_san" + slist => maplist(regex_replace("$(this)", "[^A-Za-z0-9._:@/-]", "?", "g"), + "extra_sections"); + "sections_clean" + slist => maplist(string_head("$(this)", 64), "sections_san"); + + "loaded_san" + slist => maplist(regex_replace("$(this)", "[^A-Za-z0-9._:@/-]", "?", "g"), + "loaded_keys"); + "loaded_clean" + slist => maplist(string_head("$(this)", 64), "loaded_san"); + + "key_canon[$(safe_keys)]" + string => canonify("$(safe_keys)"); + + # The key as a report shows it: at most 64 characters (a safe key is a plain + # identifier, so no character replacement is needed, but its length is not + # bounded). Lookups and class names keep using the full `safe_keys`. + "key_clean[$(safe_keys)]" + string => string_head("$(safe_keys)", 64); + + "file_ids[$(safe_keys)]" + slist => getindices("doc[vars][$(safe_keys)]"); + + "loaded_ids[$(safe_keys)]" + slist => getindices("data:variables.$(safe_keys)"); + + "unloaded_ids[$(safe_keys)]" + slist => difference("file_ids[$(safe_keys)]", "loaded_ids[$(safe_keys)]"); + + "unfiled_ids[$(safe_keys)]" + slist => difference("loaded_ids[$(safe_keys)]", "file_ids[$(safe_keys)]"); + + "unloaded_san[$(safe_keys)]" + slist => maplist(regex_replace("$(this)", "[^A-Za-z0-9._:@/-]", "?", "g"), + "unloaded_ids[$(safe_keys)]"); + + "unloaded_clean[$(safe_keys)]" + slist => maplist(string_head("$(this)", 64), "unloaded_san[$(safe_keys)]"); + + "unloaded_joined[$(safe_keys)]" + string => join(", ", "unloaded_clean[$(safe_keys)]"); + + "unloaded_text[$(safe_keys)]" + string => string_head("$(unloaded_joined[$(safe_keys)])", 400); + + "unfiled_san[$(safe_keys)]" + slist => maplist(regex_replace("$(this)", "[^A-Za-z0-9._:@/-]", "?", "g"), + "unfiled_ids[$(safe_keys)]"); + + "unfiled_clean[$(safe_keys)]" + slist => maplist(string_head("$(this)", 64), "unfiled_san[$(safe_keys)]"); + + "unfiled_joined[$(safe_keys)]" + string => join(", ", "unfiled_clean[$(safe_keys)]"); + + "unfiled_text[$(safe_keys)]" + string => string_head("$(unfiled_joined[$(safe_keys)])", 400); + + # The whole container, as JSON text, from the file and as installed. + # storejson() fails (the variable stays undefined) for anything that is + # not a container or list, and for a name that is not defined; the + # `uncomparable` class below makes an undefined side a problem. + "file_json[$(safe_keys)]" + string => storejson("doc[vars][$(safe_keys)]"); + + "loaded_json[$(safe_keys)]" + string => storejson("data:variables.$(safe_keys)"); + + classes: + "tendcf_cmdb_problem_unreadable" + expression => and(fileexists("$(file)"), + not(isvariable("tendcf_cmdb.doc"))); + + "tendcf_cmdb_problem_nofile" + expression => and(not(fileexists("$(file)")), + isgreaterthan(length("loaded_keys"), 0)); + + "tendcf_cmdb_problem_missing" + expression => isgreaterthan(length("missing_keys"), 0); + + "tendcf_cmdb_problem_unlisted" + expression => isgreaterthan(length("unlisted_keys"), 0); + + "tendcf_cmdb_problem_sections" + expression => isgreaterthan(length("extra_sections"), 0); + + "tendcf_cmdb_problem_badkey" + expression => isgreaterthan(length("bad_keys"), 0); + + # Read from the loaded state, with the calls inline: no variable here for + # a CMDB key to preset. Every variable tagged by the CMDB loader or by the + # augments loader is counted, and so is every one of them that is exactly + # data:variables. AND tagged by the CMDB loader; any excess is + # a variable of another name (or from augments), which is a problem. + "tendcf_cmdb_problem_foreign_var" + expression => isgreaterthan(length(variablesmatching(".*", "source=cmdb", "source=augments_file")), + length(variablesmatching("data:variables\.[A-Za-z0-9_]+", "source=cmdb"))); + + "tendcf_cmdb_problem_foreign_class" + expression => classmatch(".*", "source=cmdb", "source=augments_file"); + + "tendcf_cmdb_problem_partial_$(key_canon[$(safe_keys)])" + expression => and(isvariable("data:variables.$(safe_keys)"), + or(isgreaterthan(length("unloaded_ids[$(safe_keys)]"), 0), + isgreaterthan(length("unfiled_ids[$(safe_keys)]"), 0))); + + # The two texts, computed now, differ. Defined only when both exist (an + # undefined side leaves the strcmp() argument unexpanded and the + # expression undefined; that case is the next class). + "tendcf_cmdb_problem_differs_$(key_canon[$(safe_keys)])" + expression => and(isvariable("data:variables.$(safe_keys)"), + isvariable("file_json[$(safe_keys)]"), + isvariable("loaded_json[$(safe_keys)]"), + not(strcmp("$(file_json[$(safe_keys)])", + "$(loaded_json[$(safe_keys)])"))); + + # The two texts, computed now, are equal. Positive and set once, like every + # class here, and it is read only by the no-verdict class below, so it can + # only silence a no-verdict refusal; it never suppresses + # `..._problem_differs_` or `..._problem_uncomparable_`, which do not read + # it. The inputs are one snapshot (`doc` is read once, the loaded + # containers do not change), so the comparison gives the same result on + # every evaluation. + "tendcf_cmdb_json_same_$(key_canon[$(safe_keys)])" + expression => and(isvariable("data:variables.$(safe_keys)"), + isvariable("file_json[$(safe_keys)]"), + isvariable("loaded_json[$(safe_keys)]"), + strcmp("$(file_json[$(safe_keys)])", + "$(loaded_json[$(safe_keys)])")); + + # A loaded container for which one side could not be serialised. Needs only + # isvariable(), whose arguments are literal names, so it cannot be + # suppressed by an undefined variable. + "tendcf_cmdb_problem_uncomparable_$(key_canon[$(safe_keys)])" + expression => and(isvariable("data:variables.$(safe_keys)"), + or(not(isvariable("file_json[$(safe_keys)]")), + not(isvariable("loaded_json[$(safe_keys)]")))); + + # Both containers serialised, and yet neither "equal" nor "differs" was + # computed: strcmp() is skipped (the call fails, so the class stays + # undefined) when an argument still holds `$(` or `${` after expansion, + # which a file replaced after the loader's read can give (the loader itself + # refuses `$(`, `${`, `@(`, `@{` in a key or a value). No verdict is not + # agreement: refuse. Written after the two classes it reads. + "tendcf_cmdb_problem_noverdict_$(key_canon[$(safe_keys)])" + expression => and(isvariable("data:variables.$(safe_keys)"), + isvariable("file_json[$(safe_keys)]"), + isvariable("loaded_json[$(safe_keys)]"), + not("tendcf_cmdb_json_same_$(key_canon[$(safe_keys)])"), + not("tendcf_cmdb_problem_differs_$(key_canon[$(safe_keys)])")); + + "tendcf_cmdb_refused" + expression => classmatch("tendcf_cmdb_problem_.*"); +} bundle agent tendcf_interlocks { vars: + # Empty under a CMDB mismatch (see `tendcf_cmdb`): with no ids no + # pre_action command is even built. Set explicitly, not left undefined: + # a `vars` key such as "default:tendcf_interlocks.interlock_ids" would + # have preset the list before the policy loaded, and a skipped promise + # does not remove it. + "interlock_ids" + slist => getindices("data:variables.tendcf_interlock"), + ifvarclass => "!tendcf_cmdb_refused"; + "interlock_ids" - slist => getindices("data:variables.tendcf_interlock"); + slist => { }, + ifvarclass => "tendcf_cmdb_refused"; "interlock_canon[$(interlock_ids)]" string => canonify("$(interlock_ids)"); @@ -139,16 +531,71 @@ bundle agent tendcf_interlocks # still is. "tendcf: interlock '$(interlock_ids)' pre_action command[0] is not an absolute path; refused" if => not(regcmp("/.*", "$(pre_action_cmd[$(interlock_ids)])")); + + # The one report of a CMDB mismatch (tendcf_cmdb decides, this says). + # First bundle of the sequence, so it comes before anything else. + "tendcf_cmdb_refused":: + "tendcf: CMDB cross-check failed: refusing to actuate anything (no interlock pre_action, no service, no tombstone) until $(tendcf_cmdb.file) and the data CFEngine loaded from it agree"; + + "tendcf_cmdb_problem_unreadable":: + "tendcf: CMDB cross-check: $(tendcf_cmdb.file) exists but cannot be read as JSON (parse error or larger than 5242880 bytes)"; + + "tendcf_cmdb_problem_nofile":: + "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_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)"; + + "tendcf_cmdb_problem_partial_$(tendcf_cmdb.key_canon[$(tendcf_cmdb.safe_keys)])":: + "tendcf: CMDB cross-check: key '$(tendcf_cmdb.key_clean[$(tendcf_cmdb.safe_keys)])' loaded differently from $(tendcf_cmdb.file): in the file only: [$(tendcf_cmdb.unloaded_text[$(tendcf_cmdb.safe_keys)])]; loaded only: [$(tendcf_cmdb.unfiled_text[$(tendcf_cmdb.safe_keys)])]"; + + "tendcf_cmdb_problem_differs_$(tendcf_cmdb.key_canon[$(tendcf_cmdb.safe_keys)])":: + "tendcf: CMDB cross-check: key '$(tendcf_cmdb.key_clean[$(tendcf_cmdb.safe_keys)])' content differs between $(tendcf_cmdb.file) and the data CFEngine loaded"; + + "tendcf_cmdb_problem_uncomparable_$(tendcf_cmdb.key_canon[$(tendcf_cmdb.safe_keys)])":: + "tendcf: CMDB cross-check: key '$(tendcf_cmdb.key_clean[$(tendcf_cmdb.safe_keys)])' content could not be compared between $(tendcf_cmdb.file) and the data CFEngine loaded (one side is not a container or list)"; + + "tendcf_cmdb_problem_noverdict_$(tendcf_cmdb.key_canon[$(tendcf_cmdb.safe_keys)])":: + "tendcf: CMDB cross-check: key '$(tendcf_cmdb.key_clean[$(tendcf_cmdb.safe_keys)])' content comparison reached no verdict between $(tendcf_cmdb.file) and the data CFEngine loaded (a text that cannot be evaluated, such as one holding a variable reference)"; + + "tendcf_cmdb_problem_sections":: + "tendcf: CMDB cross-check: $(tendcf_cmdb.file) has top-level section '$(tendcf_cmdb.sections_clean)' besides 'vars'; only 'vars' is accepted (the loader would also apply 'variables' and 'classes')"; + + # Static text on purpose: the names are in `cf-promises --show-vars` + # (tag source=cmdb or source=augments_file) and `--show-classes`. + "tendcf_cmdb_problem_foreign_var":: + "tendcf: CMDB cross-check: the CMDB or an augments file installed a variable outside data:variables. (a preset of a variable of this policy or of another bundle); only data:variables. is accepted"; + + "tendcf_cmdb_problem_foreign_class":: + "tendcf: CMDB cross-check: the CMDB or an augments file defined a class; no class from either is accepted"; + + "tendcf_cmdb_problem_badkey":: + "tendcf: CMDB cross-check: key '$(tendcf_cmdb.bad_clean)' under 'vars' in $(tendcf_cmdb.file) is not a plain identifier ([A-Za-z0-9_]+); the loader would read it as a variable reference"; } bundle agent tendcf_services { vars: + # Empty under a CMDB mismatch, see tendcf_interlocks and `tendcf_cmdb` + # (set explicitly for the same reason as there). "service_ids" - slist => getindices("data:variables.tendcf_service"); + slist => getindices("data:variables.tendcf_service"), + ifvarclass => "!tendcf_cmdb_refused"; + + "service_ids" + slist => { }, + ifvarclass => "tendcf_cmdb_refused"; + + "interlock_ids" + slist => getindices("data:variables.tendcf_interlock"), + ifvarclass => "!tendcf_cmdb_refused"; "interlock_ids" - slist => getindices("data:variables.tendcf_interlock"); + slist => { }, + ifvarclass => "tendcf_cmdb_refused"; "service_canon[$(service_ids)]" string => canonify("$(service_ids)"); @@ -363,7 +810,7 @@ bundle agent tendcf_services # unit is on disk before the manager is told about it. "/usr/bin/systemctl" arglist => { "daemon-reload" }, - ifvarclass => "tendcf_systemd_reload"; + ifvarclass => "tendcf_systemd_reload.!tendcf_cmdb_refused"; "/usr/bin/systemctl" arglist => { "enable", "$(service_ids)" }, @@ -391,7 +838,7 @@ bundle agent tendcf_services # so a run that already reloaded for a render still reloads again. "/usr/bin/systemctl" arglist => { "--quiet", "daemon-reload" }, - ifvarclass => "tendcf_systemd_unit_removed"; + ifvarclass => "tendcf_systemd_unit_removed.!tendcf_cmdb_refused"; reports: "interlock_blocked_$(interlock_bundle_canon[$(interlock_ids)])":: diff --git a/tests/policy/fixtures/cmdb-checker-preset-keys.json b/tests/policy/fixtures/cmdb-checker-preset-keys.json new file mode 100644 index 0000000..c393ed8 --- /dev/null +++ b/tests/policy/fixtures/cmdb-checker-preset-keys.json @@ -0,0 +1 @@ +{"vars":{"tendcf_interlock":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/true"],"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":"/"}},"default:tendcf_services.service_ids":["demo-runit"],"default:tendcf_cmdb.bad_keys":[],"default:tendcf_cmdb.missing_keys":[]}} diff --git a/tests/policy/fixtures/cmdb-checker-preset.json b/tests/policy/fixtures/cmdb-checker-preset.json new file mode 100644 index 0000000..55279d3 --- /dev/null +++ b/tests/policy/fixtures/cmdb-checker-preset.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":"/"}},"default:tendcf_cmdb.doc":{"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":"/"}}}},"default:tendcf_services.interlock_ids":{}}} diff --git a/tests/policy/fixtures/cmdb-classes-hidden.json b/tests/policy/fixtures/cmdb-classes-hidden.json new file mode 100644 index 0000000..deb1a29 --- /dev/null +++ b/tests/policy/fixtures/cmdb-classes-hidden.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":"/"}},"default:tendcf_cmdb.extra_sections":[],"default:tendcf_cmdb.bad_keys":[],"default:tendcf_cmdb.missing_keys":[]},"classes":{"interlock_ok_demo_check":"any::"}} diff --git a/tests/policy/fixtures/cmdb-classes-section.json b/tests/policy/fixtures/cmdb-classes-section.json new file mode 100644 index 0000000..a37d1b1 --- /dev/null +++ b/tests/policy/fixtures/cmdb-classes-section.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":{"interlock_ok_demo_check":"any::"}} diff --git a/tests/policy/fixtures/cmdb-scoped-preset.json b/tests/policy/fixtures/cmdb-scoped-preset.json new file mode 100644 index 0000000..776dde4 --- /dev/null +++ b/tests/policy/fixtures/cmdb-scoped-preset.json @@ -0,0 +1 @@ +{"vars":{"default:tendcf_interlocks.interlock_ids":["demo-check"],"default:tendcf_services.interlock_ids":["demo-check"],"default:tendcf_services.service_ids":["demo-runit"],"tendcf_interlock":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/true"],"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/cmdb-variables-collision.json b/tests/policy/fixtures/cmdb-variables-collision.json new file mode 100644 index 0000000..23317a6 --- /dev/null +++ b/tests/policy/fixtures/cmdb-variables-collision.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":{}},"variables":{"tendcf_interlock":{"value":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/true"],"expect_exit":0,"timeout_seconds":5},"report":true,"state":"present"}}}}} diff --git a/tests/policy/fixtures/interlock-malformed.json b/tests/policy/fixtures/interlock-malformed.json new file mode 100644 index 0000000..181b1bf --- /dev/null +++ b/tests/policy/fixtures/interlock-malformed.json @@ -0,0 +1 @@ +{"vars":{"tendcf_interlock":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/false","$(sys.workdir)"],"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/runit-pair.json b/tests/policy/fixtures/runit-pair.json new file mode 100644 index 0000000..40447e7 --- /dev/null +++ b/tests/policy/fixtures/runit-pair.json @@ -0,0 +1 @@ +{"vars":{"tendcf_interlock":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/true"],"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":"/"},"demo-runit-two":{"bundle":"demo","command":["/bin/sleep","2"],"run_as":"nobody","state":"present","unit":{"runit":{"enabled":true}},"working_dir":"/"}}}} diff --git a/tests/policy/probe-mutate.cf b/tests/policy/probe-mutate.cf new file mode 100644 index 0000000..333c73b --- /dev/null +++ b/tests/policy/probe-mutate.cf @@ -0,0 +1,23 @@ +# Test only (tests/policy/run.sh check 11). A `bundle common` whose one job is to +# replace host_specific.json with a file that has the same keys and entry ids but +# another pre_action command, i.e. a publication during the run. Two timings, by +# class (cf-agent -D), so each is deterministic rather than a matter of +# evaluation order: +# probe_before the replacement is made from the first evaluation of this +# bundle; the entry lists this file BEFORE tendcf_services.cf, +# so it runs before tendcf_cmdb reads the file. +# probe_after the replacement is made only once tendcf_cmdb.doc exists, i.e. +# after tendcf_cmdb's read of the file, whatever the order. + +bundle common tendcf_probe_mutate +{ + vars: + probe_before:: + "ran_before" + string => execresult("$(sys.workdir)/probe-mutate.sh", "noshell"); + + probe_after:: + "ran_after" + string => execresult("$(sys.workdir)/probe-mutate.sh", "noshell"), + ifvarclass => isvariable("tendcf_cmdb.doc"); +} diff --git a/tests/policy/run.sh b/tests/policy/run.sh index c801c5c..fa233fc 100755 --- a/tests/policy/run.sh +++ b/tests/policy/run.sh @@ -51,6 +51,54 @@ # schema alphabet admits plus a sample of letters and digits, and a # metacharacter set); 8d refuses a relative command[0] from a projection # that skipped the schema. +# 9. CMDB cross-check against the agent's real loader (tendcf_cmdb in +# policy/tendcf_services.cf, proposal 2026-11-03 section 13 option 3): a +# file the loader cannot install whole is refused and reported and +# 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 +# `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 +# JSON text with the file's). Also refused, each actuating nothing: a CMDB +# `vars` key that presets a variable of the checker itself (`doc`, +# `bad_keys`, `missing_keys`) or of a gate (`interlock_ids`), which the +# engine would otherwise keep because a vars promise with a function-call +# rvalue is skipped when the variable exists; a `classes` section that is +# hidden from the file-based checks by such a preset; and an augments file +# (`def.json` in inputs/) that defines a class and a variable. A `vars` +# 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. +# 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 +# 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 +# fail-open; a skipped service container with the interlock loaded shows +# the first bundle (tendcf_interlocks, which runs pre_action commands) is +# gated too. Same ids with a changed value (a service's command, or an +# interlock's pre_action) are refused as a content difference, which no +# key-and-id comparison could see. Under TENDCF_TEST_SYSTEMD=1 the same stand-in is run against +# the real manager (6b): no unit rendered, a tombstone leaves the unit alone. +# 11. the engine's evaluation of tendcf_cmdb, measured on a real +# cf-agent with -d: how often the checker's variables and classes are +# visited, with the file replaced (same keys and ids, another pre_action) +# by a common bundle, in two deterministic timings: before the check's read +# (refused, "content differs", nothing runs) and after it (the policy reads +# the file once, so not refused, the loaded pre_action runs and the replaced +# one does not); a debug run counts the reads (the doc promise is evaluated +# once) and prints the other counts (`info:`). A third case swaps in a file +# whose pre_action element holds `$(` (strcmp() is skipped, so the comparison +# has no verdict): refused as "reached no verdict", nothing runs. # # The pre_action commands are /usr/bin/true and /usr/bin/false, which exist # on Linux and macOS alike; /bin/true does not exist on macOS, and a missing @@ -102,6 +150,14 @@ body common control bundlesequence => { "tendcf_interlocks", "tendcf_services" }; } EOF +# Same two bundles, with the stand-in loader first (see tests/policy/sim-loader.cf). +cat > "$work/inputs/sim-entry.cf" < { "$repo/tests/policy/sim-loader.cf", "$repo/policy/tendcf_services.cf" }; + bundlesequence => { "tendcf_interlocks", "tendcf_services" }; +} +EOF fail=0 check() { # check NAME COND... @@ -109,6 +165,19 @@ check() { # check NAME COND... if "$@"; then echo "ok $name"; else echo "FAIL $name"; fail=1; fi } +# 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 +# a service or an interlock entry at all (each prints a "tendcf: service|interlock" +# report when it is processed, and `*_ids` are empty under a refusal). +refusal_reported() { grep -q "tendcf: CMDB cross-check failed: refusing to actuate anything" "$1"; } +refusal_once() { [ "$(grep -c "CMDB cross-check failed" "$1")" = 1 ]; } +no_crosscheck() { ! grep -q "CMDB cross-check" "$1"; } +no_actuation() { ! grep -Eq "Executing|Created file|launchctl|systemctl|tendcf: (service|interlock) '" "$1"; } +foreign_var_reported() { grep -q "tendcf: CMDB cross-check: the CMDB or an augments file installed a variable outside" "$1"; } +foreign_class_reported() { grep -q "tendcf: CMDB cross-check: the CMDB or an augments file defined a class" "$1"; } +key_not_loaded() { grep -q "key '$2' is under 'vars' in .* but CFEngine did not load data:variables.$2" "$1"; } + echo "# 1. wiring: cf-promises with examples/host_specific.json" cp "$repo/examples/host_specific.json" "$work/data/host_specific.json" check "cf-promises parses the bundle with the example projection" \ @@ -215,6 +284,22 @@ if [ "$(uname)" = Linux ] && [ -d /run/systemd/system ]; then unit_enabled() { as_root systemctl is-enabled --quiet "$unit"; } main_pid() { systemctl show -p MainPID --value "$unit"; } + sysd_run_sim() { # sysd_run_sim FIXTURE CLASSES OUT: stand-in loader, run as root + cp "$repo/tests/policy/fixtures/$1" "$work/data/host_specific.json" + as_root env CFENGINE_TEST_OVERRIDE_WORKDIR="$work" \ + "$cf_agent" -K -v --no-host-specific-data -D "$2" -f "$work/inputs/sim-entry.cf" >"$3" 2>&1 || true + as_root chown -R "$(id -u):$(id -g)" "$work" + } + + # 6b. Refused by the CMDB cross-check (check 10): the interlock container + # was skipped, the service loaded. Nothing may be rendered or started. + sysd_run_sim systemd-present.json sim_service "$work/sysd-sim-present.out" + check "cross-check refusal on a real systemd host: reported" \ + refusal_reported "$work/sysd-sim-present.out" + check "cross-check refusal: no unit rendered" bash -c "[ ! -e '$unit_path' ]" + check "cross-check refusal: no systemctl command or probe" \ + no_systemctl "$work/sysd-sim-present.out" + sysd_run systemd-present.json "$work/sysd1.out" check "no refusal reported on a normal systemd host" \ bash -c "! grep -q \"'$unit' refused\" '$work/sysd1.out'" @@ -230,6 +315,16 @@ if [ "$(uname)" = Linux ] && [ -d /run/systemd/system ]; then check "unit enabled after the first run" unit_enabled pid1="$(main_pid)" + # 6b, tombstone: the unit is live; a refused run must leave it alone. + sysd_run_sim systemd-absent.json sim_service "$work/sysd-sim-tomb.out" + check "cross-check refusal (tombstone): reported" \ + refusal_reported "$work/sysd-sim-tomb.out" + check "cross-check refusal (tombstone): unit file left in place" \ + bash -c "[ -f '$unit_path' ]" + check "cross-check refusal (tombstone): unit still active" unit_active + check "cross-check refusal (tombstone): no systemctl command or probe" \ + no_systemctl "$work/sysd-sim-tomb.out" + sysd_run systemd-present.json "$work/sysd2.out" check "second run issues no systemctl command" no_systemctl "$work/sysd2.out" check "second run leaves the same process" \ @@ -450,8 +545,342 @@ check "relative command[0]: the reason is reported" \ check "relative command[0]: nothing was run" \ bash -c "[ ! -e '$work/rel/ran' ]" +echo "# 9. CMDB cross-check, the agent's real loader" +cp "$repo/tests/policy/fixtures/interlock-malformed.json" "$work/data/host_specific.json" +out="$work/xc-malformed.out" +"$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true +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 +check "malformed interlock: refusal reported once" refusal_once "$out" +check "malformed interlock: nothing actuated, no pre_action run, no service processed" \ + no_actuation "$out" +for f in refused satisfied flavour; do + check "consistent file of the $f run (checks 2-4): no cross-check report" no_crosscheck "$work/$f.out" +done +rm -f "$work/data/host_specific.json" +out="$work/xc-nofile.out" +"$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true +check "no host_specific.json at all: no report" no_crosscheck "$out" +check "no host_specific.json at all: no error logged" bash -c "! grep -q 'error:' '$out'" +check "no host_specific.json at all: nothing actuated" no_actuation "$out" +printf '%s\n' '{"vars":{}}' >"$work/data/host_specific.json" +out="$work/xc-novars.out" +"$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true +check "empty vars: no report" no_crosscheck "$out" +check "empty vars: nothing actuated" no_actuation "$out" +printf '%s\n' '{bad' >"$work/data/host_specific.json" +out="$work/xc-garbage.out" +"$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true +check "unparseable file: refusal reported" refusal_reported "$out" +check "unparseable file: reported as unreadable" \ + grep -q "host_specific.json exists but cannot be read as JSON" "$out" +check "unparseable file: refusal reported once" refusal_once "$out" +check "unparseable file: nothing actuated" no_actuation "$out" + +# Consistent files from the other checks (8, 8c, 8d, and the systemd lifecycle +# when it ran): the whole-container comparison must not refuse a normal file, so +# key order and number formatting do not make a false refusal. +for f in noshell-or noshell-semi argv-alphabet argv-meta relative sysd1 sysd2 sysd3 sysd4 sysd5; do + [ -f "$work/$f.out" ] || continue + 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. +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'" +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" +check "variables-section collision: the replacement pre_action did not run" no_actuation "$out" + +# A `classes` section can define interlock_ok_demo_check, which would unblock the +# bundle whatever the pre_action returns (it is /usr/bin/false here). +cp "$repo/tests/policy/fixtures/cmdb-classes-section.json" "$work/data/host_specific.json" +out="$work/xc-classes.out" +"$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true +check "classes section: refusal reported" refusal_reported "$out" +check "classes section: the section is named" \ + grep -q "has top-level section 'classes' besides 'vars'" "$out" +check "classes section: nothing actuated (no pre_action, no service processed)" no_actuation "$out" + +# `vars` keys that name a variable of the policy's own bundles preset the id +# lists before the policy loads; a refusal must overwrite them, not leave them. +cp "$repo/tests/policy/fixtures/cmdb-scoped-preset.json" "$work/data/host_specific.json" +out="$work/xc-preset.out" +"$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true +check "scoped-key preset: refusal reported" refusal_reported "$out" +for k in default:tendcf_interlocks.interlock_ids default:tendcf_services.interlock_ids default:tendcf_services.service_ids; do + check "scoped-key preset: '$k' refused as not a plain identifier" \ + grep -q "key '$k' under 'vars' in .* is not a plain identifier" "$out" +done +check "scoped-key preset: refusal reported once" refusal_once "$out" +check "scoped-key preset: the preset id lists did not actuate" no_actuation "$out" +# The control that gives the case above its teeth: with no tendcf policy at all, +# the loader really does preset the policy's own variable from such a key (so the +# refusal had to overwrite it, not merely find it absent). +printf 'bundle agent main\n{\n}\n' > "$work/inputs/empty.cf" +"$cf_promises" --show-vars -f "$work/inputs/empty.cf" >"$work/xc-preset-vars.out" 2>&1 || true +check "scoped-key preset (control): the loader installed default:tendcf_services.service_ids" \ + bash -c "grep 'default:tendcf_services.service_ids' '$work/xc-preset-vars.out' | grep -q demo-runit" + +# A `vars` value that is not an object is installed as a scalar (not +# comparable: storejson() fails) or, for a list of primitives, as an slist of +# strings, so numbers read back as "1","2" and differ from the file's [1,2]: +# either way a problem (a difference, or one side that cannot be serialised), +# refused and named. (A list of strings compares equal and passes, below.) +printf '%s\n' '{"vars":{"tendcf_interlock":{},"tendcf_service":{},"scalar":"x","plain_list":[1,2]}}' >"$work/data/host_specific.json" +out="$work/xc-uncomparable.out" +"$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true +check "uncomparable vars values: refusal reported" refusal_reported "$out" +for k in scalar plain_list; do + check "uncomparable vars value '$k': named (differs or could not be compared)" \ + grep -Eq "key '$k' content (differs|could not be compared) between" "$out" +done +check "uncomparable vars values: the object containers are not blamed" \ + bash -c "! grep -Eq \"key 'tendcf_(interlock|service)' content (differs|could not be compared)\" '$out'" + +# A key that is a plain identifier but longer than the 64 characters a report +# may show (Astra round 3, A2): refused as before, and the report line shows at +# most its first 64 characters. The 70-character key is the loader's own scalar +# case again, so it is refused for the same reason as 'scalar' above. +long_key="$(printf 'k%.0s' $(seq 1 70))" +long_head="${long_key:0:64}" +printf '{"vars":{"tendcf_interlock":{},"tendcf_service":{},"%s":"x"}}\n' "$long_key" >"$work/data/host_specific.json" +out="$work/xc-longkey.out" +"$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true +check "long key: refusal reported" refusal_reported "$out" +check "long key: the report line shows its first 64 characters" \ + grep -Eq "key '$long_head' content (differs|could not be compared) between" "$out" +check "long key: no report line shows more than 64 characters of it" \ + bash -c "! grep -q 'key .${long_head}[A-Za-z0-9_]' '$out'" + +# A `vars` key can preset any variable of the policy, the checker's own included +# (adversary M1): a vars promise whose rvalue is a function call is skipped when +# the variable already exists (verify_vars.c, "Already did this"), so a preset +# `doc`, `bad_keys` or `missing_keys` of tendcf_cmdb, or an id list of the gates, +# stays. The policy refuses any CMDB-installed variable that is not +# data:variables. and any CMDB-installed class, read from the loaded +# state, so there is no variable of the checker's to preset. +for fx in checker-preset checker-preset-keys classes-hidden; do + cp "$repo/tests/policy/fixtures/cmdb-$fx.json" "$work/data/host_specific.json" + out="$work/xc-$fx.out" + "$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true + check "$fx: refusal reported" refusal_reported "$out" + if [ "$fx" != classes-hidden ]; then + check "$fx: the foreign variable is reported" foreign_var_reported "$out" + fi + check "$fx: refusal reported once" refusal_once "$out" + check "$fx: nothing actuated (no pre_action, no service processed)" no_actuation "$out" +done +# Its presets of the checker's variables are replaced by the policy's own values +# (check 11 shows function-call vars are re-evaluated), so the section and the +# class are what the policy sees; the foreign class is the loaded-state evidence. +check "classes-hidden: the foreign class is reported" foreign_class_reported "$work/xc-classes-hidden.out" +check "classes-hidden: the section is reported too" \ + grep -q "has top-level section 'classes' besides 'vars'" "$work/xc-classes-hidden.out" + +# Augments (def.json in inputs/) are loaded after the CMDB and can define classes +# and variables just the same. tendcf ships none, so any is refused. +cp "$repo/tests/policy/fixtures/interlock-refused.json" "$work/data/host_specific.json" +printf '%s\n' '{"classes":{"interlock_ok_demo_check":["any"]},"vars":{"probe":"x"}}' >"$work/inputs/def.json" +out="$work/xc-augments.out" +"$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true +rm -f "$work/inputs/def.json" +check "augments: refusal reported" refusal_reported "$out" +check "augments: the foreign variable is reported" foreign_var_reported "$out" +check "augments: the foreign class is reported" foreign_class_reported "$out" +check "augments: nothing actuated (the class would have unblocked the bundle)" no_actuation "$out" + +# Positive control (review B3): a `vars` container that is a list of strings +# round-trips through the loader's slist, so it is accepted and the run actuates. +printf '%s\n' '{"vars":{"tendcf_interlock":{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/true"],"expect_exit":0,"timeout_seconds":5},"report":true,"state":"present"}},"tendcf_service":{},"plain_strings":["a","b"]}}' >"$work/data/host_specific.json" +out="$work/xc-strlist.out" +"$cf_agent" -K -I -f "$work/inputs/entry.cf" >"$out" 2>&1 || true +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 "# 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" + else cp "$repo/tests/policy/fixtures/$1" "$work/data/host_specific.json"; fi + "$cf_agent" -K -I --no-host-specific-data -D "$2" -f "$work/inputs/sim-entry.cf" >"$3" 2>&1 || true +} +out="$work/xc-sim-control.out" +sim_run flavour-refused.json sim_interlock,sim_service "$out" +check "control (everything installed): no cross-check report" no_crosscheck "$out" +check "control: the pre_action ran" grep -q "Executing .*'/usr/bin/true'" "$out" +check "control: the service was processed" \ + grep -q "tendcf: service 'demo-runit' refused: unit flavour 'runit'" "$out" + +# The 2026-11-02 fail-open: the services loaded, their interlock did not. +out="$work/xc-sim-nointerlock.out" +sim_run flavour-refused.json sim_service "$out" +check "interlock container skipped: refusal reported" refusal_reported "$out" +check "interlock container skipped: tendcf_interlock named" key_not_loaded "$out" tendcf_interlock +check "interlock container skipped: tendcf_service not blamed" \ + bash -c "! grep -q \"key 'tendcf_service'\" '$out'" +check "interlock container skipped: no service processed, nothing actuated" no_actuation "$out" + +# The reverse, which also proves the FIRST bundle is gated: the interlock +# loaded, so tendcf_interlocks would run its pre_action. +out="$work/xc-sim-noservice.out" +sim_run flavour-refused.json sim_interlock "$out" +check "service container skipped: refusal reported" refusal_reported "$out" +check "service container skipped: tendcf_service named" key_not_loaded "$out" tendcf_service +check "service container skipped: the pre_action did not run (first bundle gated)" no_actuation "$out" + +out="$work/xc-sim-partial.out" +sim_run runit-pair.json sim_interlock,sim_service_partial "$out" +check "half-loaded container: refusal reported" refusal_reported "$out" +check "half-loaded container: the entry the loader lost is named" \ + grep -q "key 'tendcf_service' loaded differently from .*: in the file only: \[demo-runit-two\]; loaded only: \[\]" "$out" +check "half-loaded container: the whole key is not reported as missing" \ + bash -c "! grep -q 'did not load data:variables' '$out'" +check "half-loaded container: nothing actuated (the loaded entry is not processed either)" \ + no_actuation "$out" + +out="$work/xc-sim-stray.out" +sim_run runit-pair.json sim_interlock,sim_service,sim_stray "$out" +check "extra loaded variable: refusal reported" refusal_reported "$out" +check "extra loaded variable: named" \ + grep -q "CFEngine loaded data:variables.stray, which is not a key under 'vars'" "$out" +check "extra loaded variable: nothing actuated" no_actuation "$out" + +# Same ids, a changed value: what a loader that replaced an entry's value (or a +# file replaced between the loader's read and the policy's) would leave. Ids and +# keys match, so only the whole-container comparison can see it. +out="$work/xc-sim-changed-service.out" +sim_run flavour-refused.json sim_interlock,sim_service_changed "$out" +check "service value changed under the same id: refusal reported" refusal_reported "$out" +check "service value changed under the same id: the container is named" \ + grep -q "key 'tendcf_service' content differs between" "$out" +check "service value changed under the same id: not an id difference" \ + bash -c "! grep -q 'loaded differently' '$out'" +check "service value changed under the same id: tendcf_interlock not blamed" \ + bash -c "! grep -q \"key 'tendcf_interlock'\" '$out'" +check "service value changed under the same id: nothing actuated" no_actuation "$out" + +out="$work/xc-sim-changed-interlock.out" +sim_run interlock-refused.json sim_interlock_changed,sim_service "$out" +check "interlock value changed under the same id: refusal reported" refusal_reported "$out" +check "interlock value changed under the same id: the container is named" \ + grep -q "key 'tendcf_interlock' content differs between" "$out" +check "interlock value changed under the same id: tendcf_service not blamed" \ + bash -c "! grep -q \"key 'tendcf_service'\" '$out'" +check "interlock value changed under the same id: the passing pre_action did not run" no_actuation "$out" + +out="$work/xc-sim-nofile.out" +sim_run none sim_stray "$out" +check "data loaded with no file: refusal reported" refusal_reported "$out" +check "data loaded with no file: reported" \ + grep -q "host_specific.json does not exist but CFEngine loaded data:variables.stray" "$out" +check "data loaded with no file: nothing actuated" no_actuation "$out" + +echo "# 11. a file replaced during the run (tests/policy/probe-mutate.cf)" +# A (interlock-satisfied.json) is consistent with what the loader installed. A +# common bundle replaces it with B: same keys and ids, pre_action /usr/bin/false. +# Two timings, each with one expected outcome: +# before: B is on disk before the check reads the file. The check compares B +# with the loaded A and refuses ("content differs"); nothing runs. +# after: B appears only once tendcf_cmdb.doc exists (the probe's own guard), so +# after the check's read. The policy reads the file once (the `doc` promise +# is skipped once `doc` exists), so it never sees B: not refused, the loaded +# pre_action (true) runs, B's (false) never does, and doc is evaluated once. +# Ordering is evidenced by the outcome itself (a refusal naming a content +# difference only follows a read of B; the true/false split only a read of A) and +# by the probe's guard, not by text of a debug log: a debug log (-d) echoes the +# policy's own report strings, so it is only used for the visit counts. +cat > "$work/inputs/probe-before.cf" < { "$repo/tests/policy/probe-mutate.cf", "$repo/policy/tendcf_services.cf" }; + bundlesequence => { "tendcf_interlocks", "tendcf_services" }; +} +EOF2 +cat > "$work/inputs/probe-after.cf" < { "$repo/policy/tendcf_services.cf", "$repo/tests/policy/probe-mutate.cf" }; + bundlesequence => { "tendcf_interlocks", "tendcf_services" }; +} +EOF2 +cat > "$work/probe-mutate.sh" <> "$work/probe-count" +cp "$work/probe-B.json" "$work/data/host_specific.json" +EOF2 +chmod 700 "$work/probe-mutate.sh" +probe_a="$(cat "$repo/tests/policy/fixtures/interlock-satisfied.json")" +printf '%s\n' "${probe_a//\"\/usr\/bin\/true\"/\"\/usr\/bin\/false\"}" > "$work/probe-B.json" +probe_replaced() { [ "$(cat "$work/data/host_specific.json")" = "$(cat "$work/probe-B.json")" ]; } +probe_start() { cp "$repo/tests/policy/fixtures/interlock-satisfied.json" "$work/data/host_specific.json"; rm -f "$work/probe-count"; } + +probe_start +out="$work/xc-probe-before.out" +"$cf_agent" -K -I -D probe_before -f "$work/inputs/probe-before.cf" >"$out" 2>&1 || true +check "probe before the read: the file was replaced" probe_replaced +check "probe before the read: refused" refusal_reported "$out" +check "probe before the read: the content difference is named" \ + grep -q "key 'tendcf_interlock' content differs between" "$out" +check "probe before the read: nothing ran (neither the loaded nor the replaced pre_action)" no_actuation "$out" + +probe_start +out="$work/xc-probe-after.out" +"$cf_agent" -K -I -D probe_after -f "$work/inputs/probe-after.cf" >"$out" 2>&1 || true +check "probe after the read: the file was replaced" probe_replaced +check "probe after the read: not refused (the policy never saw the replacement)" no_crosscheck "$out" +check "probe after the read: the loaded pre_action (true) ran" \ + grep -q "info: Executing .*'/usr/bin/true'" "$out" +check "probe after the read: the replaced pre_action (false) did not" \ + bash -c "! grep -q \"info: Executing .*'/usr/bin/false'\" '$out'" + +# Visit counts, from a debug run of the after case. +probe_start +dbg="$work/xc-probe-debug.out" +"$cf_agent" -K -I -d -D probe_after -f "$work/inputs/probe-after.cf" >"$dbg" 2>&1 || true +n_doc="$(grep -c 'Evaluating vars promise: doc$' "$dbg" || true)" +n_json="$(grep -c 'Evaluating vars promise: file_json\[' "$dbg" || true)" +n_cls="$(grep -c 'Evaluating classes promise: tendcf_cmdb_refused$' "$dbg" || true)" +n_res="$(grep -c "Resolving classes and variables in 'bundle common tendcf_cmdb'" "$dbg" || true)" +n_mut="$(wc -l < "$work/probe-count" 2>/dev/null || echo 0)" +echo "info: tendcf_cmdb resolved $n_res times; vars 'doc' visited $n_doc times, 'file_json[..]' $n_json times; class 'tendcf_cmdb_refused' visited $n_cls times; mutation script ran $n_mut times" +check "probe (debug run): the mutation script ran" [ "$n_mut" -ge 1 ] +check "probe (debug run): the file is read once (doc promise evaluated once)" [ "$n_doc" = 1 ] + +# A comparison that has no verdict (adversary round 3, L1): B is A with one +# pre_action element changed to `/usr/bin/true$(nonexistent)`, swapped in before +# the check's read. strcmp() is skipped when an argument still holds `$(`, so +# neither a difference nor an equality is computed; the check must refuse anyway, +# name the key and run nothing. (The loader refuses `$(` in a value, so this can +# only be a file replaced after the loader's read, which is what the probe does.) +printf '%s\n' "${probe_a//\"\/usr\/bin\/true\"/\"\/usr\/bin\/true\$(nonexistent)\"}" > "$work/probe-B.json" +probe_start +out="$work/xc-probe-noverdict.out" +"$cf_agent" -K -I -D probe_before -f "$work/inputs/probe-before.cf" >"$out" 2>&1 || true +check "probe no verdict: the file was replaced" probe_replaced +check "probe no verdict: the replacement really holds a \$( element" \ + grep -qF "true\$(nonexistent)" "$work/data/host_specific.json" +check "probe no verdict: refused" refusal_reported "$out" +check "probe no verdict: the key is named" \ + grep -q "key 'tendcf_interlock' content comparison reached no verdict between" "$out" +check "probe no verdict: nothing ran (neither the loaded nor the replaced pre_action)" no_actuation "$out" + 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; do + 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 \ + 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 echo; echo "--- cf-agent output ($f) ---"; cat "$work/$f.out" done diff --git a/tests/policy/sim-loader.cf b/tests/policy/sim-loader.cf new file mode 100644 index 0000000..b35a30b --- /dev/null +++ b/tests/policy/sim-loader.cf @@ -0,0 +1,59 @@ +# 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 +# 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. +# +# Classes (-D, default namespace) pick what to install, each from the file: +# sim_interlock install tendcf_interlock as the file has it +# sim_service install tendcf_service as the file has it +# sim_service_partial install tendcf_service with only `demo-runit` +# sim_service_changed install tendcf_service with `demo-runit` under the same +# id but another command (/bin/sleep 2, not 1) +# sim_interlock_changed install tendcf_interlock with `demo-check` under the +# same id but pre_action /usr/bin/true (a loader that +# replaced the value of an entry it kept) +# sim_stray also install data:variables.stray + +body file control +{ + namespace => "data"; +} + +bundle common sim_source +{ + vars: + "doc" + data => readjson("$(sys.workdir)/data/host_specific.json", 5242880), + ifvarclass => fileexists("$(sys.workdir)/data/host_specific.json"); +} + +bundle common variables +{ + vars: + "tendcf_interlock" + data => mergedata("data:sim_source.doc[vars][tendcf_interlock]"), + ifvarclass => "default:sim_interlock"; + + "tendcf_service" + data => mergedata("data:sim_source.doc[vars][tendcf_service]"), + ifvarclass => "default:sim_service"; + + "tendcf_service" + data => parsejson('{"demo-runit":{"bundle":"demo","command":["/bin/sleep","1"],"run_as":"nobody","state":"present","unit":{"runit":{"enabled":true}},"working_dir":"/"}}'), + ifvarclass => "default:sim_service_partial"; + + "tendcf_service" + data => parsejson('{"demo-runit":{"bundle":"demo","command":["/bin/sleep","2"],"run_as":"nobody","state":"present","unit":{"runit":{"enabled":true}},"working_dir":"/"}}'), + ifvarclass => "default:sim_service_changed"; + + "tendcf_interlock" + data => parsejson('{"demo-check":{"blocks":"enclosing-bundle","bundle":"demo","defines_class":"demo_ok","pre_action":{"command":["/usr/bin/true"],"expect_exit":0,"timeout_seconds":5},"report":true,"state":"present"}}'), + ifvarclass => "default:sim_interlock_changed"; + + "stray" + string => "x", + ifvarclass => "default:sim_stray"; +}