Repository navigation
nftables: per-rule logging and a live firewall-log view - #14
Merged
Merged
Conversation
Add the OPNsense-style logging model to the nftables backend: mark a rule to be logged, and watch the logged rules fire in a live view. Per-rule logging (l): a rule the tool owns is replaced in place with `nft replace rule … log prefix "tui:<chain> <verdict> " …`, keeping its handle and position. The replacement is rebuilt from the rule's own modelled match and previewed like every other mutation; a rule the model does not hold in full — an unmodeled match, a NAT translation, an unsupported verdict — is refused rather than rewritten from a rendering. The log statement (prefix, level, group) now round-trips through the reader, and a logged rule carries a LOG marker in its row. Live log (w): a read-only stream of the kernel firewall log, filtered to the tool's own `tui:` prefix, read with `journalctl --kernel --follow`. Each event is parsed into time, direction, action, source, destination, port and prefix and shown newest-last; the feed pauses and the retained lines are capped. --demo plays a synthetic feed so the view animates with no journald and no root. --check and --report note how many owned rules log and whether the live source is readable. Exec for the stream stays inside internal/nftables (the backend package), so the exec boundary is unchanged. Validated against nft v1.1.1 in a rootless netns (the replace and reject-with syntax, and the JSON round-trip); the kernel-log parser is proven on the documented nf_log line format, since a rootless netns fires the rule but does not deliver its kernel log line. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MCypLQF5AD8JD831Ea9S9q
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the OPNsense-style logging model to the nftables backend: mark a rule to be logged, and watch the logged rules fire in a live view.
Per-rule logging (
l)nft replace rule … log prefix "tui:<chain> <verdict> " …, keeping its handle and position. nft rules are immutable, so a log statement can only be added or removed by replacing the whole rule.log/nflogstatement (prefix, level, group) now round-trips through the reader; the prefix keeps its own trailing space so it round-trips to nft. Arejectrule keeps the answer it sends.LOGmarker in its row and a LOG column.Live log (
w)tui:prefix, read withjournalctl --kernel --follow --output=short-iso. A machine without journald is told so plainly.--demoplays a synthetic feed so the view animates with no journald and no root.--check/--reportnote how many owned rules log and whether the live source is readable.Boundary
Exec for the stream stays inside
internal/nftables/(the backend package), socheck-exec.shis unchanged. Every mutation is still a previewedrunner.Command.Validation (no lab)
make checkgreen: fmt, vet, golangci (incl. gosec), exec boundary, tests, tidy.unshare -rn: thereplace … log prefix …and its reverse are accepted,reject with tcp reset+ log is accepted, and the log statement round-trips throughnft -j. A logging drop rule fires (counter increments) but the rootless netns does not deliver its kernel-log line, so the parser is proven on the documentednf_logline format as labelled fixtures.FuzzParseKernelLogLine(45s) plusFuzzDecodeExprs(35s) andFuzzParseRuleset(30s) with new log/nflog/reject seeds — no crashes.Lab acceptance still owed (item 10's lab twin, for later)
Mark a drop-with-log rule through the real TUI, generate blocked traffic against the router, and see the live view show the event with the correct direction and source — on the multi-VM lab where the init-namespace kernel log and journald deliver the line.
🤖 Generated with Claude Code