Skip to content
TarunnoPublic

About

Go daemon that mirrors CrowdSec LAPI/ipset/nftable bans into GCP VPC and Azure NSG rules, with Redis-backed state, TTL expiry and rule reusablity.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

Ashwall

Sync CrowdSec blacklists (ipset, nftables, or CrowdSec LAPI) to cloud firewall rules on GCP and Azure.

Ashwall watches a local blacklist source, creates matching deny rules in your cloud firewalls, and removes them when bans expire. State is tracked in Redis.

Architecture

Ashwall architecture

How it works

  1. Reads banned IPs from ipset, nftables, or the CrowdSec decisions API
  2. Reuses an existing cloud firewall/NSG rule when it still has capacity and enough Redis TTL; otherwise creates a new rule
  3. Stores ban metadata in Redis with TTLs matching the ban duration
  4. The unban service deletes orphaned cloud rules whose Redis keys have expired

Requirements

  • Go 1.23+
  • Redis
  • One of:
    • ipset with an active blacklist set
    • nft with an active blacklist set (e.g. CrowdSec nftables bouncer)
    • CrowdSec Local API reachable with a bouncer API key
  • Credentials for the active cloud only (CLOUD_PROVIDER=gce or azure)

Configuration

Copy the templates from config/ to /opt:

sudo cp config/.env /opt/.env
sudo cp config/service-account.json /opt/service-account.json

Runtime tuning lives in config/init.conf (installed to /opt/ashwall/config/init.conf).

Edit /opt/.env:

Variable Description
CLOUD_PROVIDER gce/gcp or azure (optional; falls back to GCP/Azure IMDS auto-detect)
GCP_PROJECT GCP project ID
GCP_NETWORK VPC network path (e.g. global/networks/default)
GCP_SERVICE_ACCOUNT_PATH Path to GCP service account JSON
BLACKLIST_BACKEND ipset (default), nftables, or crowdsec
IPSET_NAME Local ipset to watch (when backend is ipset)
NFT_FAMILY nftables family, e.g. inet (when backend is nftables)
NFT_TABLE nftables table, e.g. crowdsec
NFT_SET nftables set, e.g. crowdsec-blacklists
CROWDSEC_LAPI_URL CrowdSec LAPI base URL, e.g. http://127.0.0.1:8080
CROWDSEC_LAPI_KEY Bouncer API key from cscli bouncers add
CROWDSEC_DECISION_TYPE Decision type filter (default ban)
SUBSCRIPTION_ID Azure subscription ID
RESOURCE_GROUP Azure resource group
AZURE_CLIENT_ID Azure app (client) ID
AZURE_TENANT_ID Azure tenant ID
AZURE_CLIENT_SECRET Azure client secret
REDIS_ADDR Redis address (localhost:6379)
REDIS_PASSWORD Redis password (empty if none)
REDIS_DB Redis DB index

config/init.conf

Key Description
BANSCHEDULER_INTERVAL Ban poll interval (seconds)
UNBANSCHEDULER_INTERVAL Orphan cleanup interval (seconds)
BAN_DURATION Ban TTL in Redis / rule lifetime (seconds)
MAX_IPS_PER_RULE Max IPs packed into one cloud rule before creating another
REUSE_IF_TTL_LESS_THAN Reuse a rule only if its Redis TTL is at least this many seconds
REDIS_BANRULE_KEY_PREFIX Redis key prefix for ban rules
REDIS_BANNED_IP_KEY_PREFIX Redis key prefix for banned IPs

Platform limits

Feature Azure NSG GCP Firewall
Max IPs per rule 4,000 256 CIDR blocks
Practical Ashwall default 250 250

nftables (CrowdSec)

BLACKLIST_BACKEND=nftables
NFT_FAMILY=inet
NFT_TABLE=crowdsec
NFT_SET=crowdsec-blacklists

Confirm the set exists:

sudo nft list set inet crowdsec crowdsec-blacklists

CrowdSec decisions API

sudo cscli bouncers add ashwall
BLACKLIST_BACKEND=crowdsec
CROWDSEC_LAPI_URL=http://127.0.0.1:8080
CROWDSEC_LAPI_KEY=<bouncer-api-key>
CROWDSEC_DECISION_TYPE=ban

Ashwall polls /v1/decisions/stream?startup=true each ban cycle and syncs active IP/range decisions.

Fill in service-account.json with your GCP service account credentials.

NSG names are derived from the machine hostname prefix: {hostname}-nsg.

Build & install

go build -o ashwall
chmod +x scripts/install.sh
sudo ./scripts/install.sh

This installs the binary to /opt/ashwall and enables two systemd services:

  • ashwall-ban — watches the local blacklist and creates/updates cloud firewall rules
  • ashwall-unban — deletes orphaned cloud rules after Redis TTLs expire

Service management

sudo systemctl status ashwall-ban ashwall-unban
sudo systemctl restart ashwall-ban ashwall-unban
sudo journalctl -u ashwall-ban -u ashwall-unban -f

License

Private — all rights reserved.

About

Go daemon that mirrors CrowdSec LAPI/ipset/nftable bans into GCP VPC and Azure NSG rules, with Redis-backed state, TTL expiry and rule reusablity.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages