traefik-crowdsec-bouncer

command module
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2023 License: MIT Imports: 8 Imported by: 0

README

thespad/traefik-crowdsec-bouncer

A http service to verify requests and bounce them according to decisions made by CrowdSec. Fork of https://github.com/fbonalair/traefik-crowdsec-bouncer with extra features.

GitHub Release Commits Image Size Docker Pulls GitHub Stars Docker Stars

Prerequisites

  • Docker and Docker-compose installed.
  • Traefik v2.x
  • CrowdSec running natively or in a container and configured to read logs from Traefik

Application Setup

  1. Get a bouncer API key from CrowdSec with command docker exec crowdsec cscli bouncers add bouncer-traefik
  2. Pull the docker image for the bouncer: docker pull ghcr.io/thespad/traefik-crowdsec-bouncer
  3. Copy the API key printed. You WON'T be able the get it again.
  4. Paste this API key as the value for bouncer environment variable CROWDSEC_BOUNCER_API_KEY, or use an .env file.
  5. Set the other environment variables as required (see below for details).
  6. Start bouncer.
  7. Visit a site proxied by Traefik and confirm you can access it.
  8. In another console, ban your IP with command docker exec crowdsec cscli decisions add --ip <your ip> -R "Test Ban", modify the IP with your address.
  9. Visit the site again, in your browser you will see "Forbidden" since this time since you've been banned.
  10. Unban yourself with docker exec crowdsec cscli decisions delete --ip <your IP>
  11. Visit the site one last time, you will have access to the site again.
Traefik Setup

Create a Forward Auth middleware, i.e.

    middleware-crowdsec-bouncer:
      forwardauth:
        address: http://crowdsec-bouncer-traefik:8080/api/v1/forwardAuth
        trustForwardHeader: true

Then apply it either to individual containers you wish to protect or as a default middlware on the Traefik listener.

Exposed routes

The webservice exposes some routes:

  • GET /api/v1/forwardAuth - Main route to be used by Traefik: query CrowdSec agent with the header X-Real-Ip as client IP`
  • GET /api/v1/ping - Simple health route that respond pong with http 200`
  • GET /api/v1/healthz - Another health route that query CrowdSec agent with localhost (127.0.0.1)`
  • GET /api/v1/metrics - Prometheus route to scrap metrics

Versions

  • 01.05.23: - Move docker image to its own repo.
  • 01.05.23: - Update deps.
  • 01.05.23: - Restructure repo.
  • 26.04.23: - Support CF forwarded IP headers.
  • 15.02.22: - Initial Release.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
bouncer module
healthcheck module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL