CrowdSec integration for matrix-webhook-bridge
A script that polls CrowdSec for new decisions and forwards them to Matrix via matrix-webhook-bridge.
Every 5 minutes, the script runs via a systemd timer, fetches recent decisions from the local
CrowdSec container using cscli, and sends a formatted Matrix message for each new ban or
remediation via matrix-webhook-bridge.
Assumptions
- CrowdSec runs as a Docker container named
crowdsecon the same host. matrix-webhook-bridgeis reachable athttp://localhost:5001(configurable viaMATRIX_WEBHOOK_BRIDGE_URL).- If
server.webhook_secretis set on the bridge, pointBRIDGE_CONFIGat the config file so the script reads the secret automatically (requirespyyaml). Alternatively, exportWEBHOOK_SECRETdirectly. - The script runs every 5 minutes via a systemd timer and queries decisions from the last
5m(configurable viaSINCE).
Add a Matrix Application Service
Follow the instructions in the Matrix Application Service Setup guide to set up a Matrix Application Service for CrowdSec and invite the bot user to a room on your Synapse server.
Setup
Copy the script and systemd units to the appropriate locations and make the script executable:
curl \
-L https://raw.githubusercontent.com/krahlos/matrix-webhook-bridge/main/integrations/crowdsec-alert/notify-decisions.py \
-o /etc/crowdsec/notify-decisions.py
chmod +x /etc/crowdsec/notify-decisions.py
curl \
-L https://raw.githubusercontent.com/krahlos/matrix-webhook-bridge/main/integrations/crowdsec-alert/crowdsec-decisions.service \
-o /etc/systemd/system/crowdsec-decisions.service
curl \
-L https://raw.githubusercontent.com/krahlos/matrix-webhook-bridge/main/integrations/crowdsec-alert/crowdsec-decisions.timer \
-o /etc/systemd/system/crowdsec-decisions.timer
Then enable and start the timer: