
A http service to verify request and bounce them according to decisions made by CrowdSec.
This repository aim to implement a CrowdSec bouncer for the router Traefik to block malicious IP to access your services. For this it leverages Traefik v2 ForwardAuth middleware and query CrowdSec with client IP. If the client IP is on ban list, it will get a http code 403 response. Otherwise, request will continue as usual.
Docker and Docker-compose installed.
You can use the docker-compose in the examples' folder as a starting point.
Through traefik it exposes the whoami countainer on port 80, with the bouncer accepting and rejecting client IP.
Launch your all services except the bouncer with the follow commands:
bashgit clone https://github.com/fbonalair/traefik-crowdsec-bouncer.git && \ cd traefik-crowdsec-bouncer/examples && \ docker-compose up -d traefik crowdsec whoami
docker exec crowdsec-example cscli bouncers add traefik-bouncerCROWDSEC_BOUNCER_API_KEY, instead of "MyApiKey"docker-compose up bouncerX-Real-Ip line (i.e. 192.168.128.1).docker exec crowdsec-example cscli decisions add --ip 192.168.128.1, modify the IP with your address.docker exec crowdsec-example cscli decisions delete --ip 192.168.128.1Enjoy!
For now, this web service is mainly fought to be used as a container.
If you need to build from source, you can get some inspiration from the Dockerfile.
You should have Traefik v2 and a CrowdSec instance running.
The container is available on docker as image fbonalair/traefik-crowdsec-bouncer. Host it as you see fit, though it must have access to CrowdSec and be accessible by Traefik.
Follow traefik v2 ForwardAuth middleware documentation to create a forwardAuth middle pointing to your bouncer host.
Generate a bouncer API key following CrowdSec documentation
The webservice configuration is made via environment variables:
CROWDSEC_BOUNCER_API_KEY - CrowdSec bouncer API key required to be authorized to request local API (required)`CROWDSEC_AGENT_HOST - Host and port of CrowdSec agent, i.e. crowdsec-agent:8080 (required)`CROWDSEC_BOUNCER_SCHEME - Scheme to query CrowdSec agent. Expected value: http, https. Default to http`CROWDSEC_BOUNCER_LOG_LEVEL - Minimum log level for bouncer. Expected value https://pkg.go.dev/github.com/rs/zerolog#readme-leveled-logging. Default to 1CROWDSEC_BOUNCER_BAN_RESPONSE_CODE - HTTP code to respond in case of ban. Default to 403CROWDSEC_BOUNCER_BAN_RESPONSE_MSG - HTTP body as message to respond in case of ban. Default to ForbiddenPORT - Change listening port of web server. Default listen on 8080GIN_MODE - By default, run app in "debug" mode. Set it to "release" in productionTRUSTED_PROXIES - List of trusted proxies IP addresses in CIDR format, delimited by ','. Default of 0.0.0.0/0 should be fine for most use cases, but you HAVE to add them directly in traefik.The webservice exposes some routes:
/api/v1/forwardAuth - Main route to be used by Traefik: query CrowdSec agent with the header X-Real-Ip as client IP`/api/v1/ping - Simple health route that respond pong with http 200`/api/v1/healthz - Another health route that query CrowdSec agent with localhost (127.0.0.1)`/api/v1/metrics - Prometheus route to scrap metricsAny constructive feedback is welcome, fill free to add an issue or a pull request. I will review it and integrate it to the code.
_test.env from template _test.env.example such as cp _test.env.example _test.env docker exec traefik-crowdsec-bouncer-crowdsec-1 cscli bouncers add traefik-bouncer_test.env replace <your_generated_api_key> with the previously generated keydocker exec traefik-crowdsec-bouncer-crowdsec-1 cscli decisions add -i 1.2.3.4godotenv -f ./_test.env go test -cover您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。





探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
不支持 push
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务