mms host drift hash is an unkeyed SHA-256 over server env values and is printed in reports
Description
mms/drift.py compute_drift_hash returned sha256: + the first 16 hex chars of SHA-256 over a server's canonical form, which includes command, args and the full env mapping with values. Host configs often carry credentials in env. The hash was:
- persisted in
~/.mms/import_state.toml(drift_hash), and - printed by
mms host status --jsonasbaseline_hash/current_hash, and bymms host sync --jsoninplan.remove[],plan.cleanup[]andplan.skipped_changed[]. The text output never carried it.
Impact
Someone who sees a report (pasted into an issue, a chat or CI logs) and knows the rest of the server entry (often a shared template) can confirm a guessed credential value offline by recomputing the 64-bit digest. A reader of the report does not need access to the machine.
Measured on 0.7.8 with a throwaway HOME: the digest computed outside the package from a correct guess appears 5 times in mms host status --json and 3 times in mms host sync --plan --json for a three-entry config; a wrong guess appears 0 times.
Fix
The drift hash is an HMAC under a random installation-local key kept in ~/.mms/import_state.toml.key (mode 0600), and no unkeyed value is printed.
- Hash version 2 is an HMAC over the version 1 digest string, so a stored version 1 row is re-keyed without the server shape it was computed from.
- Rows written by earlier versions are still compared by the old rule, so every entry keeps its drift state across the upgrade. The next
mms host sync --apply, or anmms import --applythat finds a host definition, re-keys them in place; achangedentry stayschanged. - Each keyed row records the id of the key that stamped it. After a lost or replaced key the rows read
no_baseline, notchanged. mms host statusandmms host sync --planneither create the key nor change its mode.--applycreates it only after its gates have passed and before the first write. A key file that exists but cannot be used is an error and is never overwritten.- The sidecar moves to
schema_version = 2. An unkeyedsha256:hash is accepted for hash version 1 only.
On the fix commit the same measurement gives 0 occurrences in status, plan and apply output and in the rewritten sidecar.
Limits
- Reports already shared stay checkable. Rotate a credential whose entry appeared in a report that left the machine.
- The key sits beside
~/.mms/registry.toml, which holds the sameenvvalues in plain text. Keying covers reports and copies of the sidecar that leave the machine, not a copy of the whole directory. - Until the first
--applythat writes after upgrading, the sidecar still holds the version 1 values (they are not printed).
Notes
Found while reviewing the fix for issue #1381 (keyed surfacing query digest). Related hardening for local stores: issue #1416.