Skip to content

Linux kernel sensor: audit netlink, Tetragon reader, minimal capabilities (#59) - #70

Merged
jusso-dev merged 13 commits into
mainfrom
feat/linux-sensor
Nov 9, 2026
Merged

jusso-dev merged 13 commits into
mainfrom
feat/linux-sensor

Conversation

@jusso-dev

Copy link
Copy Markdown
Owner

Stacked on #68.

Linux kernel-backed process, network and file events for the agent (#59). The agent reads the kernel audit subsystem over NETLINK_AUDIT itself and can optionally read Tetragon's JSON export. The /proc poller stays on as the fallback and as a reconciliation pass.

Acceptance criteria

Criterion Status
Decision record with the chosen source and why Done: docs/architecture/linux-sensor.md (audit netlink in the agent, optional Tetragon reader, Falco not used)
Short-lived processes the poller misses show up as process_start with entity ids Done in code and unit tests. Live proof is the new CI step (50 /bin/true runs, at least 50 events with entity ids). See "What ran where" for the container limit
Outbound connections show up as network_connect with the owning process Done: connect records joined with SOCKADDR, owning process entity_id and pid. Tested on captured records (IPv4, IPv6, v4-mapped, EINPROGRESS). Unix sockets and refused connects are dropped
Still runs as tawny with only the documented capabilities, all other hardening kept Done: AmbientCapabilities and CapabilityBoundingSet list CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_DAC_READ_SEARCH CAP_KILL CAP_SYS_PTRACE. test-install.sh checks the exact set and every hardening line. Each capability is documented in docs/production-agent-hardening.md
With no kernel source, falls back to polling and reports degraded health Done: sensor_health (sensor: linux_kernel, status: degraded, reason) at start, and agent_health.sensors carries linux_kernel with source, status and events_per_minute. CI checks it with no capabilities
CI green, including agent (linux-x64) and agent-cross (linux-arm64) See the checks on this PR

What changed

  • agent/src/platform/linux/audit.zig: netlink reader (registers as audit daemon and loads rules keyed tawny, or joins the read-only multicast group when auditd owns the socket), an auditd log tail, and pure functions for record parsing, joining by serial (SYSCALL, EXECVE, CWD, PATH, SOCKADDR, PROCTITLE, EOE), mapping to v2 events and audit_rule_data encoding. Captured samples are in testdata/. A pin test checks the message types, field ids, arch values and syscall numbers against linux/audit.h and the std syscall tables.
  • agent/src/platform/linux/tetragon.zig: maps process_exec, process_exit and process_kprobe (tcp_connect) export lines to the same events, with pure tests.
  • agent/src/collectors/linux_sensor.zig: picks the source (linux_sensor = auto | audit | audit_log | tetragon | proc), drains it each loop, reports health and drops poller events the kernel source already sent. With audit netlink or Tetragon running the poller runs every 10 minutes; with a partial source (multicast, log) it keeps its normal interval. tawny-agent --linux-sensor-dump prints events with no server, for CI and operators.
  • agent/install/install.sh: the unit is written by a function so the dry run prints it; two capability lines added, nothing else changed.
  • CI: new step on agent (linux-x64).

Not in this PR

  • nftables isolation is left for a follow-up. isolate_host still answers "isolate_host is not supported on linux yet", which ci/agent_e2e.py and the contract suite depend on. No CAP_NET_ADMIN is granted.
  • fanotify, eBPF in the agent, Falco.

Commands run and results

Command Where Result
zig build -Doptimize=ReleaseSafe macOS arm64 ok
zig build test --summary all macOS arm64 192 passed, 7 skipped
cross-builds x86_64-linux, aarch64-linux, x86_64-windows, x86_64-macos (ReleaseSafe) macOS all ok
zig build test --summary all in ubuntu:26.04 (agent only mounted) OrbStack aarch64 container 165 passed, 28 skipped (schema checks skip without schemas/)
bash agent/install/test-install.sh macOS and ubuntu:26.04 passed; a negative run with one capability removed fails as expected
--linux-sensor-dump --source audit_log with testdata/audit.log appended live container 2 process_start, 1 network_connect, 2 file_create, 1 process_exit
new CI step script, run in a container with sudo shimmed container passes through the fallback branch (multicast, then log path with 50 events, then no-caps degraded)
setpriv recipe from the docs container CapEff, CapAmb, CapBnd all 0000002040080024 (exactly the five)
cd server && zig test src/main.zig -lc macOS 158 passed, 0 SafeAllocator lines
/tmp/run-e2e.sh macOS agent fails at "isolate result", and fails the same way on the base branch: the script expects the Linux message and the agent was a macOS build
e2e with the Linux agent in a container against the same server OrbStack container heartbeat_ok, event_ok, schema_v2_ok, isolate_result_ok, e2e_ok

What ran where, and the gap

Docker containers (OrbStack, including --privileged --pid=host) refuse audit netlink (auditctl gets EPERM adding a rule), because the kernel only allows it from the initial namespaces. So live audit netlink was not proved locally. The CI step on the hosted VM is the live proof. If the hosted runner also refuses it, the step warns audit netlink was not available to the sensor and proves the auditd log path instead. I will note the result here once checks finish.

🤖 Generated with Claude Code

jusso-dev and others added 4 commits November 10, 2026 06:21
Compares Tetragon, Falco and auditd netlink and picks audit netlink in
the agent, with Tetragon's JSON export as an optional source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
platform/linux/audit.zig reads NETLINK_AUDIT as the audit daemon (or the
read-only multicast group when auditd owns it, or auditd's log), joins
SYSCALL, EXECVE, CWD, PATH, SOCKADDR and PROCTITLE records by serial and
maps them to v2 process_start, process_exit, network_connect and
file_create with entity ids. Parsing, joining, mapping and rule encoding
are pure and tested against captured records in testdata/, with a pin
test for the kernel constants.

platform/linux/tetragon.zig maps Tetragon's export (process_exec,
process_exit, tcp_connect kprobes) to the same events.

collectors/linux_sensor.zig picks the source, reports it in
sensor_health and agent_health.sensors (source, status, events per
minute), and keeps the /proc poller as a 10 minute reconciliation pass
beside a complete source, or as the fallback with degraded health.
--linux-sensor-dump prints events without a server for CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AmbientCapabilities and CapabilityBoundingSet list CAP_AUDIT_CONTROL,
CAP_AUDIT_READ, CAP_DAC_READ_SEARCH, CAP_KILL and CAP_SYS_PTRACE. User=tawny
and every other hardening line stay. The dry run prints the unit and
test-install.sh checks the exact set and each hardening line. Each
capability is documented in production-agent-hardening.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
agent (linux-x64) runs --linux-sensor-dump as an unprivileged user with
exactly the five unit capabilities through sudo setpriv, runs /bin/true
50 times and expects at least 50 process_start events with entity ids
from audit netlink. If the runner refuses audit netlink it proves the
auditd log path instead and warns. With no capabilities the sensor must
fall back to the poller and report degraded.

A watch rule for a missing folder no longer stops the agent registering
as the audit daemon.

nftables isolation is left for a follow-up; isolate_host keeps its
not-supported message on Linux.

Closes #59

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

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: afd0bee2-f9bd-4066-b896-7c35c1f8e723
Commits

Reviewing files that changed from the base of the PR and between eba4b12 and adf6970.

Files ignored due to path filters: 1

  • agent/src/platform/linux/testdata/audit.log is excluded by !**/*.log
Files selected for processing: 15

  • .github/workflows/ci.yml
  • .gitignore
  • agent/install/install.sh
  • agent/install/test-install.sh
  • agent/src/collectors/linux_sensor.zig
  • agent/src/collectors/process_events.zig
  • agent/src/config.zig
  • agent/src/main.zig
  • agent/src/platform/linux/audit.zig
  • agent/src/platform/linux/testdata/README.md
  • agent/src/platform/linux/testdata/netlink_exec_connect.txt
  • agent/src/platform/linux/testdata/tetragon.jsonl
  • agent/src/platform/linux/tetragon.zig
  • docs/architecture/linux-sensor.md
  • docs/production-agent-hardening.md
  • 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 7 commits November 10, 2026 06:42
*.log is ignored repo-wide, so testdata/audit.log never reached the
branch and every agent job failed at @embedfile. Recreated it to the
shape testdata/README.md and the test describe (node= prefix, enriched
\x1d suffix, a split hex argument, execveat with only PROCTITLE, a
connect, creates under PARENT and CWD, exit_group). Addresses use
documentation ranges. Ran in an ubuntu:26.04 container: 183/193 pass,
10 skipped, and the test fails when the fixture is altered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The agent aborted under setpriv on the runner, but its output went to a
file the step never showed, so the panic message was lost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
windows-x64 runs the Linux parser tests too. std.fs.path.join uses the
host separator, so a created file came out as /etc/cron.d\backdoor and
the auditd log test failed. Audit and Tetragon records always carry
Linux paths, so use POSIX-only helpers, with a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Linux runner aborted the agent: std.Thread.spawn hit 'reached
unreachable code' starting the audit reader under setpriv with the
audit capabilities (it treats EPERM and EINVAL from pthread_create as
unreachable). Call pthread_create directly, log the errno, and return an
error so the sensor falls back to polling. On that error, unload the
rules and unregister before returning, without a double free.

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

- The audit reader thread is still refused on the runner. Health now
  says which pthread_create errno it was instead of "failed to start".
- The fallback CI path chowned the log to tawny-ci, so the runner could
  no longer append to it (Permission denied). The runner keeps
  ownership; tawny-ci only needs to read it. Checked in an ubuntu:26.04
  container: 50 process_start events from the log path.

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

- The runner refused pthread_create with EINVAL for the reader thread's
  attributes. Retry once with libc defaults before falling back.
- The log-path fallback read a file under /home/runner, which tawny-ci
  can't traverse ("audit log not readable"). Use a 0755 dir under
  /tmp. Checked in ubuntu:26.04 with a 0750 home: 50 process_start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Live audit capture now works on the runner: 54 process_start and 54
process_exit with entity IDs, 50 of them for /bin/true. On Ubuntu 26.04
/bin/true resolves to /usr/bin/gnutrue, so the check counted 0. It now
matches readlink -f /bin/true.

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 4e4a531. Live kernel audit capture is proven on the hosted Linux runner, not the log-file fallback:

sensor source: audit_netlink
SUMMARY  source=audit_netlink  status=running  process_start=54  process_exit=54
/bin/true resolves to /usr/bin/gnutrue

The agent ran as tawny-ci under setpriv with only the five documented capabilities, registered as the audit daemon, and caught all 50 short-lived /bin/true runs as process_start, with entity IDs and matching process_exit. The no-capabilities case falls back to the /proc poller and reports degraded.

The step's grep count reads 100, not 50, because each matching line counts twice in the output file. The check is "at least 50", so this doesn't change the result, but the count is overstated. It's a small follow-up.

Fixed after the PR opened:

  • testdata/audit.log was never committed, because *.log is gitignored. Recreated it and added an exception.
  • Linux paths were joined with the host separator, which broke the parser tests on Windows.
  • std.Thread.spawn aborted the agent: it treats a pthread_create EINVAL as unreachable. The agent now calls pthread_create itself, retries with default attributes, and falls back softly if that fails too.
  • CI fallback path: log file permissions, and a log directory tawny-ci can traverse.
  • The check now matches the real path of /bin/true.

Not done: nftables isolation (isolate_host still says "not supported on linux"). network_connect and file_create are covered by tests on captured records, not by a live CI check.

Decisions for Justin:

  • When auditd already owns the socket, the agent reads that daemon's records read-only and reports degraded. It never changes auditd's rules.
  • The CI step stops auditd on the runner if one is running.

Stacked on #68. It's independent of #69, so merge either first.

…check

The check matched the image path on any line, so each /bin/true run was
counted on both its process_start and its process_exit, giving 100.
Count process_start lines only. Checked against the runner's real output
from the last run: 50.

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 ba5ad9c. The Linux check now counts only process_start lines and reports the real count: process_start events for /bin/true: 50 (source audit_netlink).

@jusso-dev
jusso-dev changed the base branch from feat/agent-hardening to main November 9, 2026 22:44
@jusso-dev
jusso-dev merged commit 37b4d9c 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.

1 participant