Update auto ban

This commit is contained in:
2026-04-01 19:54:01 +11:00
parent 7ae2616308
commit 5c6786231f
2 changed files with 37 additions and 2 deletions
+14 -2
View File
@@ -99,13 +99,25 @@ spec:
sed 's/,$//') sed 's/,$//')
echo "Active ban count: $(echo "$RAW" | tail -n +2 | grep -c '.' || echo 0)" echo "Active ban count: $(echo "$RAW" | tail -n +2 | grep -c '.' || echo 0)"
echo "Blocked CIDRs: ${CIDRS:-<none>}"
# Read any manually managed IPs from block-cidrs-manual key in the same ConfigMap.
# Edit that key to permanently block IPs that CrowdSec won't remove.
MANUAL=$(kubectl get configmap ingress-nginx-controller \
-n ingress-nginx \
-o jsonpath='{.data.block-cidrs-manual}' 2>/dev/null || true)
# Merge CrowdSec bans + manual list, deduplicate
ALL=$(printf '%s,%s' "$CIDRS" "$MANUAL" | tr ',' '\n' | grep -v '^$' | sort -u | tr '\n' ',' | sed 's/,$//')
echo "CrowdSec bans: ${CIDRS:-<none>}"
echo "Manual bans: ${MANUAL:-<none>}"
echo "Merged total: ${ALL:-<none>}"
# Patch the NGINX Ingress ConfigMap (JSON merge patch — only updates block-cidrs) # Patch the NGINX Ingress ConfigMap (JSON merge patch — only updates block-cidrs)
kubectl patch configmap ingress-nginx-controller \ kubectl patch configmap ingress-nginx-controller \
-n ingress-nginx \ -n ingress-nginx \
--type merge \ --type merge \
-p "{\"data\":{\"block-cidrs\":\"${CIDRS}\"}}" -p "{\"data\":{\"block-cidrs\":\"${ALL}\"}}"
echo "ConfigMap patched successfully" echo "ConfigMap patched successfully"
resources: resources:
+23
View File
@@ -16,3 +16,26 @@ sudo netplan apply
# Check DNS servers # Check DNS servers
resolvectl status resolvectl status
## Block IP
# Ban a single IP for 1 year
kubectl exec -n crowdsec deployment/crowdsec-lapi -- \
cscli decisions add --ip 1.2.3.4 --duration 8760h --reason "manual-ban"
# Ban a subnet
kubectl exec -n crowdsec deployment/crowdsec-lapi -- \
cscli decisions add --range 1.2.3.0/24 --duration 8760h --reason "manual-ban"
# List all active decisions (including manual ones)
kubectl exec -n crowdsec deployment/crowdsec-lapi -- cscli decisions list
# Remove a manual ban
kubectl exec -n crowdsec deployment/crowdsec-lapi -- \
cscli decisions delete --ip 1.2.3.4
# # Add IPs (comma-separated, supports CIDRs)
kubectl patch configmap ingress-nginx-controller -n ingress-nginx \
--type merge \
-p '{"data":{"block-cidrs-manual":"1.2.3.4,5.6.7.0/24"}}'