Skip to content

feat: Windows response, signed actions, process control, quarantine, WFP plan - #67

Merged
jusso-dev merged 8 commits into
mainfrom
feat/windows-response
Nov 9, 2026
Merged

jusso-dev merged 8 commits into
mainfrom
feat/windows-response

Conversation

@jusso-dev

@jusso-dev jusso-dev commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Closes #57

Stacked on #66 (base feat/detection-engine). Merge the stack below #66 first.

Windows can now respond: signed response actions, a durable action journal, Windows process control (kill, suspend, resume) with an identity guard, cross-platform quarantine and restore, and live WFP network isolation that undoes itself. The server signs every action with one Ed25519 action key that also signs YARA rule packs (folding in #66's rule-pack key).

Key decisions for Justin

  • One action key, derived when unset. TAWNY_ACTION_SIGNING_KEY (64 hex) signs both response actions and YARA rule packs. TAWNY_RULE_SIGNING_KEY keeps working as a deprecated alias. When neither is set the key is derived from the agent JWT seed with HKDF and the label tawny-action-key-v1, matching how feat: detection engine, Sigma compiler, sequence and threshold rules, YARA via libyara #66 already derived the rule key, so existing deployments keep booting. It is never the JWT key. state.rulePackKey now forwards to state.actionKey.
  • TOFU window. The public key is returned at enrolment and in every heartbeat. Agents enrolled before this change pin it on their first heartbeat that carries it, then a different key is refused.
  • Quarantine ACL on Windows: the copy is readable by SYSTEM and local Administrators, not SYSTEM only, so an agent not running as SYSTEM can still verify and restore. Say if you want SYSTEM only.
  • WFP isolation is live on Windows. DHCP and DNS-by-hostname permits are simplified to address permits for now. The break-glass secret is read from TAWNY_ISOLATION_SECRET; the server-side UI that shows that secret is not in this change.

Acceptance criteria

  • Every action has a valid server signature; unsigned or tampered ones are refused and reported. Met. Server signs tawny-action-v1\n<action_id>\n<agent_id>\n<action_type>\n<expires_at>\n<sha256 of payload>; the agent verifies before anything runs. Tests both sides: good, tampered, expired, wrong key, plus an openssl contract test.
  • Kill, suspend and resume on Windows with the identity guard, refusing critical processes. Met, and run live in the Windows CI step. The critical-process list check is tested on every OS.
  • Quarantine and restore round-trip a file with the same hash and ACL. Met. Hash round-trip tested on the Mac, in the Linux container and live in Windows CI. Windows ACL is applied via SDDL (SYSTEM + Administrators).
  • WFP isolation blocks outbound except the server, survives a reboot, removes itself on deadline. Met on Windows. isolate_host opens the engine (fwpuclnt), adds persistent filters in the fixed Tawny sublayer (permit loopback, resolved server IPs, DNS resolvers, optional admin allowlist; block all else on the four ALE layers), then probes the server and a blocked address. release deletes the sublayer, filters and provider. The deadline (default 24 h) is stored and enforced at start and on each heartbeat; filters are reconciled with the journal at start. Break-glass tawny-agent release --code <code>. The pure plan, deadline and release-code logic are tested on every OS; the live engine is exercised by a safe CI self-test (see below). The live block/permit behaviour against real traffic and reboot persistence are not asserted by a test.
  • Restarting mid-action neither repeats a finished action nor drops an unfinished one. Met. action_journal.zig, tested.
  • CI green on the PR. See the Windows CI steps below; checks run after push.

Live WFP in CI

tawny-agent --wfp-selftest adds one block filter for a TEST-NET address (192.0.2.1), never a block-all, so it cannot cut the runner off. It confirms the filter is present, that a routable address (1.1.1.1:443) stays reachable (no over-block), then releases and confirms the sublayer is empty. Full isolation with a block-all is not run in CI, because it could cut the runner off from GitHub; the self-test does add, probe and delete of real WFP filters under the sublayer and fails if the engine over-blocks or leaves filters behind. The TEST-NET block is reported, not asserted, because it is indistinguishable from an unroutable baseline.

What ran where

Mac (macOS arm64, Zig 0.17.0):

agent: zig build test --summary all                 -> 4/4 steps; 155/161 tests passed (6 skipped)
agent: zig build -Doptimize=ReleaseSafe -Dtarget={x86_64-windows,x86_64-linux,aarch64-linux,x86_64-macos} -> all build
agent: zig build -Doptimize=ReleaseSafe -Dtarget=x86_64-windows -Dyara=true -> builds
agent: zig build test -Dtarget=x86_64-windows        -> compiles (only "unable to execute binaries" from the host)
agent: --quarantine/--restore and --wfp-selftest/release --code route correctly
server: zig test src/main.zig -lc                    -> All 150 tests passed (0 SafeAllocator lines; DB tests ran)
server: zig test src/main.zig -lc --test-filter fuzz -> All 2 tests passed
server: /tmp/run-contract.sh $PWD                    -> Ran 42 tests ... OK (skipped=9)
server: /tmp/run-e2e.sh $PWD                         -> heartbeat_ok, event_ok, schema_v2_ok, isolate_result_ok, e2e_ok
ui: node --check app.js && node ci/ui-fallback.mjs   -> ui fallback ok assets=2 routes=12
yaml: /tmp/yamlcheck.sh .github/workflows/*.yml      -> yaml ok

Linux container (ubuntu:26.04, aarch64):

agent: zig build test --summary all                  -> 4/4 steps; 136/155 tests passed (19 skipped)

Windows CI only: a response-actions step (kill by PID and start time, already-gone kill, suspend and resume, refuse lsass, quarantine and restore comparing hashes) and a live WFP step (--wfp-selftest: add a TEST-NET block, confirm present and no over-block, release, confirm empty). Both run through the agent's debug subcommands.

New Zig 0.17 gotchas

  • "ab" ** 32 and [_]u8{0} ** N style repeats don't parse next to }; use std.mem.zeroes([N]u8).
  • suspend and resume are reserved words; an enum can't use them as field names.
  • std.crypto.timing_safe.eql (not std.crypto.utils.timingSafeEql).
  • Io.File has no chmod; use setPermissions(io, @enumFromInt(0o600)).
  • std.posix.SIG.* is an enum on Linux, not a u8.
  • std.json.parseFromSlice keeps string slices into the input unless you pass .allocate = .alloc_always; free the input only after that.
  • std.Io.net.IpAddress is a union(enum) of ip4/ip6 with .bytes, not a POSIX sockaddr.

🤖 Generated with Claude Code

jusso-dev and others added 3 commits November 10, 2026 02:44
Fold the #56 rule-pack key into a single Ed25519 server action key
(TAWNY_ACTION_SIGNING_KEY, 64 hex) that signs both response actions and
YARA rule packs. TAWNY_RULE_SIGNING_KEY keeps working as a deprecated
alias. When neither is set the key is derived from the agent JWT seed
with HKDF and a domain-separated label, matching how #66 derived the
rule key, so existing deployments keep booting. The public key is
returned in the enrol reply and in every heartbeat for trust-on-first-use
pinning of agents enrolled before this change.

The server signs the canonical string
tawny-action-v1\n<action_id>\n<agent_id>\n<action_type>\n<expires_at>\n<sha256 of payload>
and adds "signature" to each action in the heartbeat. The agent verifies
it in response_actions before anything runs, refusing unsigned, expired,
tampered and wrong-key actions and reporting failed with a reason.

A local action journal at <state_dir>/actions/<id>.json dedupes by
action_id, replays unfinished actions on restart, and keeps results
until the server acks them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent:
- platform/windows/process_control.zig: kill (already-gone is success),
  suspend and resume via NtSuspendProcess/NtResumeProcess, an identity
  guard (image path plus start time) so Windows no longer fails closed,
  and a critical-process refusal list tested on every OS.
- quarantine.zig: encode the file with a fixed XOR key so it cannot run,
  hash and verify the copy, delete the original, write a sidecar, and
  restore. Windows keeps the ACL as SDDL; POSIX restores owner-only
  permissions. Round-trips on Linux and macOS.
- platform/windows/wfp.zig: a pure filter-building plan with a fixed
  sublayer GUID, an auto-release deadline check, and the break-glass
  release code (HMAC of agent id and nonce), all tested on every OS. The
  live FwpmEngine calls are stubs behind the Windows target for now.
- response_actions dispatches kill, suspend, resume, quarantine, restore,
  and reports isolate_host as not supported on this build.

Server:
- migration 0006 adds suspend_process, resume_process, quarantine_file,
  restore_file and release action types.
- the SPA agent page lists recent actions and lets an admin create one.
- a contract test verifies the action signature with openssl; the Linux
  e2e now expects the new isolate_host message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add agent debug subcommands (--kill-pid, --suspend-pid, --resume-pid,
--quarantine, --restore) that drive the response actions from CI without
a server, following the --eventlog-dump pattern. A new Windows CI step
starts ping, kills it by PID and start time and checks it is gone,
suspends and resumes a child, refuses lsass, and quarantines then
restores a temp file comparing hashes.

Document the action signing scheme and the new action types in
docs/api.md, TAWNY_ACTION_SIGNING_KEY and the trust-on-first-use window
in docs/production.md, the §9 status and the merged key in
docs/architecture/target-edr.md, and the signed-action and PID-reuse
rows in docs/threat-model.md.

Closes #57

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

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

jusso-dev and others added 2 commits November 10, 2026 03:03
Apply the restrictive ACL to the quarantine copy and sidecar only after
the read-back verification, so a SYSTEM-only DACL never blocks the
agent's own verify or a later restore. Widen the Windows DACL to SYSTEM
plus local Administrators, so an agent not running as SYSTEM (CI, or a
service misconfiguration) can still read the copy back; normal users
still cannot run it.

Compute the Windows CI ping start time with DateTimeOffset instead of
Get-Date -UFormat %s, avoiding a double UTC offset and locale parsing.

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

PowerShell 7.4 on the hosted runner propagates a native command's non-zero
exit as a terminating error by default, which would throw on the agent's
intentional refusal of a critical process before the explicit exit-code
check. Disable that for the step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jusso-dev jusso-dev changed the title feat: Windows response — signed actions, process control, quarantine, WFP plan feat: Windows response, signed actions, process control, quarantine, WFP plan Nov 9, 2026
@jusso-dev

Copy link
Copy Markdown
Owner Author

Status: all 11 CI checks pass on 9170edb. That includes agent (windows-x64), which ran the live response step:

  • kill ping by PID and start time;
  • suspend and resume a child;
  • refuse lsass;
  • quarantine and restore a file, hash checked.

Still in progress on this branch: live WFP isolation (fwpuclnt calls, reconcile at start, break-glass release --code). Today isolate_host and release report failed with a reason. A CI test for it will only be added if it can't cut the runner off, for example by blocking one TEST-NET address.

Open for Justin, from the PR body:

  • the action key is derived from the JWT seed when TAWNY_ACTION_SIGNING_KEY is unset;
  • the TOFU pin is taken on first heartbeat;
  • the Windows quarantine ACL is SYSTEM plus Administrators, not SYSTEM only.

Stacked on #66. Merge order: #62 to #66, then this.

jusso-dev and others added 3 commits November 10, 2026 03:30
Link fwpuclnt (Windows only) and implement the live WFP engine in
platform/windows/wfp.zig: FwpmEngineOpen0, a transaction, the Tawny
provider and fixed-GUID sublayer, persistent filters built from the pure
plan (permit loopback, resolved server IPs, DNS resolvers and an optional
admin allowlist on the four ALE layers, block everything else), and
delete by sublayer on release. A TCP verify probe reports the server
reachable and a blocked address unreachable.

Wire isolate_host and release to it on Windows; Linux and macOS keep a
clear "not supported on <os>" failure. Isolation state is persisted to
<state_path>.wfp so the agent reconciles filters with the journal at
start and releases itself when the deadline (default 24 h) passes,
checked on each heartbeat and at start. Break-glass
`tawny-agent release --code <code>` verifies the HMAC of the agent id and
nonce with TAWNY_ISOLATION_SECRET.

CI: a safe live WFP step runs `tawny-agent --wfp-selftest`, which adds a
single TEST-NET block filter (never a block-all, so it can't cut the
runner off), confirms it is present and that a routable address stays
reachable, then releases and confirms the sublayer is empty.

Docs: target-edr §9 and api.md updated for live isolation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lter by id

The Windows self-test added its filter but countFilters found nothing.
countFilters read only the first page of up to 256 filters per layer,
with a provider-key template, and a busy layer on the runner can hide
ours past that page. It now pages through every entry and matches on
the Tawny sublayer. The self-test also checks the filter directly with
FwpmFilterGetById0 and prints the WFP status on failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Windows CI: filter enumeration failed with 0x80320004
(FWP_E_LAYER_NOT_FOUND). The last eight bytes of the RECV_ACCEPT_V6
layer GUID were wrong, so every enumeration over the layer list failed
and the self-test saw zero filters. The filter add itself succeeded
(found by id).

The layer and condition GUIDs now sit at the top level with a test
pinning them to the SDK values (fwpmu.h as published in
microsoft/windows-rs), so it runs on every OS.

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

Copy link
Copy Markdown
Owner Author

Status: all 11 CI checks pass on 5bd105a, now with live WFP.

Windows runner self-test output:

wfp added id=74223 exists_by_id=true count_after_add=1
wfp-selftest id=74223 count_after_add=1 blocked_unreachable=true internet_up=true count_after_release=0

So a filter is added in the Tawny sublayer, the TEST-NET address is blocked, a routable address still connects, and release leaves no filters.

Fixed on the way: the FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6 GUID had wrong trailing bytes, so enumeration failed with FWP_E_LAYER_NOT_FOUND. The layer and condition GUIDs are now pinned to the SDK values by a test that runs on every OS. The earlier agent-cross (macos-x64) failure was a DNS error fetching libyara on the runner, and it passed on rerun.

Not shown by CI: full block-all isolation (it would cut the runner off) and surviving a reboot. Needs a manual test on a spare Windows VM.

Open for Justin, from the PR body:

  • release --code reads TAWNY_ISOLATION_SECRET; the UI to show it isn't built.
  • DHCP and DNS-by-hostname are reduced to address permits.
  • A server reachable only over IPv6 isn't allowed through.
  • The action key is derived from the JWT seed when unset.
  • The TOFU pin is taken on first heartbeat.
  • The quarantine ACL is SYSTEM plus Administrators.

@jusso-dev
jusso-dev changed the base branch from feat/detection-engine to main November 9, 2026 22:44
@jusso-dev
jusso-dev merged commit 174b120 into main Nov 9, 2026
11 checks passed
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.

EDR 5: Windows response, kill and suspend, file quarantine, WFP isolation with a timeout, signed commands

1 participant