How crowdsecurity/cs-firewall-bouncer works
This Go service synchronizes CrowdSec API decisions into firewall blocklists. The main loop loads configuration, initializes a selected backend, and adds or removes supported decisions; backend implementations cover iptables/ipset, nftables, and pf, with a dry-run option. Prometheus metrics are exposed alongside backend-specific counters. The README documents API synchronization and firewall support; detailed API polling and some backend internals were not included in the excerpts, so those links are limited to documented or directly evidenced relationships.
Main entry points: backend.go Backend dispatcher · root.go Command and sync loop · metrics.go Metrics definitions · iptables.go iptables backend
Components 20
Runtime and sync
- Program entry
main.go - Command and sync loop
cmd/root.go - Backend dispatcher
pkg/backend/backend.go
Firewall backends
- iptables backend
pkg/iptables/iptables.go - iptables rules and sets
pkg/iptables/iptables_context.go - ipset command helper
pkg/ipsetcmd/ipset.go - nftables backend
pkg/nftables/nftables.go - nftables contexts
pkg/nftables/nftables_context.go - pf backend
pkg/pf/pf.go - pf contexts
pkg/pf/pf_context.go - Dry-run backend
pkg/dryrun/dryrun.go
Metrics
- Metrics definitions
pkg/metrics/metrics.go - Prometheus endpoint
cmd/root.go - iptables metrics
pkg/iptables/metrics.go - nftables metrics
pkg/nftables/metrics.go - pf metrics
pkg/pf/metrics.go
Shared support
- Configuration
pkg/cfg/config.go - Backend interface
pkg/types/types.go
Other components
- Operator
- CrowdSec API
Connections 20
- Operator → Program entry: runs
main.go - Program entry → Command and sync loop: executes
main.go - Command and sync loop → Configuration: loads
cmd/root.go - CrowdSec API → Command and sync loop: provides decisions
README.md - Command and sync loop → Backend dispatcher: dispatches decisions
cmd/root.go - Backend dispatcher → iptables backend: selects
pkg/backend/backend.go - Backend dispatcher → nftables backend: selects
pkg/backend/backend.go - Backend dispatcher → pf backend: selects
pkg/backend/backend.go - Backend dispatcher → Dry-run backend: selects
pkg/backend/backend.go - Backend dispatcher → Backend interface: implements contract
pkg/backend/backend.go - iptables backend → iptables rules and sets: delegates rules
pkg/iptables/iptables.go - iptables rules and sets → ipset command helper: manages sets
pkg/iptables/iptables_context.go - nftables backend → nftables contexts: uses contexts
pkg/nftables/nftables.go - pf backend → pf contexts: uses contexts
pkg/pf/pf.go - Command and sync loop → Prometheus endpoint: starts endpoint
cmd/root.go - Command and sync loop → Metrics definitions: registers metrics
cmd/root.go - iptables backend → iptables metrics: collects counters
pkg/iptables/metrics.go - iptables metrics → Metrics definitions: updates gauges
pkg/iptables/metrics.go - nftables metrics → Metrics definitions: updates gauges
pkg/nftables/metrics.go - pf metrics → Metrics definitions: updates gauges
pkg/pf/metrics.go