Back to Engineering Blog
Systems Design 3 min read

A Firewall Bouncer on a Router With No Python

We deployed a CrowdSec firewall bouncer on an OpenWrt router using only Ansible's raw module, because the device has no Python. The first remote bouncer then hit a loopback-bound API.

Jason NevillBy , Houston, TX
#CrowdSec#OpenWrt#Ansible#nftables

Key Architectural Takeaways

  • Ansible's raw module runs over the bare SSH channel, so it works on devices with no Python; set gather_facts to false.
  • Raw tasks cannot report idempotency, so accept 'always changed' as a documented tradeoff.
  • A service bound to loopback is fine for its local agent and invisible to a remote one.

The challenge

The central CrowdSec server was ingesting the fleet's centralised logs and making decisions, but nothing enforced them. We needed a bouncer on a firewall. pfSense was deliberately excluded for now: its only CrowdSec package was an unstable community beta, and installing any pfSense package needed web-UI access that the read-only account did not have.

OpenWrt is the opposite case. crowdsec-firewall-bouncer (nftables-based, version 0.0.34) is a genuine, current, official package in the router's own repository. We confirmed that before building.

The first role for a Python-less host

The router has no Python at all: neither python3 nor python exists, and no Python package is installed. Normal Ansible modules need it. Our role uses ansible.builtin.raw exclusively, which runs over the raw SSH channel, and the playbook sets gather_facts: false, because the implicit setup module would fail too.

Configuration is UCI (uci set, uci commit) instead of YAML templates, which is simpler than the Debian-side setup. The cost: raw tasks have no change detection, so they always report "changed". We accepted and documented that as a tradeoff rather than treating it as a bug.

The bug

The remote bouncer got "connection refused". The CrowdSec local API was bound to 127.0.0.1:8080, fine for its own local agent and useless to a remote bouncer. We added a task binding the API to all interfaces, with the same trust model as the lab's other LAN-bound services, gated by the bouncer's API key. The key was generated on the server and kept in the encrypted group variables.

Verification

The bind change resolved the connection-refused error for the remote bouncer. The role is idempotent in effect, though not in reporting.

Takeaway

When the target lacks the runtime your tooling assumes, go one layer down to the transport, and be explicit about what you gave up. And "connection refused" from a remote client is usually a bind address.

Follow the build on LinkedIn or by RSS.

All Articles

Follow the build

Questions about the build, or spotted something we got wrong? Find us on LinkedIn and GitHub.