Repository navigation
fix(settings): audit POST /api/settings/ops/reset (#1966) - #1977
Conversation
ent#297 / PR #1893 added validation **and** an audit entry to `PUT /api/settings/ops/config`, and its prose claimed the audit half covered both routes: "Neither this endpoint nor /ops/reset logged anything, while the generic PUT /{key} directly above them does…" `/ops/reset` never got one. So the exact asymmetry ent#297 objected to survived one route over: the generic `PUT /{key}` audits, `/ops/config` audits, and `/ops/reset` — admin-only, deleting a row per key in `OPS_SETTINGS_DEFAULTS` — left no trace at all. The retention half of that prose does hold: reset `continue`s over `RETENTION_OPS_KEYS` (#1638), so it cannot shrink a retention window. What it could silently revert unlogged is everything else, including `ssh_access_enabled` — the setting that decides whether ephemeral SSH credentials can be minted at all. Two choices worth stating, since neither is a straight copy of the `/ops/config` call it mirrors: * **Keys and counts only, no values.** Every one of these rows is being DELETED, so the durable fact is which keys reverted to their code default and which were protected — not what they held on the way out. * **Logged unconditionally**, not gated on having deleted something the way `/ops/config` gates on `updated`. There, an empty set means nothing was asked for; here, an admin resetting already-default settings is a real administrative act whose absence from the log is indistinguishable from it never having been attempted — this issue's own reporting gap, in miniature. The action name is deliberately distinct (`ops_settings_reset` vs `ops_settings_change`): setting values and deleting rows are different acts, and sharing a name would make them indistinguishable in the very log built to tell them apart. `architecture.md` gains the clause that makes its existing sentence discoverable rather than merely true. tests/unit/test_1966_ops_reset_audit.py — 11 checks, 9 of which fail against the pre-fix tree. Structural assertions are scoped to the reset handler's own source slice, since `/ops/config`'s audit call sits ~30 lines above it and a whole-file grep would pass on that instead. Related to #1966 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
/review — self-review (PR #1977, #1966)Branch: [I1] The audit call sits inside the try that maps to a 500, unguarded (Confidence: 8/10)await platform_audit_service.log(...) # inside `try:` … `except Exception: raise HTTPException(500)`If I chose to depend on that rather than add a local guard, because the sibling [I2]
|
…y.json — rebuild: dev entries + this PR's entry)
vybe
left a comment
There was a problem hiding this comment.
Validated via /validate-pr — minimal fix mirroring the /ops/config audit pattern; 9/11 regression checks fail pre-fix; the retention-skip contract (#1638/#1644) is untouched and pinned from both ends (retention keys reported under skipped AND asserted never-deleted; audit-swallows-own-failures coupling test-pinned). I added the missing 'Fixes #1966' keyword and resolved the registry.json conflict. Full CI green post-rebase.
Problem
ent#297 / PR #1893 added validation and an audit entry to
PUT /api/settings/ops/config, and its prose claimed the audit half covered both routes:/ops/resetnever got one. So the exact asymmetry ent#297 objected to survived one route over:PUT /api/settings/{key}(generic)PUT /api/settings/ops/configPOST /api/settings/ops/resetreset_ops_settingsis admin-only and deletes a row for every key inOPS_SETTINGS_DEFAULTS.The retention claim in that prose does hold — reset correctly
continues overRETENTION_OPS_KEYS(#1638), so it cannot shrink a retention window. What it could silently revert with no trace is everything else, includingssh_access_enabled— the setting that decides whether ephemeral SSH credentials can be minted at all.Fix
Mirrors the
/ops/configcall, with two deliberate departures from it — neither is a straight copy, and both are the kind of thing that looks like an oversight later if unstated:Keys and counts only, no values.
/ops/configrecords the values it set, because "who shortened retention, to what" is the question there. Here every row is being deleted, so there is no value worth keeping: the durable fact is which keys reverted to their code default and which were protected.Logged unconditionally, not gated on
deletedthe way/ops/configgates onupdated. There, an empty set means nothing was asked for. Here, an admin pressing reset on already-default settings is a real administrative act — and its absence from the log would be indistinguishable from it never having been attempted, which is this issue's own reporting gap in miniature.Distinct action name (
ops_settings_reset, notops_settings_change): setting values and deleting rows are different acts, and sharing a name would make them indistinguishable in the very log built to tell them apart.One coupling made explicit
The
log()call sits inside thetrywhoseexceptmaps to a 500, with no guard of its own. A raising sink would therefore turn a completed reset into a 500 the operator retries against already-deleted rows.That is safe only because
platform_audit_service.logis documented best-effort and swallows its own errors. Rather than trust the docstring, two tests pin the coupling from both ends: one shows the handler does not guard the call, and one breaks the service's realdb.create_audit_entryseam and assertslog()returnsNoneinstead of raising. If someone later makes the audit service strict, the second test fails and names this handler as a caller that depends on it.Verification
tests/unit/test_1966_ops_reset_audit.py— 11 checks, 9 of which fail against the pre-fix tree:Structural assertions are scoped to the reset handler's own source slice, not the file:
/ops/config'sops_settings_changesits ~30 lines above, and a whole-file grep for "is there an audit call" would have passed against the unfixed tree. (The slice helper also handles the handler being the last function in the file — searching unconditionally for a followingdefraises, which is a harness failure dressed up as a code failure. I hit exactly that on the first run.)Behavioural coverage drives the real handler with the same
_Admindataclasstest_297_ops_settings_validation.pyuses — a bareMagicMockhas a truthy.agent_name, so it reads as an agent key and exercises the wrong branch (the #1816 trap, re-hit in ent#293).Also green:
test_297_ops_settings_validation,test_1638_retention_upgrade_safety,test_1644_retention_guard— 83 passed across the new file and all three siblings, including a direct assertion that retention keys were not merely reported as skipped but genuinely never deleted (a #1638 regression guard).Acceptance criteria
POST /api/settings/ops/resetwrites aCONFIGURATIONaudit entry naming which keys were reset and which were skippedskipped, neverresetarchitecture.md's "neither this route nor/ops/resetlogged anything before" is true after the changeOn the third: the sentence became true from the code change alone. I added one clause naming
ops_settings_resetand the two departures above, so the log's action names are discoverable from the doc rather than only correct in it.Related to #1966 · follow-up to trinity-enterprise#297 · surfaced in review of #1893
🤖 Generated with Claude Code
Fixes #1966