Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Not working - Probably configuration issue ? #136

Closed
luckylinux opened this issue Feb 24, 2024 · 11 comments
Closed

[BUG] Not working - Probably configuration issue ? #136

luckylinux opened this issue Feb 24, 2024 · 11 comments
Assignees
Labels
question Further information is requested

Comments

@luckylinux
Copy link

luckylinux commented Feb 24, 2024

Describe the bug 馃悰
IP Banning not working. Middleware loads into traefik dashboard for a few seconds (if at all), then disappears. Traefik probably crashes and restarts without middleware ???

Expected behavior 馃憖
IP Banning working, middleware correctly and permanently listed in traefik dashboard.

Context 馃攷
At first I thought that the issue was related to this, since the plugin type wasn't recognized. As such, I applied the same fix as suggested by @ jLemmings in #95.

I am not sure whether I need to just set the dynamic configuration or if I need to define a middleware with a different name each time for each container in their own compose.yml file. I tried both approaches, with the per-container defined middleware to usually load into traefik dashboard then disappear a few seconds later (and unsure if traefik crashed in the meantime ...).

As such I find the example in the documentation for the whoami container a bit confusing/misleading: aren't we already configuring the middleware (including the LAPI Key) in the traefik dynamic configuration file ? Or probably something (obvious) which I fail to see ...

Version (please complete the following information):

  • OS: Debian GNU/Linux Bookworm (12) AMD, Podman from Debian Testing/Trixie Repositories using APT Pinning (4.9.3)
  • Traefik version: 2.11.0
  • Plugin version: 1.2.0
  • Redis: No

To Reproduce
Unsure to be honest.

This is what I have used.

Traefik configured via compose.yml file

version: '3.9'

networks:
  traefik:
    external: true

services:
  traefik:
    image: traefik:latest
    hostname: ra.MYDOMAIN.TLD
    domainname: MYDOMAIN.TLD
    restart: unless-stopped
    container_name: traefik
    ports:
      - 80:80
      - 443:443
#      - 8080:8080
#      - 8443:8443
    networks:
      - traefik
    volumes:
      - /run/user/1001/podman/podman.sock:/var/run/docker.sock:ro
      - ~/data/traefik/letsencrypt:/letsencrypt
#      - ~/config/traefik/traefik.yml:/etc/traefik/traefik.yml:ro # Command line arguments, static configuration file and environment variables are mutually exclusive: https://doc.traefik.io/traefik/getting-started/configuration-overview/#the-static-configuration
      - ~/config/traefik/dynamic:/etc/traefik/dynamic
      - ~/certificates/traefik:/certificates
      - ~/log/traefik:/log
    command:
      ## Logging
      # Server Log
      - "--log.level=DEBUG"
#      - "--log.level=INFO"
      - "--log.filePath=/log/server/traefik.log"

      # Error Log
      - "--accesslog=true"
      - "--accesslog.filePath=/log/access/access.log"

      ## Dashboard & API
      - "--api"
      - "--api.insecure=false" # production = false , development = true
      - "--api.dashboard=true"

      ## EntryPoints
      # Unsecure Connection - Redirect to Secure
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web.http.redirections.entrypoint.to=websecure"
      - "--entryPoints.web.http.redirections.entrypoint.scheme=https"
#      - "--entrypoints.web.http.redirections.entrypoint.permanent=true"

      # Secure Connection
      - "--entrypoints.websecure.address=:443"
      - "--entrypoints.websecure.http.tls=true"
      - "--entrypoints.websecure.http.tls.certresolver=letsencrypt"
      - "--entryPoints.websecure.transport.respondingTimeouts.readTimeout=420"
      - "--entryPoints.websecure.transport.respondingTimeouts.writeTimeout=420"
      - "--entryPoints.websecure.transport.respondingTimeouts.idleTimeout=420"


      ## Letsencrypt Configuration
#      - "--certificatesresolvers.lets-encrypt.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory" # For testing only
      - "--certificatesresolvers.letsencrypt.acme.caserver=https://acme-v02.api.letsencrypt.org/directory" # Production - Rated limited !!!
      - "--certificatesresolvers.letsencrypt.acme.email=MYEMAIL@MYDOMAIN.TLD"
      - "--certificatesresolvers.letsencrypt.acme.httpchallenge=true"           
      - "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web" 
#      - "--certificatesresolvers.letsencrypt.acme.tlschallenge=true"
      - "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"

      ## Docker / Podman Intergration
      - "--providers.docker=true"
      - "--providers.docker.exposedByDefault=false"
      - "--providers.docker.watch=false"
      - "--providers.docker.swarmMode=false"
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"

      # Crowdsec Plugin
      - "--experimental.plugins.crowdsec-bouncer-traefik-plugin.moduleName=github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin"
      - "--experimental.plugins.crowdsec-bouncer-traefik-plugin.version=v1.2.0" # Version Must be manually updated

      ## Other
      # ...
      - "--serversTransport.insecureSkipVerify=true"

      # No Telemetry
      - "--global.sendAnonymousUsage=false"

    labels:
      # Enable Traefik
      - "traefik.enable=true"

      # Dashboard
      - "traefik.http.routers.dashboard.rule=Host(`ra.MYDOMAIN.TLD`) && PathPrefix(`/api` , `/dashboard`)"
      - "traefik.http.routers.dashboard.service=api@internal"
      - "traefik.http.routers.dashboard.middlewares=authtraefik , crowdsec"

      # Authentication for Dashboard access
      - "traefik.http.middlewares.authtraefik.basicauth.usersfile=/config/users"

      # Create bouncer middleware
#      - "traefik.http.middlewares.crowdsec.plugin.crowdsec-bouncer-traefik-plugin.crowdseclapikey=MVr63g3nqsNzzb79J67FEw"
#      - "traefik.http.middlewares.crowdsec.plugin.crowdsec-bouncer-traefik-plugin.crowdseclapischeme=http"
#      - "traefik.http.middlewares.crowdsec.plugin.crowdsec-bouncer-traefik-plugin.crowdseclapihost=crowdsec:8080"

Dynamic traefik configuration (based on stock config - only replaced plugin name based on jLemmings findings in #95)

# Dynamic configuration

http:
  routers:
    my-router:
      rule: host(`whoami.localhost`)
      service: service-foo
      entryPoints:
        - web
      middlewares:
        - crowdsec

  services:
    service-foo:
      loadBalancer:
        servers:
          - url: http://127.0.0.1:5000

  middlewares:
#    default-crowdsec-bouncer-traefik-plugin:
#      CrowdsecLapiKey: XXXXXXXXXXXXXXXXXXXXXXX
#      Enabled: true
    crowdsec:
      plugin:
        crowdsec-bouncer-traefik-plugin:
          enabled: true
          logLevel: DEBUG
          updateIntervalSeconds: 60
          defaultDecisionSeconds: 60
          httpTimeoutSeconds: 10
          crowdsecMode: live
          crowdsecAppsecEnabled: false
          crowdsecAppsecHost: crowdsec:7422
          crowdsecAppsecFailureBlock: true
          crowdsecLapiKey: XXXXXXXXXXXXXXXXXXXXXXX
#          crowdsecLapiKeyFile: /etc/traefik/cs-privateKey-foo
          crowdsecLapiHost: crowdsec:8080
          crowdsecLapiScheme: http
          crowdsecLapiTLSInsecureVerify: false
          crowdsecCapiMachineId: login
          crowdsecCapiPassword: password
          crowdsecCapiScenarios:
            - crowdsecurity/http-path-traversal-probing
            - crowdsecurity/http-xss-probing
            - crowdsecurity/http-generic-bf
          forwardedHeadersTrustedIPs:
#            - 10.0.10.23/32
#            - 10.0.20.0/24
          clientTrustedIPs:
#            - 192.168.1.0/24
          forwardedHeadersCustomName: X-Custom-Header
          redisCacheEnabled: false
          redisCacheHost: "redis:6379"
          redisCachePassword: password
          redisCacheDatabase: "5"
#          crowdsecLapiTLSCertificateAuthority: |-
#            -----BEGIN CERTIFICATE-----
#            MIIEBzCCAu+gAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwgZQxCzAJBgNVBAYTAlVT
#            ...
#            Q0veeNzBQXg1f/JxfeA39IDIX1kiCf71tGlT
#            -----END CERTIFICATE-----
#          crowdsecLapiTLSCertificateAuthorityFile: /etc/traefik/crowdsec-certs/ca.pem
#          crowdsecLapiTLSCertificateBouncer: |-
#            -----BEGIN CERTIFICATE-----
#            MIIEHjCCAwagAwIBAgIUOBTs1eqkaAUcPplztUr2xRapvNAwDQYJKoZIhvcNAQEL
#            ...
#            RaXAnYYUVRblS1jmePemh388hFxbmrpG2pITx8B5FMULqHoj11o2Rl0gSV6tHIHz
#            N2U=
#            -----END CERTIFICATE-----
#          crowdsecLapiTLSCertificateBouncerFile: /etc/traefik/crowdsec-certs/bouncer.pem
#          crowdsecLapiTLSCertificateBouncerKey: |-
#            -----BEGIN RSA PRIVATE KEY-----
#            MIIEogIBAAKCAQEAtYQnbJqifH+ZymePylDxGGLIuxzcAUU4/ajNj+qRAdI/Ux3d
#            ...
#            ic5cDRo6/VD3CS3MYzyBcibaGaV34nr0G/pI+KEqkYChzk/PZRA=
#            -----END RSA PRIVATE KEY-----
#          crowdsecLapiTLSCertificateBouncerKeyFile: /etc/traefik/crowdsec-certs/bouncer-key.pem

Example of container compose.yml configuration for Headscale:

version: '3.9'
networks:
  headscale:
    external: true

services:
  headscale:
    image: headscale/headscale:latest
#    pull_policy: always
    container_name: headscale
    hostname: headscale.MYDOMAIN.TLD
    domainname: MYDOMAIN.TLD
    restart: unless-stopped
    command: headscale serve
    volumes:
      - ~/config/headscale:/etc/headscale
      - ~/data/headscale:/var/lib/headscale
 #   ports:
 #     - 8080:8080
 #     - 9090:9090
 #   networks:
 #     -  traefik
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.headscale-rtr.rule=PathPrefix(`/`) && Host(`headscale.MYDOMAIN.TLD`)"
      - "traefik.http.routers.headscale-rtr.middlewares=crowdsec"

      - "traefik.http.services.headscale-svc.loadbalancer.server.port=8080"

#      - "traefik.http.middlewares.headscale-crowdsec.plugin.bouncer.crowdseclapikey=XXXXXXXXXXXXXXX"
#      - "traefik.http.middlewares.headscale-crowdsec.plugin.bouncer.crowdseclapischeme=http"
#      - "traefik.http.middlewares.headscale-crowdsec.plugin.bouncer.crowdseclapihost=crowdsec:8080"
    depends_on:
      - traefik

@mathieuHa mathieuHa self-assigned this Feb 25, 2024
@mathieuHa mathieuHa added the question Further information is requested label Feb 25, 2024
@mathieuHa
Copy link
Collaborator

mathieuHa commented Feb 26, 2024

Hey @luckylinux,

I looked at your configuration and I tried to make a minimal/simplified working example for you.
It is based on a docker-compose and only 2 files for configuration:

docker-compose.yml

version: '3.9'

networks:
  traefik:
    external: true

services:
  traefik:
    image: traefik:latest
    # hostname: ra.MYDOMAIN.TLD
    # domainname: MYDOMAIN.TLD
    restart: unless-stopped
    container_name: traefik
    ports:
      - 80:80
      - 443:443
      - 8080:8080
#      - 8443:8443
    networks:
      - traefik
    volumes:
      - /run/user/1001/podman/podman.sock:/var/run/docker.sock:ro
      - ~/data/traefik/letsencrypt:/letsencrypt
#      - ~/config/traefik/traefik.yml:/etc/traefik/traefik.yml:ro # Command line arguments, static configuration file and environment variables are mutually exclusive: https://doc.traefik.io/traefik/getting-started/configuration-overview/#the-static-configuration
      - ./whoami.yml:/whoami.yml
      - ~/certificates/traefik:/certificates
      # - ~/log/traefik:/log
      - "logs:/var/log/traefik"
    command:
      ## Logging
      # Server Log
      - "--log.level=DEBUG"
#      - "--log.level=INFO"
      - "--log.filePath=/log/server/traefik.log"

      # Error Log
      - "--accesslog=true"
      - "--accesslog.filePath=/log/access/access.log"
      
      ## Dashboard & API
      - "--api"
      - "--api.insecure=true" # production = false , development = true
      - "--api.dashboard=true"

      ## EntryPoints
      # Unsecure Connection - Redirect to Secure
      - "--entrypoints.web.address=:80"
      # - "--entrypoints.web.http.redirections.entrypoint.to=websecure"
      # - "--entryPoints.web.http.redirections.entrypoint.scheme=https"
#      - "--entrypoints.web.http.redirections.entrypoint.permanent=true"

      ## Docker / Podman Intergration
      - "--providers.docker=true"
      - "--providers.docker.exposedByDefault=false"
      - "--providers.docker.watch=false"
      - "--providers.docker.swarmMode=false"
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"
      - "--providers.file.filename=/whoami.yml"

      # Crowdsec Plugin
      - "--experimental.plugins.crowdsec-bouncer-traefik-plugin.moduleName=github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin"
      - "--experimental.plugins.crowdsec-bouncer-traefik-plugin.version=v1.2.0" # Version Must be manually updated

      ## Other
      # ...
      - "--serversTransport.insecureSkipVerify=true"

      # No Telemetry
      - "--global.sendAnonymousUsage=false"
  
  whoami1:
    image: traefik/whoami
    container_name: "simple-service-foo"
    networks:
      - traefik

  crowdsec:
    image: crowdsecurity/crowdsec:v1.6.0
    container_name: "crowdsec"
    hostname: crowdsec
    restart: unless-stopped
    environment:
      COLLECTIONS: crowdsecurity/traefik crowdsecurity/appsec-virtual-patching
      CUSTOM_HOSTNAME: crowdsec
      # We need to register one api key per service we will use
      BOUNCER_KEY_test: XXXXXXXXXXXXXXXXXXXXXXX
    volumes:
      - ./acquis.yaml:/etc/crowdsec/acquis.yaml:ro
      - logs:/var/log/traefik:ro
    labels:
      - "traefik.enable=false"
    networks:
      - traefik

volumes:
  logs:

whoami.yml

# Dynamic configuration

http:
  routers:
    my-router:
      rule: PathPrefix(`/foo`)
      service: service-foo
      entryPoints:
        - web
      middlewares:
        - crowdsec

  services:
    service-foo:
      loadBalancer:
        servers:
          - url: http://172.18.0.3:80

  middlewares:
    crowdsec:
      plugin:
        crowdsec-bouncer-traefik-plugin:
          enabled: true
          logLevel: DEBUG
          updateIntervalSeconds: 60
          defaultDecisionSeconds: 60
          httpTimeoutSeconds: 10
          crowdsecMode: live
          crowdsecAppsecEnabled: false
          crowdsecAppsecHost: crowdsec:7422
          crowdsecAppsecFailureBlock: true
          crowdsecLapiKey: XXXXXXXXXXXXXXXXXXXXXXX
          crowdsecLapiHost: crowdsec:8080
          crowdsecLapiScheme: http

acquis.yml

---
filenames:
 - /var/log/traefik/access.log
labels:
  type: traefik

---
listen_addr: 0.0.0.0:7422
appsec_config: crowdsecurity/virtual-patching
name: myAppSecComponent
source: appsec
labels:
  type: appsec

Create thoses 3 files and launch a terminal in the same path.

``虁`
docker compose up -d

docker-compose logs traefik -f

docker-compose logs crowdsec -f
``虁`

Then access:

http://localhost/foo to test the whoami service

In Traefik logs you should see something like this:

time="2024-02-26T18:39:34Z" level=info msg="Configuration loaded from flags."
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:34 No IP provided for ForwardedHeadersTrustedIPs
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:34 No IP provided for ClientTrustedIPs
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:34 getTLSConfigCrowdsec:CrowdsecLapiScheme https:no
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:34 cache:New initialized isRedis:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:34 New initialized mode:live
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:43 ServeHTTP ip:172.18.0.1 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:43 cache:GetDecision ip:172.18.0.1
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:43 ServeHTTP:getDecision ip:172.18.0.1 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:43 ServeHTTP:handleNoStreamCache ip:172.18.0.1 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=172.18.0.1&banned=true, statusCode:403
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:51 ServeHTTP ip:172.18.0.1 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:51 cache:GetDecision ip:172.18.0.1
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:51 ServeHTTP:getDecision ip:172.18.0.1 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:39:51 ServeHTTP:handleNoStreamCache ip:172.18.0.1 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=172.18.0.1&banned=true, statusCode:403
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:22 ServeHTTP ip:172.18.0.1 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:22 cache:GetDecision ip:172.18.0.1
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:22 ServeHTTP:getDecision ip:172.18.0.1 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:22 ServeHTTP:handleNoStreamCache ip:172.18.0.1 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=172.18.0.1&banned=true, statusCode:403
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:24 ServeHTTP ip:172.18.0.1 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:24 cache:GetDecision ip:172.18.0.1
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:24 ServeHTTP:getDecision ip:172.18.0.1 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:24 ServeHTTP:handleNoStreamCache ip:172.18.0.1 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=172.18.0.1&banned=true, statusCode:403
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:45:59 ServeHTTP ip:172.18.0.1 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:45:59 cache:GetDecision ip:172.18.0.1
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:45:59 ServeHTTP:getDecision ip:172.18.0.1 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:45:59 cache:SetDecision ip:172.18.0.1 isBanned:false duration:60s

In Crowdsec you might see logs like this:

be effective."
Registered bouncer for test
time="2024-02-26T18:45:47Z" level=info msg="Enabled feature flags: <none>"
time="2024-02-26T18:45:47Z" level=info msg="Crowdsec v1.5.6-rc12-4b8e6cd7"
time="2024-02-26T18:45:47Z" level=info msg="Loading prometheus collectors"
time="2024-02-26T18:45:47Z" level=info msg="Loading CAPI manager"
time="2024-02-26T18:45:48Z" level=info msg="CAPI manager configured successfully"
time="2024-02-26T18:45:48Z" level=error msg="Machine is not enrolled in the console, can't synchronize with the console"
time="2024-02-26T18:45:48Z" level=info msg="Start push to CrowdSec Central API (interval: 10s once, then 10s)"
time="2024-02-26T18:45:48Z" level=info msg="Start sending metrics to CrowdSec Central API (interval: 18m51s once, then 30m0s)"
time="2024-02-26T18:45:48Z" level=info msg="CrowdSec Local API listening on [::]:8080"
time="2024-02-26T18:45:48Z" level=warning msg="scenario list is empty, will not pull yet"
time="2024-02-26T18:45:48Z" level=info msg="capi metrics: sending"
time="2024-02-26T18:45:48Z" level=info msg="Loading grok library /etc/crowdsec/patterns"
time="2024-02-26T18:45:48Z" level=info msg="Loading enrich plugins"
time="2024-02-26T18:45:48Z" level=info msg="Successfully registered enricher 'GeoIpCity'"
time="2024-02-26T18:45:48Z" level=info msg="Successfully registered enricher 'GeoIpASN'"
time="2024-02-26T18:45:48Z" level=info msg="Successfully registered enricher 'IpToRange'"
time="2024-02-26T18:45:48Z" level=info msg="Successfully registered enricher 'reverse_dns'"
time="2024-02-26T18:45:48Z" level=info msg="Successfully registered enricher 'ParseDate'"
time="2024-02-26T18:45:48Z" level=info msg="Successfully registered enricher 'UnmarshalJSON'"
time="2024-02-26T18:45:48Z" level=info msg="Loading parsers from 10 files"
time="2024-02-26T18:45:48Z" level=info msg="Loaded 1 parser nodes" file=/etc/crowdsec/parsers/s00-raw/cri-logs.yaml stage=s00-raw
time="2024-02-26T18:45:48Z" level=info msg="Loaded 1 parser nodes" file=/etc/crowdsec/parsers/s00-raw/docker-logs.yaml stage=s00-raw
time="2024-02-26T18:45:48Z" level=info msg="Loaded 2 parser nodes" file=/etc/crowdsec/parsers/s00-raw/syslog-logs.yaml stage=s00-raw
time="2024-02-26T18:45:48Z" level=info msg="Loaded 1 parser nodes" file=/etc/crowdsec/parsers/s01-parse/appsec-logs.yaml stage=s01-parse
time="2024-02-26T18:45:48Z" level=info msg="Loaded 1 parser nodes" file=/etc/crowdsec/parsers/s01-parse/sshd-logs.yaml stage=s01-parse
time="2024-02-26T18:45:48Z" level=info msg="Loaded 1 parser nodes" file=/etc/crowdsec/parsers/s01-parse/traefik-logs.yaml stage=s01-parse
time="2024-02-26T18:45:48Z" level=info msg="Loaded 1 parser nodes" file=/etc/crowdsec/parsers/s02-enrich/dateparse-enrich.yaml stage=s02-enrich
time="2024-02-26T18:45:48Z" level=info msg="Loaded 1 parser nodes" file=/etc/crowdsec/parsers/s02-enrich/geoip-enrich.yaml stage=s02-enrich
time="2024-02-26T18:45:48Z" level=info msg="Loaded 1 parser nodes" file=/etc/crowdsec/parsers/s02-enrich/http-logs.yaml stage=s02-enrich
time="2024-02-26T18:45:48Z" level=info msg="Loaded 1 parser nodes" file=/etc/crowdsec/parsers/s02-enrich/whitelists.yaml stage=s02-enrich
time="2024-02-26T18:45:48Z" level=info msg="Loaded 11 nodes from 3 stages"
time="2024-02-26T18:45:48Z" level=info msg="No postoverflow parsers to load"
time="2024-02-26T18:45:48Z" level=info msg="Loading 41 scenario files"
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=aged-breeze name=crowdsecurity/CVE-2022-46169-bf
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=muddy-moon name=crowdsecurity/CVE-2022-46169-cmd
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=lively-moon name=crowdsecurity/jira_cve-2021-26086
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=small-forest name=crowdsecurity/ssh-bf
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=shy-waterfall name=crowdsecurity/ssh-bf_user-enum
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=wispy-shape name=crowdsecurity/CVE-2022-44877
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=cold-voice name=ltsich/http-w00tw00t
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=cool-silence name=crowdsecurity/http-backdoors-attempts
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=lingering-field name=crowdsecurity/CVE-2023-22515
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=ancient-voice name=crowdsecurity/apache_log4j2_cve-2021-44228
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=divine-resonance name=crowdsecurity/CVE-2022-35914
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=quiet-sea name=crowdsecurity/http-cve-2021-41773
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=morning-wood name=crowdsecurity/http-xss-probbing
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=green-surf name=crowdsecurity/thinkphp-cve-2018-20062
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=autumn-frog name=crowdsecurity/pulse-secure-sslvpn-cve-2019-11510
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=delicate-silence name=crowdsecurity/CVE-2022-42889
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=billowing-butterfly name=crowdsecurity/http-crawl-non_statics
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=misty-night name=crowdsecurity/grafana-cve-2021-43798
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=long-wood name=crowdsecurity/http-admin-interface-probing
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=dark-voice name=crowdsecurity/http-cve-2021-42013
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=morning-pond name=crowdsecurity/fortinet-cve-2022-40684
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=late-wildflower name=crowdsecurity/CVE-2022-41082
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=purple-wildflower name=crowdsecurity/vmware-vcenter-vmsa-2021-0027
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=long-firefly name=crowdsecurity/f5-big-ip-cve-2020-5902
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=wandering-sun name=crowdsecurity/vmware-cve-2022-22954
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=nameless-frog name=crowdsecurity/ssh-slow-bf
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=cool-snow name=crowdsecurity/ssh-slow-bf_user-enum
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=wispy-field name=crowdsecurity/appsec-vpatch
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=twilight-rain name=crowdsecurity/http-open-proxy
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=little-sunset name=crowdsecurity/CVE-2022-26134
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=damp-wave name=crowdsecurity/http-bad-user-agent
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=floral-frost name=crowdsecurity/CVE-2023-49103
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=aged-fog name=crowdsecurity/CVE-2023-22518
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=crimson-grass name=crowdsecurity/http-sqli-probbing-detection
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=white-fire name=crowdsecurity/CVE-2019-18935
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=wispy-wave name=crowdsecurity/http-path-traversal-probing
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=billowing-moon name=crowdsecurity/netgear_rce
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=lingering-dew name=crowdsecurity/CVE-2022-41697
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=dry-wind name=crowdsecurity/http-generic-bf
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=young-cloud name=LePresidente/http-generic-401-bf
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=misty-hill name=LePresidente/http-generic-403-bf
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=morning-thunder name=crowdsecurity/fortinet-cve-2018-13379
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=lingering-river name=crowdsecurity/http-probing
time="2024-02-26T18:45:48Z" level=info msg="Adding leaky bucket" cfg=silent-water name=crowdsecurity/http-sensitive-files
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=muddy-glitter name=crowdsecurity/spring4shell_cve-2022-22965
time="2024-02-26T18:45:48Z" level=info msg="Adding trigger bucket" cfg=blue-grass name=crowdsecurity/CVE-2022-37042
time="2024-02-26T18:45:48Z" level=info msg="Loaded 46 scenarios"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2020-11738 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2022-22965 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-20198 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-24489 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-46805 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-28121 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-38205 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-42793 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-33617 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-6553 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/base-config to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2019-12989 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2022-27926 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2022-44877 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-1389 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2018-1000861 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2021-3129 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-49070 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-50164 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2022-35914 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-env-access to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2017-9841 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2022-46169 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2018-10562 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2020-17496 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-23752 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-34362 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-7028 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-40044 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-laravel-debug-mode to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2019-1003030 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2021-22941 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-22515 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="Adding crowdsecurity/vpatch-CVE-2023-3519 to appsec rules"
time="2024-02-26T18:45:48Z" level=info msg="loading acquisition file : /etc/crowdsec/acquis.yaml"
time="2024-02-26T18:45:48Z" level=warning msg="No matching files for pattern /var/log/traefik/access.log" type=file
time="2024-02-26T18:45:48Z" level=info msg="Cache duration for auth not set, using default: 1m0s" name=myAppSecComponent type=appsec
time="2024-02-26T18:45:48Z" level=info msg="loading /etc/crowdsec/appsec-configs/virtual-patching.yaml" component=appsec_config name=myAppSecComponent type=appsec
time="2024-02-26T18:45:48Z" level=info msg="Loaded 0 outofband rules" component=appsec_config name=crowdsecurity/virtual-patching type=appsec
time="2024-02-26T18:45:48Z" level=info msg="loading inband rule crowdsecurity/base-config" component=appsec_config name=crowdsecurity/virtual-patching type=appsec
time="2024-02-26T18:45:48Z" level=info msg="loading inband rule crowdsecurity/vpatch-*" component=appsec_config name=crowdsecurity/virtual-patching type=appsec
time="2024-02-26T18:45:48Z" level=info msg="Loaded 34 inband rules" component=appsec_config name=crowdsecurity/virtual-patching type=appsec
time="2024-02-26T18:45:48Z" level=info msg="Created 1 appsec runners" name=myAppSecComponent type=appsec
time="2024-02-26T18:45:48Z" level=info msg="Starting processing data"
time="2024-02-26T18:45:48Z" level=info msg="1 appsec runner to start" name=myAppSecComponent type=appsec
time="2024-02-26T18:45:48Z" level=info msg="Starting Appsec server on 0.0.0.0:7422/" name=myAppSecComponent type=appsec
time="2024-02-26T18:45:48Z" level=info msg="Appsec Runner ready to process event" name=myAppSecComponent runner_uuid=ffc18710-8e90-44eb-b4fe-6f2d52576292 type=appsec
time="2024-02-26T18:45:49Z" level=info msg="127.0.0.1 - [Mon, 26 Feb 2024 18:45:49 UTC] \"POST /v1/watchers/login HTTP/1.1 200 56.482118ms \"crowdsec/v1.5.6-rc12-4b8e6cd7\" \""
time="2024-02-26T18:45:49Z" level=info msg="Starting community-blocklist update"
time="2024-02-26T18:45:49Z" level=info msg="capi/community-blocklist : 0 explicit deletions"
time="2024-02-26T18:45:49Z" level=info msg="capi/community-blocklist : received 0 new entries (expected if you just installed crowdsec)"
time="2024-02-26T18:45:49Z" level=info msg="Start pull from CrowdSec Central API (interval: 1h59m5s once, then 2h0m0s)"
time="2024-02-26T18:45:59Z" level=info msg="172.18.0.2 - [Mon, 26 Feb 2024 18:45:59 UTC] \"GET /v1/decisions?ip=172.18.0.1&banned=true HTTP/1.1 200 10.638491ms \"Go-http-client/1.1\" \""
time="2024-02-26T19:32:27Z" level=info msg="127.0.0.1 - [Mon, 26 Feb 2024 19:32:27 UTC] \"GET /v1/heartbeat HTTP/1.1 200 8.312477ms \"crowdsec/v1.5.6-rc12-4b8e6cd7\" \""
time="2024-02-26T19:33:27Z" level=info msg="127.0.0.1 - [Mon, 26 Feb 2024 19:33:27 UTC] \"GET /v1/heartbeat HTTP/1.1 200 8.412648ms \"crowdsec/v1.5.6-rc12-4b8e6cd7\" \""
time="2024-02-26T19:34:27Z" level=info msg="127.0.0.1 - [Mon, 26 Feb 2024 19:34:27 UTC] \"GET /v1/heartbeat HTTP/1.1 200 8.229106ms \"crowdsec/v1.5.6-rc12-4b8e6cd7\" \""
time="2024-02-26T19:35:27Z" level=info msg="127.0.0.1 - [Mon, 26 Feb 2024 19:35:27 UTC] \"GET /v1/heartbeat HTTP/1.1 200 8.143741ms \"crowdsec/v1.5.6-rc12-4b8e6cd7\" \""
time="2024-02-26T19:36:27Z" level=info msg="127.0.0.1 - [Mon, 26 Feb 2024 19:36:27 UTC] \"GET /v1/heartbeat HTTP/1.1 200 8.283622ms \"crowdsec/v1.5.6-rc12-4b8e6cd7\" \""
time="2024-02-26T19:37:27Z" level=info msg="127.0.0.1 - [Mon, 26 Feb 2024 19:37:27 UTC] \"GET /v1/heartbeat HTTP/1.1 200 2.564351ms \"crowdsec/v1.5.6-rc12-4b8e6cd7\" \""
time="2024-02-26T19:38:27Z" level=info msg="127.0.0.1 - [Mon, 26 Feb 2024 19:38:27 UTC] \"GET /v1/heartbeat HTTP/1.1 200 8.213716ms \"crowdsec/v1.5.6-rc12-4b8e6cd7\" \""
time="2024-02-26T19:39:27Z" level=info msg="127.0.0.1 - [Mon, 26 Feb 2024 19:39:27 UTC] \"GET /v1/heartbeat HTTP/1.1 200 8.007346ms \"crowdsec/v1.5.6-rc12-4b8e6cd7\" \""
time="2024-02-26T19:40:27Z" level=info msg="127.0.0.1 - [Mon, 26 Feb 2024 19:40:27 UTC] \"GET /v1/heartbeat HTTP/1.1 200 8.728651ms \"crowdsec/v1.5.6-rc12-4b8e6cd7\" \""

Please tell us if that work for you and if not could you add log files for traefik and crowdsec.

Best,

@luckylinux
Copy link
Author

Hi @mathieuHa . Thank you for your quick reply. I hope I can try it tomorrow in the morning.

What is acquis.yml though ? And where should I place it exactly ? I don't see it referenced in the compose.yml files.

@mathieuHa
Copy link
Collaborator

Hi @mathieuHa . Thank you for your quick reply. I hope I can try it tomorrow in the morning.

What is acquis.yml though ? And where should I place it exactly ? I don't see it referenced in the compose.yml files.

Hey,

It's used by Crowdsec in the docker-compose as a file mounted for basic configuration to enable traefik log parsing and appsec enablement like this:

 crowdsec:
    image: crowdsecurity/crowdsec:v1.6.0
    container_name: "crowdsec"
    hostname: crowdsec
    restart: unless-stopped
    environment:
      COLLECTIONS: crowdsecurity/traefik crowdsecurity/appsec-virtual-patching
      CUSTOM_HOSTNAME: crowdsec
      # We need to register one api key per service we will use
      BOUNCER_KEY_test: XXXXXXXXXXXXXXXXXXXXXXX
    volumes:
      - ./acquis.yaml:/etc/crowdsec/acquis.yaml:ro
      - logs:/var/log/traefik:ro
    labels:
      - "traefik.enable=false"
    networks:
      - traefik

@mathieuHa
Copy link
Collaborator

mathieuHa commented Feb 26, 2024

Just for context, in Traefik logs:

DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:22 ServeHTTP:handleNoStreamCache ip:172.18.0.1 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=172.18.0.1&banned=true, statusCode:403
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:24 ServeHTTP ip:172.18.0.1 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:24 cache:GetDecision ip:172.18.0.1
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:24 ServeHTTP:getDecision ip:172.18.0.1 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:44:24 ServeHTTP:handleNoStreamCache ip:172.18.0.1 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=172.18.0.1&banned=true, statusCode:403
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:45:59 ServeHTTP ip:172.18.0.1 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:45:59 cache:GetDecision ip:172.18.0.1
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:45:59 ServeHTTP:getDecision ip:172.18.0.1 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/26 18:45:59 cache:SetDecision ip:172.18.0.1 isBanned:false duration:60s

At first I had a 403 between traefik and crowdsec because my configuration had a wrong token, but then I fixed and checked it so last part of log shows working request.

@luckylinux
Copy link
Author

OK super, I'll check tomorrow 馃憤 .

I'm still a bit skeptical about the part of configuring the middleware in each container instead as part of traefik dynamic configuration. Something doesn't feel right there. Like if I have 10 containers that need to use crowdsec I would need to configure 10 middleware all with the same settings in 10 different files.

That's why I thought that defining it once in the (dynamic) traefik config would have been enough.

But maybe I miss something ...

@luckylinux
Copy link
Author

luckylinux commented Feb 27, 2024

I gave it a try ... I am also a bit confused about the part

# We need to register one api key per service we will use
      BOUNCER_KEY_test

per service ? I thought BOUNCER_KEY_TRAEFIK was a "reserved name".

podman logs traefik-basic-example gives:

time="2024-02-27T06:23:26Z" level=info msg="Configuration loaded from flags."
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 No IP provided for ForwardedHeadersTrustedIPs
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 No IP provided for ClientTrustedIPs
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 getTLSConfigCrowdsec:CrowdsecLapiScheme https:no
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 cache:New initialized isRedis:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 New initialized mode:live
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 No IP provided for ForwardedHeadersTrustedIPs
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 No IP provided for ClientTrustedIPs
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 getTLSConfigCrowdsec:CrowdsecLapiScheme https:no
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 cache:New initialized isRedis:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 New initialized mode:live
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:24:41 ServeHTTP ip:10.89.0.16 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:24:41 cache:GetDecision ip:10.89.0.16
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:24:41 ServeHTTP:getDecision ip:10.89.0.16 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:24:41 ServeHTTP:handleNoStreamCache ip:10.89.0.16 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true Get "http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true": dial tcp 10.89.0.18:8080: connect: connection refused

podman logs crowdsec gives:
crowdsec.log

Not sure, but at least looking at the traefik logs, it seems to load it ?

I cannot access through localhost as this is hosted through a VPS, I had to access through xx.MYDOMAIN.TLD/foo.
Not sure if that causes some differences ?

From within the VPS I tried to run curl -s -o /dev/null -I -w "%{http_code}" http://localhost/foo and I get 403 (forbidden).

After trying with CURL from within the VPS I get a bit different result (isBanned: false).

time="2024-02-27T06:23:26Z" level=info msg="Configuration loaded from flags."
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 No IP provided for ForwardedHeadersTrustedIPs
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 No IP provided for ClientTrustedIPs
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 getTLSConfigCrowdsec:CrowdsecLapiScheme https:no
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 cache:New initialized isRedis:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 New initialized mode:live
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 No IP provided for ForwardedHeadersTrustedIPs
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 No IP provided for ClientTrustedIPs
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 getTLSConfigCrowdsec:CrowdsecLapiScheme https:no
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 cache:New initialized isRedis:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:23:33 New initialized mode:live
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:24:41 ServeHTTP ip:10.89.0.16 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:24:41 cache:GetDecision ip:10.89.0.16
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:24:41 ServeHTTP:getDecision ip:10.89.0.16 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:24:41 ServeHTTP:handleNoStreamCache ip:10.89.0.16 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true Get "http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true": dial tcp 10.89.0.18:8080: connect: connection refused
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:14 ServeHTTP ip:10.89.0.16 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:14 cache:GetDecision ip:10.89.0.16
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:14 ServeHTTP:getDecision ip:10.89.0.16 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:14 ServeHTTP:handleNoStreamCache ip:10.89.0.16 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true Get "http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true": dial tcp 10.89.0.18:8080: connect: connection refused
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:55 ServeHTTP ip:10.89.0.16 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:55 cache:GetDecision ip:10.89.0.16
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:55 ServeHTTP:getDecision ip:10.89.0.16 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:55 ServeHTTP:handleNoStreamCache ip:10.89.0.16 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true Get "http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true": dial tcp 10.89.0.18:8080: connect: connection refused
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:58 ServeHTTP ip:10.89.0.16 isTrusted:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:58 cache:GetDecision ip:10.89.0.16
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:58 ServeHTTP:getDecision ip:10.89.0.16 isBanned:false cache:miss
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:27:58 ServeHTTP:handleNoStreamCache ip:10.89.0.16 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true Get "http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true": dial tcp 10.89.0.18:8080: connect: connection refused

@mathieuHa
Copy link
Collaborator

OK super, I'll check tomorrow 馃憤 .

I'm still a bit skeptical about the part of configuring the middleware in each container instead as part of traefik dynamic configuration. Something doesn't feel right there. Like if I have 10 containers that need to use crowdsec I would need to configure 10 middleware all with the same settings in 10 different files.

That's why I thought that defining it once in the (dynamic) traefik config would have been enough.

But maybe I miss something ...

You're absolutely right.
The middleware should be defined only once in the dynamic configuration.
I even think declaring some parameters multiple time for the same middleware name and different argument would be overwritten depending on the order it's loaded.

Note that declaring multiple middleware crowdsec with different names and configuration is also not supported by this plugin as mentionned here:
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin?tab=readme-ov-file#note

I believe it's better to declare it outside of a service so you can use it in multiple services without confusion.

I'll adapt the docker-compose from my comment tonight with this addition

@mathieuHa
Copy link
Collaborator

I gave it a try ... I am also a bit confused about the part

# We need to register one api key per service we will use
      BOUNCER_KEY_test

You can see in the entrypoint of Crowdsec container https://github.com/crowdsecurity/crowdsec/blob/8e9e091656f2a72a37e21c173ed0c2015e97e726/docker/docker_start.sh#L387 or in the dockerhub README if you prefer
that we can use any name after CROWDSEC_BOUNCER_*

image

From this log:
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/02/27 06:24:41 ServeHTTP:handleNoStreamCache ip:10.89.0.16 isBanned:true crowdsecQuery url:http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true Get "http://crowdsec:8080/v1/decisions?ip=10.89.0.16&banned=true": dial tcp 10.89.0.18:8080: connect: connection refused
We see that the plugin did started but it has trouble reaching Crowdsec container.
Many things can happen here:

  • DNS resolution (seems ok since it resolved the IP)
  • networking (are both container in the traefik network ?) use docker inspect to see the ip of each container

@mathieuHa
Copy link
Collaborator

From within the VPS I tried to run curl -s -o /dev/null -I -w "%{http_code}" http://localhost/foo and I get 403 (forbidden).

This is normal when the plugin cannot reach crowdsec as a security mesure everything is blocked (configurable with a configuration var in the plugin)

@mathieuHa
Copy link
Collaborator

mathieuHa commented Feb 27, 2024

OKay I see from your crowdsec logs

time="2024-02-27T06:23:49Z" level=info msg="loading acquisition file : /etc/crowdsec/acquis.yaml"
time="2024-02-27T06:23:49Z" level=fatal msg="crowdsec init: while loading acquisition config: failed to yaml decode /etc/crowdsec/acquis.yaml: yaml: input error: read /etc/crowdsec/acquis.yaml: is a directory"

Crowdsec is crashing and restarting so that cannot help Traefik contact him

Here the problem is the mounting option, podman attach aquis.yaml as a directory and not only the file.
It is pretty common issue but i'm not an expert on podman.
In docker using ./filename :

  volumes:
      - ./acquis.yaml:/etc/crowdsec/acquis.yaml:ro

is enough, but you might create a directory crowdsec and add the file in it and then bind mount the folder

I'll let you read some info on others ways to override conf in Crowdsec doc: https://docs.crowdsec.net/docs/configuration/crowdsec_configuration/#overriding-values

@mathieuHa
Copy link
Collaborator

mathieuHa commented Feb 27, 2024

I believe it's better to declare it outside of a service so you can use it in multiple services without confusion.

I'll adapt the docker-compose from my comment tonight with this addition

I just checked and the conf I proposed in the previous comments was already independent from any services and thus can be used in any service.

Example like this foo and bar whoami.

http:
  routers:
    my-router-foo:
      rule: PathPrefix(`/foo`)
      service: service-foo
      entryPoints:
        - web
      middlewares:
        - crowdsec
        
    my-router-bar:
      rule: PathPrefix(`/bar`)
      service: service-bar
      entryPoints:
        - web
      middlewares:
        - crowdsec

  services:
    service-bar:
      loadBalancer:
        servers:
          - url: http://172.18.0.4:80
    service-foo:
      loadBalancer:
        servers:
          - url: http://172.18.0.3:80
   
 

We need to register one api key per service we will use

This is a something that should have disapeared a long time ago, as it is not true.
I will update the documentation accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants