Skip to content

feat: readable firewall rule expressions - #5

Merged
Jamkris merged 3 commits into
mainfrom
feat/firewall-page-improve
Jul 10, 2026
Merged

feat: readable firewall rule expressions#5
Jamkris merged 3 commits into
mainfrom
feat/firewall-page-improve

Conversation

@Jamkris

@Jamkris Jamkris commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

The Firewall page showed each rule's body as raw nftables JSON, which is unreadable. This renders it in nft-like syntax instead.

  • New pure services/nftexpr.py render_expr() — converts the JSON statement list to text (e.g. tcp dport 22 accept, ip saddr @allowlist accept, ct state in { established, related } accept). Defensive: unknown shapes fall back to compact JSON, never raises.
  • Firewall rules table shows the readable form; the original JSON is on hover (title).
  • Section headers tidied (Chains / Sets / Rules).

Test plan

  • python -m pytest -q → 137 passed. New: tests/test_nftexpr.py (12 cases incl. UFW/zapret-style rules).

Follow-up

Will validate against a real nft -j list ruleset dump and add a fixture if any rule renders oddly.


Summary by cubic

Render firewall rules in readable nft syntax instead of raw JSON to make the Firewall page easier to scan. Handles implicit set membership and meta-key formatting with safe fallbacks.

  • New Features
    • Added services/nftexpr.py with render_expr() to convert nftables JSON to nft-like text; supports implicit set membership and correct meta-key prefixes; unknown shapes fall back to compact JSON; names iptables-nft xt matches.
    • Firewall page shows readable rule expressions with the original JSON in the title tooltip; updated headers and code.rule-expr styling/hover.
    • Exposed nft_expr as a template global; added tests for UFW/iptables-nft rules, meta keys, set membership, and fallback cases.

Written for commit eaf3d5a. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread bastion/services/nftexpr.py
Comment thread tests/test_nftexpr.py Outdated
Comment thread bastion/services/nftexpr.py Outdated
Comment thread bastion/services/nftexpr.py Outdated
@Jamkris
Jamkris merged commit 2e2a555 into main Jul 10, 2026
4 checks passed
@Jamkris
Jamkris deleted the feat/firewall-page-improve branch July 10, 2026 02:32
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