Skip to content

Add the deception command group and Deception SDK class - #482

Merged
maximelb merged 2 commits into
masterfrom
feat/deception-cli
Nov 25, 2026
Merged

maximelb merged 2 commits into
masterfrom
feat/deception-cli

Conversation

@maximelb

@maximelb maximelb commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What

A new limacharlie deception command group and SDK class (limacharlie.sdk.deception.Deception) for the ext-deception extension. Until now the CLI had nothing Deception-specific: every action went through extension request --data '<json>'.

Each user-facing request of the extension gets a subcommand with typed flags, named after the extension's own request fields:

Command Request
config get / set / enable the extension_config record ext-deception
kinds, plan, deploy, rollout-status, restore-rules list_kinds, plan, deploy, rollout_status, restore_rules
list, list-hosts, verify, rotate, remove list, list_hosts, verify, rotate, remove
coverage, test-fire, list-test-runs, list-test-paths same names
list-hits, list-readers list_hits, list_readers
drops create/list/get/update/rotate/delete/draft-document create_drop, list_drops, get_drop, update_drop, rotate_drop, delete_drop, draft_drop_document
uninstall, uninstall-status uninstall, uninstall_status

Choices made:

  • config set takes the bare configuration or a record as config get prints it. The etag in that record (or --etag) makes the write a compare-and-set, so config get > f; edit; config set --input-file f never overwrites someone else's save. A record that does not exist yet is created enabled: a disabled record gives the extension an empty configuration, which is the trap the docs warn about for extension config-set. Creation is conditional (create-only etag), so a record created meanwhile is not replaced. An existing record keeps its metadata unless --enabled/--disabled or a usr_mtd block is given.
  • Validation stays in the extension. The CLI checks only the shape of its own flags (choices for stable enums such as layer, form and format; free text for values the extension has been extending, such as host status, failure cause and classification).
  • Destructive commands need --confirm: remove, drops delete, and uninstall (except --cancel).
  • drops update / drops rotate are compare-and-set on the drop's version; --version defaults to the current one, read just before.
  • --save PATH on drops create/get/rotate writes the document (checked against its sha256) or the QR code SVG. The answer is printed first, so a create's value is never lost if the file cannot be written.
  • list-hits --event-type is repeatable: one value sends event_type, several send event_types. --auto-response-outcome is repeatable and sent comma-joined, as the extension expects.

The three hand-maintained maps are updated: _COMMAND_MODULE_MAP, a new deception discovery profile (no existing profile fits a product group, as with email_security and investigation_engine), and doc/cli/deception.md. The SDK class is documented in doc/sdk/security-products.md.

Permissions

No new permission: requests need ext.request and the record needs ext.conf.get / ext.conf.set, as extension request and extension config-get/config-set already do. config set reads the stored metadata first (ext.conf.get or ext.conf.get.mtd). Stated in the changelog.

Tests

tests/unit/test_cli_deception.py runs the commands through the real SDK with only the extension request and the hive mocked, and checks the exact request the extension receives: flag-to-field mapping, list encodings, the confirm gates, draft plan file loading, drop version read-before-write, --save (including a hash mismatch that writes nothing but still prints the answer), and every config set metadata and etag case. Discovery coverage of the group is pinned both ways, and every leaf command has an --ai-help text.

pytest tests/unit/ tests/microbenchmarks/: 6620 passed (151 skipped, all pre-existing).

Review rounds

Round 1 (both reviewers NOT_APPROVED) was fixed in b8d7bc6: config set checks the record exists on every path, and --enabled writes on the etag its metadata was read with. In a terminal, lists show their rows as a table and the rest as YAML, and other answers print as YAML, so no token is cut. restore-rules fails unless every rule reads back enabled. --save refuses url/hostname drops before creating them. Round 2: /lc-review APPROVED.

Left open:

  • A delete in the instant between config set's metadata read and its write recreates the record, because the hive ignores an etag once the record is gone. No client can close that window; it needs an atomic "must exist and match" condition in the hive. hive set --etag has the same behaviour.
  • Lows, for a follow-up PR:
    • drops rotate --save on a url or hostname drop should refuse before rotating.
    • restore-rules exit tests for an all-successful answer, enabled: false alone and error alone.
    • --save should write to a temporary file and rename it, so a failed write never leaves a truncated file behind a message saying nothing was written.

🤖 Generated with Claude Code

Typed subcommands for every user-facing request of the ext-deception
extension (plan, deploy, rollout-status, decoys and hosts, verify, rotate,
remove, coverage, test-fire, test runs and paths, hits, readers, drops,
restore-rules, uninstall) and config get/set/enable on the extension_config
record with compare-and-set on its etag.

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

Copy link
Copy Markdown
Contributor Author

/lc-review

@maximelb

Copy link
Copy Markdown
Contributor Author

Self-review (adversarial), head 676d1f0

Checked every subcommand's request fields against the extension's published request schema (limacharlie extension schema --name ext-deception): action names, field names, list vs single encodings (event_type / event_types, comma-joined auto_response_outcome), page_token / page_size (max 500), update_drop's "" clears, test_fire's policy / drop_id, plan's draft_policy / draft_templates. No mismatch found.

Checked hive semantics for config set: data without metadata keeps the stored metadata; a metadata block replaces it; a new record is created through a create-only etag, so a record created meanwhile is refused, not replaced. Subcommand options never collide with hoisted global options (--oid, --output, --filter, --debug*, --quiet, --env, --wide).

Low, not fixed (noted for a follow-up if anyone cares):

  • config set with a usr_mtd block and an etag of a record deleted since it was read: the hive ignores the etag when no record exists, so the write recreates it (the data-only path refuses this case instead). Same behaviour as hive set.
  • config set (data only) when the record is deleted between the metadata read and the write: the hive recreates it with its default (disabled). Needs a concurrent delete within milliseconds.

Verdict: APPROVED (0 High, 0 Medium, 2 Low)

lcbill
lcbill previously approved these changes Nov 25, 2026

@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

Verdict: NOT_APPROVED (0 High, 1 Medium, 3 Low)

This is a first-round review. I read every changed file in full: the SDK class, the CLI group, the discovery, module-map and lazy-loading changes, the docs, the changelog and the tests.

General Feedback

  • Low Priority: Many commands have no test that checks how their flags map to request fields: list-hosts, list-readers, list-test-runs, list-test-paths, coverage, test-fire, drops list, drops draft-document and kinds. Most of these are pass-through mappings, so a mistyped field name (for example managed_by, last_hit_since or include_deleted) would reach users without any test failing. One test per command that asserts ext.calls (like test_list_sends_states_and_flags_only_when_set) would cover this.
  • Note (not counted): the config set tests mock Hive entirely. Nothing tests the premise behind _CREATE_ONLY_ETAG: that the hive ignores an etag when no record exists and refuses it when a record exists. If that premise is wrong, every first config set on an org fails. Please confirm it against the hive's behaviour.
  • test-time-budget: no check run was found on this commit. The check is not required on master (branch protection and rulesets list no required checks).

Blast radius

The new code lives in its own modules (limacharlie/commands/deception.py, limacharlie/sdk/deception.py). These modules are loaded lazily through _COMMAND_MODULE_MAP. The shared code changes only by adding entries: one module-map entry and one discovery profile, deception. Code that lists PROFILES or the top-level commands (help, discovery output, completion) will now show the new group. Hive, HiveRecord and Extensions are used but not modified, so existing commands behave as before. On a live org, config set writes the shared extension_config/ext-deception record. extension config-set, hive and sync edit the same record.


This review was generated automatically by Claude Code.

Comment thread limacharlie/sdk/deception.py Resolved
Comment thread limacharlie/commands/deception.py Resolved
Comment thread limacharlie/commands/deception.py Resolved
config set checks the record exists on every path (a stale etag of a deleted
record is refused, a new record is written create-only), and --enabled on an
existing record writes on the etag its metadata was read with. Tables show a
list's rows and the rest of the answer as YAML so nothing is cut.
restore-rules fails unless every rule reads back enabled. --save refuses a
url or hostname drop before creating it and reports write errors cleanly. An
empty --draft-policy file is refused. More mapping tests.

Co-Authored-By: Claude Opus 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

Verdict: APPROVED (0 High, 0 Medium, 2 Low)

This is a re-review of the changes since 676d1f0. Four files changed: limacharlie/sdk/deception.py, limacharlie/commands/deception.py, doc/cli/deception.md and tests/unit/test_cli_deception.py. I read each of them in full again. The other PR files have not changed since the last round.

Earlier findings

  • All three earlier threads are fixed. I verified each one and replied on its thread.
  • The earlier General Feedback Low (no request-mapping tests for list-hosts, list-readers, list-test-runs, list-test-paths, coverage, test-fire, drops list, drops draft-document, kinds) is fixed by TestMoreRequests.test_mapping.

General Feedback

  • drops rotate --save on a url or hostname drop repeats the problem fixed for drops create. See the inline thread.
  • test-time-budget: no check run was found on this commit. The check is not required on master (branch protection and rulesets list no required checks).

Blast radius

This round's changes stay inside the deception modules. _out changes only how deception commands print in table mode: lists print as a table plus YAML, and every other answer prints as YAML. JSON, YAML, CSV, --filter and --fields still go through command_output, so scripts that parse non-table output see no change. set_config now always reads the metadata first, so every config set needs ext.conf.get or ext.conf.get.mtd. restore-rules now exits 1 more often: when any row lacks enabled: true, carries an error, or the answer has no rows. Scripts that check its exit code will see this.


This review was generated automatically by Claude Code.

Comment thread limacharlie/commands/deception.py Resolved
Comment thread limacharlie/commands/deception.py Resolved
@maximelb

Copy link
Copy Markdown
Contributor Author

Second reviewer, round 2: one Medium (a delete in the instant between config set's metadata read and its write recreates the record, because the hive ignores an etag for a missing record) and one Low (atomic --save write). The Medium is the same class as round 1's and cannot be closed client-side: it needs an atomic must-exist condition in the hive, and hive set --etag has the same window. Recorded in the PR description; the Lows go to the follow-up PR. /lc-review approved b8d7bc6.

@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

Verdict: APPROVED (0 High, 0 Medium, 3 Low)

This is a re-review at b8d7bc6, the same commit my last review covered. The compare returned identical, not ahead, so I treated every file as changed and read all of them in full again: the SDK class, the CLI group, cli.py, discovery.py, the docs, the changelog and the three test files. I found no new High or Medium issue.

Earlier findings

  • drops rotate --save on a url or hostname drop (thread at limacharlie/commands/deception.py:985, resolved): still open in the code. The drop is rotated before _save_paste fails, so a retry on exit 1 rotates it again. The author has moved it to a follow-up PR. Carried over as Low.
  • restore-rules exit tests (thread at limacharlie/commands/deception.py:651, resolved): still open. There is still no test that a fully successful answer exits 0, and none for enabled: false alone or error alone. Moved to the follow-up PR. Carried over as Low.
  • The three round-1 threads stay fixed.

General Feedback

  • Low Priority: _save_paste (limacharlie/commands/deception.py:139-158) opens the target with open(path, "wb") and writes to it directly. If the write fails partway (disk full, I/O error), a truncated file is left at path, but the message says "nothing was written". The PR description already plans the fix: write to a temporary file in the same directory, then os.replace it onto path, and remove the temporary file on error.
  • Answer to the reviewer instructions (not counted): I agree that the window between config set's metadata read and its write cannot be closed from the client. When the record exists, the data-only path could send the etag it just read, but by the PR's own premise (sdk/deception.py:34-37) the hive ignores an etag once the record is gone. So a delete inside that window still recreates the record. Closing it needs a "must exist" condition on the hive side. hive set --etag has the same limit, and the PR description records it. I do not count it against this PR.
  • Note (not counted): the instructions said the open Lows go to a follow-up PR. That does not change how I review: I listed them above and counted them in the Verdict line.
  • Note (not counted): as in the last round, the create-only etag premise is only tested against a mocked Hive. Its correctness depends on how the hive behaves.
  • test-time-budget: no check run was found on this commit. The check is not required on master (branch protection and rulesets list no required checks).

Blast radius

The new code is limited to limacharlie/commands/deception.py and limacharlie/sdk/deception.py. Both load lazily through _COMMAND_MODULE_MAP. Shared code only gains entries: one module-map entry and the deception discovery profile. So top-level help, completion and discovery listings now show the group. Hive, HiveRecord, Extensions and the output helpers are used but not changed. _out changes table-mode printing for deception commands only. At runtime, config set and config enable write the shared extension_config/ext-deception record. extension config-set, hive and sync edit the same record.


This review was generated automatically by Claude Code.

@maximelb
maximelb merged commit e36f54e into master Nov 25, 2026
7 checks passed
@maximelb
maximelb deleted the feat/deception-cli branch November 25, 2026 21:03
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