From 1098e5230e2483fbc34141ab1c3056f40db5e98c Mon Sep 17 00:00:00 2001 From: MathieuHa Date: Wed, 28 Sep 2022 21:04:58 +0200 Subject: [PATCH] Add initial readme, update com on bouncer --- README.md | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ bouncer.go | 1 + 2 files changed, 75 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ad1a1ae --- /dev/null +++ b/README.md @@ -0,0 +1,74 @@ +[![Build Status](https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/workflows/Main/badge.svg?branch=master)](https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/actions) + +# Crowdsec Bouncer Traefik plugin + +This plugins aims to implement a Crowdsec Bouncer into a traefik plugin + +## Usage + + +### Configuration + +For each plugin, the Traefik static configuration must define the module name (as is usual for Go packages). + +The following declaration (given here in YAML) defines a plugin: + +```yaml +# Static configuration + +experimental: + localPlugins: + bouncer: + moduleName: github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin +``` + +```yaml +# Dynamic configuration + +http: + routers: + my-router: + rule: host(`woami.localhost`) + service: service-foo + entryPoints: + - web + middlewares: + - my-plugin + + services: + service-foo: + loadBalancer: + servers: + - url: http://127.0.0.1:5000 + + middlewares: + crowdsec: + plugin: + bouncer: + enabled: true + crowdseclapikey: 40796d93c2958f9e58345514e67740e5 +``` + +### Local Mode + +Traefik also offers a developer mode that can be used for temporary testing of plugins not hosted on GitHub. +To use a plugin in local mode, the Traefik static configuration must define the module name (as is usual for Go packages) and a path to a [Go workspace](https://golang.org/doc/gopath_code.html#Workspaces), which can be the local GOPATH or any directory. + +The plugins must be placed in `./plugins-local` directory, +which should be in the working directory of the process running the Traefik binary. +The source code of the plugin should be organized as follows: + +``` +./plugins-local/ + └── src + └── github.com + └── maxlerebourg + └── crowdsec-bouncer-traefik-plugin + ├── bouncer.go + ├── bouncer_test.go + ├── go.mod + ├── LICENSE + ├── Makefile + ├── readme.md + └── vendor/* +``` diff --git a/bouncer.go b/bouncer.go index 618b329..144eff1 100644 --- a/bouncer.go +++ b/bouncer.go @@ -140,6 +140,7 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h return bouncer, nil } +// TODO the serve HTTP should be split as it's too long func (a *Bouncer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { if !a.enabled { log.Printf("Crowdsec Bouncer not enabled")