Skip to content

Host Posture: host-posture commands, host_posture_rule hive, default pack install - #463

Merged
maximelb merged 5 commits into
masterfrom
hp-ga/cli
Nov 16, 2026
Merged

maximelb merged 5 commits into
masterfrom
hp-ga/cli

Conversation

@maximelb

@maximelb maximelb commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the limacharlie host-posture command group for the Host Posture extension, and the host_posture_rule hive it reads.

  • rules list|get|set|delete|enable|disable|tag: the host_posture_rule hive (record name = rule id). The server validates every record; the CLI does not.
  • install-defaults: fetches default_pack from the extension and writes the records with the caller's own permissions. The extension decides every rule's fate (pack_status: new, current, update_available, edited, org_newer); the CLI computes no digest.
    • new: created create-only, enabled (--disabled for disabled), tagged lc:pack-sha256:<digest> with the digest exactly as default_pack returned it.
    • update_available: replaced only with --update; etag-conditional; enabled state, expiry, other tags, ui_actions and the org's own comment are kept.
    • edited (including a record with no digest tag) and org_newer: replaced only with --force (which implies --update).
    • On a write conflict nothing is retried: the rule is skipped and pack_status is read again, so the entry reports state_now.
    • --id, --disabled, --dry-run. Exit code 1 when a write failed.
  • scan --sid, sweep [--tag], status, and results summary|hosts|host|rules|rule-hosts|standards (server-side filters and paging).
  • host_posture_rule added to hive list-types, sync pull/push (--hive-host-posture-rule, --all) and Configs.ALL_HIVES.
  • New SDK class limacharlie.sdk.host_posture.HostPosture.
  • Permissions: saving, enabling or disabling a rule needs host_posture.set and sensor.task; deleting needs host_posture.set. Documented in the command help.
  • cli.py command map, discovery.py PROFILES, doc/cli/host-posture.md, doc/cli/* and CHANGELOG updated.

Notes

  • The extension actions used (default_pack, pack_status, query_*, scan, sweep, status) are exercised through mocks here, not against a live extension.

Test plan

  • pytest tests/unit/ tests/microbenchmarks/: 6294 passed (151 skipped, as before this change)
  • New: tests/unit/test_sdk_host_posture.py (state matrix, conflicts, partial failure), tests/unit/test_cli_host_posture.py, sync round trip, command map and discovery lints

🤖 Generated with Claude Code

…ault pack install

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@maximelb

Copy link
Copy Markdown
Contributor Author

/lc-review

lcbill
lcbill previously approved these changes Nov 14, 2026
@maximelb

Copy link
Copy Markdown
Contributor Author

Self-review (adversarial pass over the diff)

  • Never overwrites an edited rule. --update needs three things: a stored digest tag, a stored data digest that still matches it, and a strictly newer pack version. A record with no digest tag (made by hand, or by another surface) counts as edited and needs --force. Tests cover: unedited update, edited, foreign, not-older, force.
  • Etag safety. Create writes with a create-only etag; update writes with the etag that was read. An etag conflict is reported as skipped with a reason, not as a failure, and nothing is retried blindly. A lost response replayed with a stale etag would show as skipped, never as an overwrite.
  • Metadata. set() replaces metadata wholesale and a block without enabled stores the record disabled, so update sends the stored enabled, expiry and tags back and only swaps the digest tag. The org's own comment is kept.
  • Failure isolation. One rule's failure goes to failed and the loop continues; any non-not-found read error is a failure for that rule, never "treated as missing". Exit code 1 when failed is non-empty.
  • Known limit. If the server ever normalizes stored data (key order is irrelevant; added or dropped keys would matter), the digest no longer matches and the rule is treated as edited, so --update fails safe to "skipped". Other surfaces that install the pack should write the same lc:pack-sha256: tag for --update to recognize their records.
  • Validation stays on the server. No client-side validation of rules, as for app-control. rules enable and rules disable write metadata only, so the server enforces sensor.task there; the help says so.
  • Wiring. _COMMAND_MODULE_MAP, PROFILES, hive list-types, sync flag and Configs.ALL_HIVES all updated with their lint tests; doc/cli/host-posture.md and CHANGELOG added.
  • Tests. 6290 passed. 151 skipped, the same count as before this change.

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

Found 1 medium issue in install-defaults --update/--force: the replacement record drops the stored ui_actions metadata.

General Feedback

  • test-time-budget: no check run was found for this commit. The check is not required on master (branch protection and rulesets list no required checks), and this PR does not touch whatever would create it.
  • test_cli_host_posture.py::test_install_defaults_arguments_and_failure_exit and test_sweep_tags do not assert exit_code == 0 on the success runs. If the command crashes after calling the mock, the assert_called_with checks still pass. Low priority.
  • _CREATE_ONLY_ETAG depends on server behaviour (the hive ignores an etag when no record exists). The PR only tests this with mocks. sdk/investigation.py already relies on the same convention, so this is not flagged. But if the server ever rejected that etag, every fresh install would report all rules as skipped ("created while installing") with exit code 0.

Blast radius

  • Adding host_posture_rule to Configs.ALL_HIVES changes sync pull --all and sync push --all for every org. If you run sync push --all --force with a config file pulled before this change (no host_posture_rule key), it can now remove every Host Posture rule in the org, including installed default-pack rules. Earlier hive additions to ALL_HIVES worked the same way, but this is worth a line in the CHANGELOG.
  • hive list-types, the hive help text, the discovery PROFILES and the lazy-load command map all gain new entries. Tools that snapshot these outputs will see the change.
  • New public SDK surface: limacharlie.sdk.host_posture.HostPosture, record_digest, and the tag and comment conventions (lc:default-pack, lc:pack-sha256:). Other clients have to keep the digest scheme byte-compatible (sorted keys, compact separators, ensure_ascii=False, first 32 hex characters). Otherwise --update will treat pack rules they write as edited.

This review was generated automatically by Claude Code.

Comment thread limacharlie/sdk/host_posture.py Resolved
… note

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@maximelb

Copy link
Copy Markdown
Contributor Author

/lc-review

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

Re-reviewed at d97aa0f. The earlier ui_actions finding is fixed: _install_one now carries existing.ui_actions into the replacement record, and test_update_replaces_unedited_older_rule_keeping_org_state asserts it. The success runs in test_sweep_tags and test_install_defaults_arguments_and_failure_exit now assert exit_code == 0. I found no new high or medium issues.

General Feedback

  • test-time-budget: no check run exists for this commit. Neither branch protection nor rulesets on master require the check, and this PR does not touch anything that creates it.
  • Low: the host-posture.install-defaults explain text (commands/host_posture.py lines 184-185) still lists only "Enabled state, expiry, other tags and your own comment" as kept. The SDK docstring now also lists ui_actions. Add it to the help text so the two match.
  • Low: the tests cover _CREATE_ONLY_ETAG (create-only writes) only with mocks. If the server ever rejected an unknown etag on a missing record, a fresh install would report every rule as skipped and exit 0. This is the same convention as existing SDK code, so I am not flagging it.

Blast radius

  • Configs.ALL_HIVES now includes host_posture_rule. So sync pull --all and sync push --all now cover this hive for every org. A forced sync push --all of a config file pulled before this change has no host_posture_rule key and could remove the org's Host Posture rules. The CHANGELOG now says so.
  • hive list-types, the hive help text, the discovery PROFILES and the lazy-load command map all gain new entries. Tools that snapshot these outputs will see the change.
  • New public SDK surface: limacharlie.sdk.host_posture.HostPosture and record_digest, plus the lc:default-pack and lc:pack-sha256: tag conventions. Any other client that installs the pack must compute the same digest (sorted keys, compact separators, ensure_ascii=False, first 32 hex characters). Otherwise --update treats its records as edited.

This review was generated automatically by Claude Code.

lcbill
lcbill previously approved these changes Nov 14, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@maximelb

Copy link
Copy Markdown
Contributor Author

/lc-review

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

Re-reviewed at 330ad72. This commit only changes text: the install-defaults help and doc/cli/host-posture.md now list ui_actions as kept metadata. That fixes the Low note from the last review. The help, the docs and the SDK docstring now match the code (_install_one passes ui_actions=existing.ui_actions). I found no high or medium issues.

General Feedback

  • test-time-budget: no check run exists for this commit. Neither branch protection nor rulesets on master require the check, and this PR does not touch anything that creates it.
  • Low, carried over and not blocking: the tests cover the create-only etag (_CREATE_ONLY_ETAG) only with mocks. If the server ever rejected an unknown etag on a missing record, a fresh install would report every rule as skipped and still exit 0. Existing SDK code relies on the same convention.

Blast radius

  • Configs.ALL_HIVES now includes host_posture_rule, so sync pull --all and sync push --all now cover this hive. A forced sync push --all of a config file pulled before this change could remove the org's Host Posture rules. The CHANGELOG notes this.
  • hive list-types, the hive help text, the discovery PROFILES and the lazy-load command map all gain entries. Tools that snapshot these outputs will see the change.
  • New public SDK surface: limacharlie.sdk.host_posture.HostPosture, record_digest, and the lc:default-pack and lc:pack-sha256: tag conventions. Any other client that installs the pack must compute the same digest, or --update will treat its records as edited.

This review was generated automatically by Claude Code.

lcbill
lcbill previously approved these changes Nov 14, 2026
…sion's digest, report state_now on conflicts

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@maximelb

Copy link
Copy Markdown
Contributor Author

Update for the revised pack contract (head after this push).

  • The CLI no longer computes a digest. install-defaults asks the extension for pack_status and acts on its new, current, update_available, edited and org_newer decisions. A new rule is written create-only with the tag lc:pack-sha256:<digest>, the digest exactly as default_pack returned it. Local canonical-JSON hashing and the version/digest heuristics are removed.
  • --update replaces update_available only. --force (which implies --update) is required for edited and org_newer. Replacements stay etag-conditional.
  • On a write conflict (a new rule that appeared, or an update that lost the etag race) nothing is retried: the rule is skipped, pack_status is read again, and the entry carries state_now.
  • A pack entry without a digest, a rule missing from pack_status, or an unknown state fails that rule only.
  • Tests rewritten for the state matrix (32 in test_sdk_host_posture.py); suite: 6294 passed, 151 skipped (unchanged count).

@maximelb

Copy link
Copy Markdown
Contributor Author

/lc-review

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

Re-reviewed at 2296759 (the revised pack contract, where pack_status decides each rule's state). Found 1 medium issue: --update can overwrite a rule that was edited after pack_status was read.

General Feedback

  • test-time-budget: no check run exists for this commit. Earlier reviews of this PR found that master does not require the check, and this PR does not touch anything that creates it.
  • Low, carried over: the tests cover the create-only etag (_CREATE_ONLY_ETAG) only with mocks. Existing SDK code relies on the same convention.
  • The earlier ui_actions finding is still fixed in this version (host_posture.py line 364, asserted in test_update_replaces_keeping_org_state).

Blast radius

  • Configs.ALL_HIVES now includes host_posture_rule, so sync pull --all and sync push --all now cover this hive. A forced sync push --all of a config file pulled before this change could remove the org's Host Posture rules. The CHANGELOG notes this.
  • hive list-types, the hive help text, the discovery PROFILES and the lazy-load command map all gain entries. Tools that snapshot these outputs will see the change.
  • New public SDK surface: limacharlie.sdk.host_posture.HostPosture (including pack_status), and the lc:default-pack / lc:pack-sha256: tag conventions. record_digest from earlier commits is gone, so nothing outside this PR could depend on it yet. install-defaults now needs the extension to support the pack_status action. With an older extension build, the whole command fails before it writes anything.

This review was generated automatically by Claude Code.

Comment thread limacharlie/sdk/host_posture.py Resolved
lcbill
lcbill previously approved these changes Nov 15, 2026
…eplacing it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@maximelb

Copy link
Copy Markdown
Contributor Author

/lc-review

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

Re-reviewed at 3830d0c. The race from the last review is fixed. After hive.get, _install_one reads pack_status again and writes only if the state has not changed. The write still uses the etag from that get. An edit before the get shows up in the new state, and an edit after it fails the etag check. If the second read fails, state_now is None and the rule is skipped, so the code fails safe. Three new tests cover this: an edit between the reads, a recheck that fails, and --force also rechecking. Each one asserts that hive.set is not called. I found no high or medium issues.

General Feedback

  • Low: each update_available/edited/org_newer rule that reaches the write path now calls pack_status once more. --dry-run does this too. Each call returns the status of every rule. A full --update of N rules therefore makes N+1 extension requests and moves O(N²) status data. That is fine for a pack of tens of rules, but it will get slower as the pack grows. A pack_status filter by id would keep each recheck small, if the extension can add one.
  • Low: line 185 of commands/host_posture.py is now much longer than the lines around it in the explain text, so the help output wraps unevenly.
  • test-time-budget: no check run exists for this commit. Neither branch protection nor rulesets on master require the check, and this PR does not touch anything that creates it.
  • Low, carried over: the tests cover _CREATE_ONLY_ETAG only with mocks.

Blast radius

  • Configs.ALL_HIVES now includes host_posture_rule, so sync pull --all and sync push --all cover this hive. A forced sync push --all of a config file pulled before this change could remove the org's Host Posture rules. The CHANGELOG notes this.
  • hive list-types, the hive help text, the discovery PROFILES and the lazy-load command map all gain entries.
  • New public SDK surface: limacharlie.sdk.host_posture.HostPosture and the lc:default-pack / lc:pack-sha256: tag conventions. install-defaults needs an extension build that supports pack_status and returns digest in default_pack. With an older build, the command fails before it writes anything, or it fails every rule.

This review was generated automatically by Claude Code.

@limacharlie-refractionpoint

limacharlie-refractionpoint Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

LimaCharlie Cloud Security — code scan

No new code findings were introduced by this pull request.

This check reports and never fails: no gating.fail_on is set on the code_scanning policy.

Scanned refractionPOINT/python-limacharlie 01120bb…3830d0c — only findings new in the head commit are listed; anything already on the base branch is the repository's own finding set, on the Cloud Security Code page.

This comment is updated in place on every push to this pull request.

@maximelb
maximelb marked this pull request as draft November 15, 2026 08:33
@maximelb

Copy link
Copy Markdown
Contributor Author

Held as draft on purpose: sync --all now includes the host_posture_rule hive, so this release has to wait until that hive is live in every region. Approved and green.

@maximelb
maximelb marked this pull request as ready for review November 16, 2026 15:51
@maximelb

Copy link
Copy Markdown
Contributor Author

/lc-review

@limacharlie-event-notifications limacharlie-event-notifications Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Code Review Summary

Re-reviewed at 3830d0c. This is the same commit as the last review, and there are no new commits. I read all the changed files again: the SDK, the commands, sync, configs, hive, discovery, the cli map, the docs and the tests. I found no high or medium issues.

The race found earlier is still fixed. _install_one reads the record with hive.get first. It then reads pack_status again (_state_now) and writes only if the state has not changed. The write uses the etag from that get. If the second read fails, state_now is None and the rule is skipped, so the code fails safe.

General Feedback

  • Low (still open): every rule that reaches the write path (update_available, edited or org_newer) triggers one more full pack_status call, and --dry-run does this too. For N rules, that is N+1 extension requests and O(N²) status data. A pack_status filter by id would keep each recheck small.
  • Low (still open): commands/host_posture.py line 185 is much longer than the lines around it in the explain text, so the help output wraps unevenly.
  • Low (still open): the create-only etag (_CREATE_ONLY_ETAG) is tested only with mocks. Existing SDK code relies on the same convention.
  • test-time-budget: no check run was found for this commit. Neither branch protection nor rulesets on master require the check, and this PR does not change anything that creates it.

Blast radius

  • Configs.ALL_HIVES now includes host_posture_rule, so sync pull --all and sync push --all now cover this hive. A forced sync push --all of a config file pulled before this change has no host_posture_rule key, so it could remove the org's Host Posture rules. The CHANGELOG notes this, and the author is holding the release until the hive is live.
  • hive list-types, the hive help text, the discovery PROFILES and the lazy-load command map all gain entries.
  • New public SDK surface: limacharlie.sdk.host_posture.HostPosture and the lc:default-pack and lc:pack-sha256: tag conventions. install-defaults needs an extension that supports pack_status and returns digest from default_pack. With an older extension, the command either fails before it writes anything or fails every rule.

This review was generated automatically by Claude Code.

@maximelb
maximelb merged commit 81ebc78 into master Nov 16, 2026
8 checks passed
@maximelb
maximelb deleted the hp-ga/cli branch November 16, 2026 15:53
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.

2 participants