mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-09-02 20:28:50 +02:00
Compare commits
2
Commits
v1.1.11-beta
...
v1.1.11
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fcd4f4e2f | ||
|
|
39fcc38980 |
@@ -30,4 +30,6 @@ Steps to reproduce the behavior:
|
|||||||
3. Scroll down to '....'
|
3. Scroll down to '....'
|
||||||
4. See error
|
4. See error
|
||||||
|
|
||||||
|
<!---
|
||||||
If you like the plugin, please consider starring it, so you can get updates and we get some more visibility ✨
|
If you like the plugin, please consider starring it, so you can get updates and we get some more visibility ✨
|
||||||
|
-->
|
||||||
|
|||||||
@@ -16,4 +16,6 @@ A clear and concise description of what you want to happen.
|
|||||||
**Additional context**
|
**Additional context**
|
||||||
Add any other context or screenshots about the feature request here.
|
Add any other context or screenshots about the feature request here.
|
||||||
|
|
||||||
|
<!---
|
||||||
If you like the plugin, please consider starring it, so you can get updates and we get some more visibility ✨
|
If you like the plugin, please consider starring it, so you can get updates and we get some more visibility ✨
|
||||||
|
-->
|
||||||
|
|||||||
+11
-10
@@ -144,7 +144,6 @@ func New(ctx context.Context, next http.Handler, config *configuration.Config, n
|
|||||||
config.RedisCachePassword, _ = configuration.GetVariable(config, "RedisCachePassword")
|
config.RedisCachePassword, _ = configuration.GetVariable(config, "RedisCachePassword")
|
||||||
bouncer.cacheClient.New(config.RedisCacheEnabled, config.RedisCacheHost, config.RedisCachePassword)
|
bouncer.cacheClient.New(config.RedisCacheEnabled, config.RedisCacheHost, config.RedisCachePassword)
|
||||||
|
|
||||||
//nolint:nestif
|
|
||||||
if (config.CrowdsecMode == configuration.StreamMode || config.CrowdsecMode == configuration.AloneMode) && ticker == nil {
|
if (config.CrowdsecMode == configuration.StreamMode || config.CrowdsecMode == configuration.AloneMode) && ticker == nil {
|
||||||
if config.CrowdsecMode == configuration.AloneMode {
|
if config.CrowdsecMode == configuration.AloneMode {
|
||||||
if err := getToken(bouncer); err != nil {
|
if err := getToken(bouncer); err != nil {
|
||||||
@@ -152,17 +151,10 @@ func New(ctx context.Context, next http.Handler, config *configuration.Config, n
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := handleStreamCache(bouncer); err != nil {
|
handleStreamTicker(bouncer)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
isStartup = false
|
isStartup = false
|
||||||
ticker = startTicker(config, func() {
|
ticker = startTicker(config, func() {
|
||||||
if err := handleStreamCache(bouncer); err != nil {
|
handleStreamTicker(bouncer)
|
||||||
isCrowdsecStreamHealthy = false
|
|
||||||
logger.Error(err.Error())
|
|
||||||
} else {
|
|
||||||
isCrowdsecStreamHealthy = true
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
logger.Debug(fmt.Sprintf("New initialized mode:%s", config.CrowdsecMode))
|
logger.Debug(fmt.Sprintf("New initialized mode:%s", config.CrowdsecMode))
|
||||||
@@ -269,6 +261,15 @@ type Login struct {
|
|||||||
Expire string `json:"expire"`
|
Expire string `json:"expire"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleStreamTicker(bouncer *Bouncer) {
|
||||||
|
if err := handleStreamCache(bouncer); err != nil {
|
||||||
|
isCrowdsecStreamHealthy = false
|
||||||
|
logger.Error(err.Error())
|
||||||
|
} else {
|
||||||
|
isCrowdsecStreamHealthy = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func startTicker(config *configuration.Config, work func()) chan bool {
|
func startTicker(config *configuration.Config, work func()) chan bool {
|
||||||
ticker := time.NewTicker(time.Duration(config.UpdateIntervalSeconds) * time.Second)
|
ticker := time.NewTicker(time.Duration(config.UpdateIntervalSeconds) * time.Second)
|
||||||
stop := make(chan bool, 1)
|
stop := make(chan bool, 1)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ version: "3.8"
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
traefik:
|
traefik:
|
||||||
image: "traefik:v2.9.6"
|
image: "traefik:v2.9.8"
|
||||||
container_name: "traefik"
|
container_name: "traefik"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
command:
|
command:
|
||||||
@@ -15,7 +15,7 @@ services:
|
|||||||
- "--entrypoints.web.address=:80"
|
- "--entrypoints.web.address=:80"
|
||||||
|
|
||||||
- "--experimental.plugins.bouncer.modulename=github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin"
|
- "--experimental.plugins.bouncer.modulename=github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin"
|
||||||
- "--experimental.plugins.bouncer.version=v1.1.7"
|
- "--experimental.plugins.bouncer.version=v1.1.11-beta2"
|
||||||
# - "--experimental.localplugins.bouncer.modulename=github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin"
|
# - "--experimental.localplugins.bouncer.modulename=github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin"
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
@@ -26,16 +26,17 @@ services:
|
|||||||
- 8080:8080
|
- 8080:8080
|
||||||
depends_on:
|
depends_on:
|
||||||
- crowdsec
|
- crowdsec
|
||||||
- redis
|
- redis-insecure
|
||||||
|
- redis-secure
|
||||||
|
|
||||||
whoami-foo:
|
whoami-redis-insecure:
|
||||||
image: traefik/whoami
|
image: traefik/whoami
|
||||||
container_name: "simple-service-foo"
|
container_name: "simple-service-foo"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
# Definition of the router
|
# Definition of the router
|
||||||
- "traefik.http.routers.router-foo.rule=Path(`/foo`)"
|
- "traefik.http.routers.router-foo.rule=Path(`/redis-insecure`)"
|
||||||
- "traefik.http.routers.router-foo.entrypoints=web"
|
- "traefik.http.routers.router-foo.entrypoints=web"
|
||||||
- "traefik.http.routers.router-foo.middlewares=crowdsec-foo@docker"
|
- "traefik.http.routers.router-foo.middlewares=crowdsec-foo@docker"
|
||||||
# Definition of the service
|
# Definition of the service
|
||||||
@@ -45,16 +46,18 @@ services:
|
|||||||
# crowdseclapikey must be uniq to the middleware attached to the service
|
# crowdseclapikey must be uniq to the middleware attached to the service
|
||||||
- "traefik.http.middlewares.crowdsec-foo.plugin.bouncer.crowdseclapikey=40796d93c2958f9e58345514e67740e5"
|
- "traefik.http.middlewares.crowdsec-foo.plugin.bouncer.crowdseclapikey=40796d93c2958f9e58345514e67740e5"
|
||||||
- "traefik.http.middlewares.crowdsec-foo.plugin.bouncer.rediscacheenabled=true"
|
- "traefik.http.middlewares.crowdsec-foo.plugin.bouncer.rediscacheenabled=true"
|
||||||
|
# Contact redis-unsecure without a password
|
||||||
|
- "traefik.http.middlewares.crowdsec-foo.plugin.bouncer.redisCacheHost=redis-insecure:6379"
|
||||||
- "traefik.http.middlewares.crowdsec-foo.plugin.bouncer.loglevel=DEBUG"
|
- "traefik.http.middlewares.crowdsec-foo.plugin.bouncer.loglevel=DEBUG"
|
||||||
|
|
||||||
whoami-bar:
|
whoami-redis-secure:
|
||||||
image: traefik/whoami
|
image: traefik/whoami
|
||||||
container_name: "simple-service-bar"
|
container_name: "simple-service-bar"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
# Definition of the router
|
# Definition of the router
|
||||||
- "traefik.http.routers.router-bar.rule=Path(`/bar`)"
|
- "traefik.http.routers.router-bar.rule=Path(`/redis-secure`)"
|
||||||
- "traefik.http.routers.router-bar.entrypoints=web"
|
- "traefik.http.routers.router-bar.entrypoints=web"
|
||||||
- "traefik.http.routers.router-bar.middlewares=crowdsec-bar@docker"
|
- "traefik.http.routers.router-bar.middlewares=crowdsec-bar@docker"
|
||||||
# Definition of the service
|
# Definition of the service
|
||||||
@@ -64,11 +67,14 @@ services:
|
|||||||
# crowdseclapikey must be uniq to the middleware attached to the service
|
# crowdseclapikey must be uniq to the middleware attached to the service
|
||||||
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.crowdseclapikey=44c36dac5c4140af9f06f397508e82c7"
|
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.crowdseclapikey=44c36dac5c4140af9f06f397508e82c7"
|
||||||
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.rediscacheenabled=true"
|
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.rediscacheenabled=true"
|
||||||
|
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.redisCachePassword=FIXME"
|
||||||
|
# Contact redis-secure with password
|
||||||
|
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.redisCacheHost=redis-secure:6379"
|
||||||
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.loglevel=DEBUG"
|
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.loglevel=DEBUG"
|
||||||
|
|
||||||
|
|
||||||
crowdsec:
|
crowdsec:
|
||||||
image: crowdsecurity/crowdsec:v1.4.3
|
image: crowdsecurity/crowdsec:v1.4.6
|
||||||
container_name: "crowdsec"
|
container_name: "crowdsec"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
@@ -84,18 +90,27 @@ services:
|
|||||||
labels:
|
labels:
|
||||||
- "traefik.enable=false"
|
- "traefik.enable=false"
|
||||||
|
|
||||||
redis:
|
redis-secure:
|
||||||
image: "redis:7.0.5-alpine"
|
image: "redis:7.0.9-alpine"
|
||||||
container_name: "redis"
|
container_name: "redis-secure"
|
||||||
|
hostname: redis-secure
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
command: "redis-server --save 60 1"
|
command: "redis-server --save 60 1 --loglevel debug --requirepass FIXME"
|
||||||
volumes:
|
volumes:
|
||||||
- redis-data:/data
|
- redis-secure-data:/data
|
||||||
ports:
|
|
||||||
- 6379:6379
|
redis-insecure:
|
||||||
|
image: "redis:7.0.9-alpine"
|
||||||
|
container_name: "redis-insecure"
|
||||||
|
hostname: redis-unsecure
|
||||||
|
restart: unless-stopped
|
||||||
|
command: "redis-server --save 60 1 --loglevel debug"
|
||||||
|
volumes:
|
||||||
|
- redis-unsecure-data:/data
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
logs-redis:
|
logs-redis:
|
||||||
crowdsec-db-redis:
|
crowdsec-db-redis:
|
||||||
crowdsec-config-redis:
|
crowdsec-config-redis:
|
||||||
redis-data:
|
redis-unsecure-data:
|
||||||
|
redis-secure-data:
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ go 1.19
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/leprosus/golang-ttl-map v1.1.7
|
github.com/leprosus/golang-ttl-map v1.1.7
|
||||||
github.com/maxlerebourg/simpleredis v1.0.5
|
github.com/maxlerebourg/simpleredis v1.0.6
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
github.com/leprosus/golang-ttl-map v1.1.7 h1:cF4AAFDDnJTFSV+/42sKLhmMluvLdRlCGS2UaifH6UM=
|
github.com/leprosus/golang-ttl-map v1.1.7 h1:cF4AAFDDnJTFSV+/42sKLhmMluvLdRlCGS2UaifH6UM=
|
||||||
github.com/leprosus/golang-ttl-map v1.1.7/go.mod h1:4QWHJPeVBbrkhOhXdhCv9IEiyj/YzkO04/iexy4vSe0=
|
github.com/leprosus/golang-ttl-map v1.1.7/go.mod h1:4QWHJPeVBbrkhOhXdhCv9IEiyj/YzkO04/iexy4vSe0=
|
||||||
github.com/maxlerebourg/simpleredis v1.0.5 h1:1ubyIpTgIb+dadpILivAxuhZTHOOapEHRhcMakveuYY=
|
github.com/maxlerebourg/simpleredis v1.0.6 h1:dKd0hgKk7uGKjujWUMuPTVOAONYdlCys5Iqh6w3dOU4=
|
||||||
github.com/maxlerebourg/simpleredis v1.0.5/go.mod h1:/DH8zOK6kDskSqoX/m5CJJdNGfkIQZd/ERBJgytDDSk=
|
github.com/maxlerebourg/simpleredis v1.0.6/go.mod h1:/DH8zOK6kDskSqoX/m5CJJdNGfkIQZd/ERBJgytDDSk=
|
||||||
|
|||||||
+4
-2
@@ -1,6 +1,7 @@
|
|||||||
# simpleredis
|
# simpleredis
|
||||||
Minimal go redis with only `get`, `set` and `delete` operation.
|
Minimal go redis with only `get`, `set` and `delete` operation.
|
||||||
With **NO** extern dependencies.
|
It supports password authentication with redis.
|
||||||
|
With **NO** external dependencies.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
```go
|
```go
|
||||||
@@ -26,4 +27,5 @@ if err != nil {
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
Max Lerebourg @ [Primadviz.com](https://primadviz.com)
|
Max Lerebourg @ [Primadviz.com](https://primadviz.com)
|
||||||
|
Mathieu Hanotaux
|
||||||
+2
-1
@@ -81,8 +81,9 @@ func askRedis(sr *SimpleRedis, cmd redisCmd, channel chan redisCmd) {
|
|||||||
channel <- redisCmd{Error: fmt.Errorf(RedisNoAuth)}
|
channel <- redisCmd{Error: fmt.Errorf(RedisNoAuth)}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
// breaks out of for
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
# github.com/leprosus/golang-ttl-map v1.1.7
|
# github.com/leprosus/golang-ttl-map v1.1.7
|
||||||
## explicit; go 1.15
|
## explicit; go 1.15
|
||||||
github.com/leprosus/golang-ttl-map
|
github.com/leprosus/golang-ttl-map
|
||||||
# github.com/maxlerebourg/simpleredis v1.0.5
|
# github.com/maxlerebourg/simpleredis v1.0.6
|
||||||
## explicit; go 1.19
|
## explicit; go 1.19
|
||||||
github.com/maxlerebourg/simpleredis
|
github.com/maxlerebourg/simpleredis
|
||||||
|
|||||||
Reference in New Issue
Block a user