Skip to content

Warned about CMDB keys whose dots are taken as a scope separator - #82

Open
djbclark wants to merge 46 commits into
masterfrom
fix/cmdb-dotted-key-warning-r3
Open

djbclark wants to merge 46 commits into
masterfrom
fix/cmdb-dotted-key-warning-r3

Conversation

@djbclark

@djbclark djbclark commented Nov 1, 2026

Copy link
Copy Markdown
Owner

GetCMDBVariableRef() hands a host_specific.json key to VarRefParse(),
which splits it at the first dot. A flat-looking key such as
"com.dotted.key" therefore installs the variable dotted.key in the
scope com, reachable as $(data:com.dotted.key), and not a variable of
the name that was written. Nothing said so.

Picking a scope this way is supported and policies rely on it, so the
behaviour is unchanged: the same variable is installed at the same address
as before. Only the logging is new, in vars and in variables
(classes are not scope-parsed and are not affected).

A key of the documented [namespace:]bundle.variable form cannot be told
from a deliberate scope qualification, so it is logged at verbose level
only; a warning on every agent run about a working configuration would be
noise. A key that cannot be of that form gets a warning naming the key and
the address it ended up at: an empty scope (.key), an empty variable name
(key.), or a variable name that still holds a dot (com.dotted.key),
which a vars promise cannot create. That is a judgement call, not a
certainty.

Unlike the earlier version of this change (fix/cmdb-dotted-key-warning-r2),
this one leaves AddCMDBVariable() and its key parameter alone and only
adds an else branch to GetCMDBVariableRef(), so it applies on its own
and together with the other libpromises/cmdb.c changes (name the
offending key, skip only the bad entry, JSON null crash). The three
"Installing CMDB variable" verbose messages are not touched either.

Fixes #11

Measured on the exact head 56c3352 (one
commit on upstream/master 5ac9805):

  • macOS acceptance 00_basics/06_host_specific_data: 12 pass, 0 fail,
    including the new 14-dotted-keys.cf.
  • Linux gate (u24 container, --enable-debug, as root): unit check 78/78
    rc=0, simulate_mode_test 5/5, 29_simulate_mode 7/7, own dir
    00_basics/06_host_specific_data 12 pass / 0 fail.
  • Negative control (same build, test kept): 14-dotted-keys.cf fails with
    libpromises/cmdb.c at upstream/master.
  • Merges without conflict with fix/cmdb-name-offending-key-r2,
    fix/cmdb-one-bad-entry-skips-only-that-entry-r2 and
    fix/cmdb-null-value-crash-r3 (each alone, all three merged in that order
    followed by this one, and this one merged with the three-way union).
    That union (throwaway, not pushed) builds, passes 06_host_specific_data
    16/16 on macOS and on the Linux gate (unit check 78/78, simulate 5/5
    and 7/7).
  • cfengine format --check clean on the new test and its JSON.

Adversary review (omp Claude Opus 5.5, read-only): APPROVE, no P0-P2. P3 notes, tracked in #81 : a this.x.y key stays silent; the warning is once per key per component invocation; the test has an unescaped . and no empty-half or verbose-line case; this branch overlaps with PR #58, which it supersedes.

🤖 Generated with Claude Code

victormlg and others added 30 commits October 28, 2026 12:55
Added the reactor tests to jenkins, to be able to run them in jenkins. This
means we can test cf-reactor on all the different platforms.

Signed-off-by: Victor Moene <victor.moene@northern.tech>
Made the logs prettier and added a log file where the xtrace is
printed

Signed-off-by: Victor Moene <victor.moene@northern.tech>
The guest environment cannot contain "-". On hosts containing "-", the
promise fails. The host name is now canonofied.

Signed-off-by: Victor Moene <victor.moene@northern.tech>
X509_get_subject_name() now returns a const name. Build a new
X509_NAME and set it as both subject and issuer instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Tests that print Pass message but have logs errors will fail with `FAIL (Error printed)` message.
Tests which are expected to log errors should use `.error.cf` or `.error.pass.cf` suffix. see: `tests/acceptance/README`

Ticket: CFE-3041
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
These tests read files created by their own init bundle, but pre-evaluation calls the read functions before the files exist, logging "Could not examine file" errors which now fail regular tests.

Ticket: CFE-3041
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
Errors printed by the command were reported on lines starting with "error:", so testall mistook them for errors of the test itself.

Ticket: CFE-3041

Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
These tests read files and directories created by their own policy, but pre-evaluation calls the functions before they exist, logging errors which now fail regular tests.

Ticket: CFE-3041
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
The agent loads def.json from the directory of the input policy file, so tests in 00_basics/ tried to read this directory as their augments file and logged "Could not open JSON file" errors.

Ticket: CFE-3041
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
The test used the 'immediate' body from plucked.sub.cf before it was
loaded during pre-evaluation, so the promise is now skipped until the
test framework is loaded.

Ticket: CFE-3041
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
The test referred to a promise module which never existed and did not run its init and cleanup bundles.

Ticket: CFE-3041
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
The check bundle counted lines in files which do not exist until the test bundle has run, but the agent evaluates the functions of all promises before any bundle runs.

Ticket: CFE-3041
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
wrong-bundle-type.cf printed the sub-agent output in its DEBUG report, so the sub-agent errors were mistaken for errors of the test, and ifelse.cf used invalid class expressions as false conditions.

Ticket: CFE-3041
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
These tests intentionally exercise error paths, the reason is documented in the header of each test.

Ticket: CFE-3041
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
Ticket: CFE-3041
Signed-off-by: Nick Anderson <nick@cmdln.org>
Ticket: CFE-3041
Signed-off-by: Nick Anderson <nick@cmdln.org>
The errorpass branch only checked for logged errors and the Pass
message, so a test marked test_soft_fail or test_skip_unsupported was
reported as FAIL (e.g. process_select_fncalls.error.pass.cf on Windows,
which soft fails due to ENT-10217 and logs no errors there). Errorpass
tests now go through the regular outcome handling and only differ in
requiring at least one logged error on Pass.
Ticket: CFE-3041
Signed-off-by: Nick Anderson <nick@cmdln.org>
Signed-off-by: Dhanraj E <dhanraj@labs.digiscrypt.com>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
…ptions() public

Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
The test promised the current user with policy "present" and expected
the promise to be kept. For an existing user, "present" also means
"not locked". When run as root, cf-reactor can read /etc/shadow, and if
the account's password hash starts with '!' (as root's does on some
systems), it is considered locked and gets unlocked. The promise was
then repaired instead of kept, and the test modified the root account.
As a normal user, /etc/shadow is unreadable, so the account was
considered unlocked and the test passed.

Instead, we modify the policy to always return "kept"

Signed-off-by: Victor Moene <victor.moene@northern.tech>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
larsewi and others added 16 commits October 29, 2026 13:05
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
…be created

Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
…per.c

Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
ENT-14766: Prepared cf-reactor event types for package events
ENT-14766: Moved package module wrapper from cf-agent to libpromises
Ticket: ENT-14765
Changelog: `cf-reactor` can now react to a user being added or removed, with the `user_added` and `user_removed` attributes of `when` bodies
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
CFE-3041: Made testall fail regular acceptance tests which log errors
…Jenkins

Added reactor tests to make check
ENT-14765: cf-reactor: Added user_added and user_removed events
…-path-overflow

fix stack buffer overflow in SaveAsFile backup path construction
GetCMDBVariableRef() hands the key to VarRefParse(), which splits it at the
first dot. A flat-looking key such as "com.dotted.key" therefore installs the
variable "dotted.key" in the scope "com", reachable as $(data:com.dotted.key)
and not as a variable of the name that was written. Nothing said so.

Picking a scope this way is a supported feature that policies rely on, so the
behaviour is unchanged: the same variable is installed at the same address as
before. Only the logging is new.

Where to draw the line matters more than the message, because a warning on
every agent run about a working configuration is worse than no warning at
all. A key of the documented "[namespace:]bundle.variable" form is
indistinguishable from a deliberate scope qualification, so it is reported at
LOG_LEVEL_VERBOSE only. A key that cannot be of that form gets
LOG_LEVEL_WARNING: that form has room for exactly one dot, and neither half
can be empty, so an empty scope (".key"), an empty variable name ("key.") or
a variable name that still contains a dot ("com.dotted.key") is something
else. The last case is the common one and the strongest signal, since a vars
promise splits its promiser the same way and so cannot create a variable
whose name contains a dot. This is a judgement call, not a certainty;
someone who really wants "bundle.a.b" now gets one line telling them exactly
where it landed.

The 'variables' section (CFE-3633) shares GetCMDBVariableRef() and is covered
by the same change. The 'classes' section is not affected: class names are
not scope-parsed, EvalContextClassPut() canonifies them.

Changelog: Title
Ticket: none
Signed-off-by: Daniel JB Clark <djbclark@gmail.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T19:32:07.045532Z 56c3352 PR opened
🔒 Security Review ✅ Completed 2026-11-01T19:32:52.820311Z 56c3352 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dotted CMDB keys silently become scope paths, with no warning

7 participants