|
| 1 | +# CrowdSec HAProxy SPOA Bouncer Docker Image |
| 2 | + |
| 3 | +This is a minimal scratch-based Docker image containing only the statically-linked bouncer binary and essential files. |
| 4 | + |
| 5 | +## Image Contents |
| 6 | + |
| 7 | +``` |
| 8 | +/crowdsec-spoa-bouncer # The bouncer binary |
| 9 | +/etc/ssl/certs/ca-certificates.crt # CA certs for HTTPS to LAPI |
| 10 | +/etc/crowdsec/bouncers/crowdsec-spoa-bouncer.yaml # Default config |
| 11 | +/usr/lib/crowdsec-haproxy-spoa-bouncer/lua/ # Lua files for HAProxy |
| 12 | +/var/lib/crowdsec-haproxy-spoa-bouncer/html/ # Ban/captcha templates |
| 13 | +``` |
| 14 | + |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +```bash |
| 18 | +docker run -d \ |
| 19 | + --name crowdsec-spoa-bouncer \ |
| 20 | + -e API_KEY=your-api-key \ |
| 21 | + -p 9000:9000 \ |
| 22 | + crowdsec/haproxy-spoa-bouncer |
| 23 | +``` |
| 24 | + |
| 25 | +## Configuration |
| 26 | + |
| 27 | +### Environment Variables |
| 28 | + |
| 29 | +The default config supports environment variable substitution for `API_KEY`. For other settings, mount a custom config file. |
| 30 | + |
| 31 | +### Custom Configuration |
| 32 | + |
| 33 | +```bash |
| 34 | +docker run -d \ |
| 35 | + --name crowdsec-spoa-bouncer \ |
| 36 | + -v /path/to/your/config.yaml:/etc/crowdsec/bouncers/crowdsec-spoa-bouncer.yaml:ro \ |
| 37 | + -p 9000:9000 \ |
| 38 | + crowdsec/haproxy-spoa-bouncer |
| 39 | +``` |
| 40 | + |
| 41 | +Or specify a different config path: |
| 42 | + |
| 43 | +```bash |
| 44 | +docker run -d \ |
| 45 | + --name crowdsec-spoa-bouncer \ |
| 46 | + -v /path/to/config.yaml:/config.yaml:ro \ |
| 47 | + -p 9000:9000 \ |
| 48 | + crowdsec/haproxy-spoa-bouncer -c /config.yaml |
| 49 | +``` |
| 50 | + |
| 51 | +### Unix Socket (Recommended for Same-Host HAProxy) |
| 52 | + |
| 53 | +```bash |
| 54 | +docker run -d \ |
| 55 | + --name crowdsec-spoa-bouncer \ |
| 56 | + -v /path/to/config.yaml:/etc/crowdsec/bouncers/crowdsec-spoa-bouncer.yaml:ro \ |
| 57 | + -v /run/crowdsec-spoa:/run/crowdsec-spoa \ |
| 58 | + crowdsec/haproxy-spoa-bouncer |
| 59 | +``` |
| 60 | + |
| 61 | +Ensure the socket directory exists and has appropriate permissions for HAProxy to connect. |
| 62 | + |
| 63 | +## Docker Compose Example |
| 64 | + |
| 65 | +```yaml |
| 66 | +services: |
| 67 | + crowdsec-spoa-bouncer: |
| 68 | + image: crowdsec/haproxy-spoa-bouncer |
| 69 | + restart: unless-stopped |
| 70 | + environment: |
| 71 | + - API_KEY=${CROWDSEC_API_KEY} |
| 72 | + volumes: |
| 73 | + - ./config/crowdsec-spoa-bouncer.yaml:/etc/crowdsec/bouncers/crowdsec-spoa-bouncer.yaml:ro |
| 74 | + - spoa-socket:/run/crowdsec-spoa |
| 75 | + # Optional: resource limits |
| 76 | + deploy: |
| 77 | + resources: |
| 78 | + limits: |
| 79 | + memory: 256M |
| 80 | + # Optional: set GOMEMLIMIT for better memory management |
| 81 | + # environment: |
| 82 | + # - GOMEMLIMIT=200MiB |
| 83 | + |
| 84 | + haproxy: |
| 85 | + image: haproxy:latest |
| 86 | + volumes: |
| 87 | + - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro |
| 88 | + - spoa-socket:/run/crowdsec-spoa |
| 89 | + ports: |
| 90 | + - "80:80" |
| 91 | + - "443:443" |
| 92 | + depends_on: |
| 93 | + - crowdsec-spoa-bouncer |
| 94 | + |
| 95 | +volumes: |
| 96 | + spoa-socket: |
| 97 | +``` |
| 98 | +
|
| 99 | +## Running as Non-Root |
| 100 | +
|
| 101 | +The scratch image runs as root by default. To run as a specific user: |
| 102 | +
|
| 103 | +```bash |
| 104 | +docker run -d \ |
| 105 | + --user 1000:1000 \ |
| 106 | + --name crowdsec-spoa-bouncer \ |
| 107 | + -p 9000:9000 \ |
| 108 | + crowdsec/haproxy-spoa-bouncer |
| 109 | +``` |
| 110 | + |
| 111 | +Note: Ensure mounted volumes have appropriate permissions for the specified user. |
| 112 | + |
| 113 | +## Health Checks |
| 114 | + |
| 115 | +The bouncer exposes Prometheus metrics when enabled in config: |
| 116 | + |
| 117 | +```yaml |
| 118 | +prometheus: |
| 119 | + enabled: true |
| 120 | + listen_addr: 0.0.0.0 |
| 121 | + listen_port: 60601 |
| 122 | +``` |
| 123 | +
|
| 124 | +Then use for health checks: |
| 125 | +
|
| 126 | +```bash |
| 127 | +docker run -d \ |
| 128 | + --name crowdsec-spoa-bouncer \ |
| 129 | + --health-cmd="wget -q --spider http://localhost:60601/metrics || exit 1" \ |
| 130 | + --health-interval=30s \ |
| 131 | + -p 9000:9000 \ |
| 132 | + -p 60601:60601 \ |
| 133 | + crowdsec/haproxy-spoa-bouncer |
| 134 | +``` |
| 135 | + |
| 136 | +Note: Since this is a scratch image, `wget` is not available. Use an external health check or a sidecar container for HTTP health probes. |
| 137 | + |
| 138 | +## Ports |
| 139 | + |
| 140 | +| Port | Description | |
| 141 | +|------|-------------| |
| 142 | +| 9000 | SPOA TCP listener (default) | |
| 143 | +| 60601 | Prometheus metrics (when enabled) | |
| 144 | +| 6060 | pprof debug endpoint (when enabled) | |
| 145 | + |
| 146 | +## Troubleshooting |
| 147 | + |
| 148 | +### View Logs |
| 149 | + |
| 150 | +```bash |
| 151 | +docker logs -f crowdsec-spoa-bouncer |
| 152 | +``` |
| 153 | + |
| 154 | +### Debug Mode |
| 155 | + |
| 156 | +Set `log_level: debug` in your config file for verbose logging. |
| 157 | + |
| 158 | +### Connection Issues |
| 159 | + |
| 160 | +1. Verify LAPI is reachable from the container |
| 161 | +2. Check API key is correct |
| 162 | +3. Ensure HAProxy can reach the SPOA listener (TCP port or Unix socket) |
| 163 | + |
| 164 | +## Building the Image |
| 165 | + |
| 166 | +```bash |
| 167 | +docker build -t crowdsec/haproxy-spoa-bouncer . |
| 168 | +``` |
| 169 | + |
| 170 | +### Build Arguments |
| 171 | + |
| 172 | +| Argument | Default | Description | |
| 173 | +|----------|---------|-------------| |
| 174 | +| GOVERSION | 1.25 | Go version for build stage | |
| 175 | + |
0 commit comments