Skip to content

Commit b0a4e24

Browse files
feat: add Docker-optimized config with environment variables
- Add config/crowdsec-spoa-bouncer.docker.yaml with stdout logging - Support env vars: CROWDSEC_KEY, CROWDSEC_URL, LOG_LEVEL, etc. - Enable Prometheus by default on port 6060 - Update Dockerfile to use Docker config and expose both ports - Update README with comprehensive environment variables table
1 parent 5e2ea3e commit b0a4e24

File tree

3 files changed

+103
-37
lines changed

3 files changed

+103
-37
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2222
# Copy the static binary
2323
COPY --from=build /go/src/cs-spoa-bouncer/crowdsec-spoa-bouncer /crowdsec-spoa-bouncer
2424

25-
# Copy default config file
26-
COPY --from=build /go/src/cs-spoa-bouncer/config/crowdsec-spoa-bouncer.yaml /etc/crowdsec/bouncers/crowdsec-spoa-bouncer.yaml
25+
# Copy Docker-optimized config file
26+
COPY --from=build /go/src/cs-spoa-bouncer/config/crowdsec-spoa-bouncer.docker.yaml /etc/crowdsec/bouncers/crowdsec-spoa-bouncer.yaml
2727

2828
# Copy Lua files for HAProxy integration
2929
COPY --from=build /go/src/cs-spoa-bouncer/lua/ /usr/lib/crowdsec-haproxy-spoa-bouncer/lua/
@@ -35,7 +35,7 @@ COPY --from=build /go/src/cs-spoa-bouncer/templates/ /var/lib/crowdsec-haproxy-s
3535
COPY --from=build /run/crowdsec-spoa/ /run/crowdsec-spoa/
3636
COPY --from=build /var/log/crowdsec-spoa/ /var/log/crowdsec-spoa/
3737

38-
EXPOSE 9000
38+
EXPOSE 9000 6060
3939

4040
ENTRYPOINT ["/crowdsec-spoa-bouncer"]
4141
CMD ["-c", "/etc/crowdsec/bouncers/crowdsec-spoa-bouncer.yaml"]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## Docker-optimized configuration for CrowdSec SPOA Bouncer
2+
## Environment variables can be used for configuration: ${VAR_NAME}
3+
4+
## Log configuration
5+
## stdout is recommended for Docker (use `docker logs` to view)
6+
log_mode: ${LOG_MODE:-stdout}
7+
log_level: ${LOG_LEVEL:-info}
8+
9+
## LAPI configuration
10+
api_url: ${CROWDSEC_URL:-http://crowdsec:8080/}
11+
api_key: ${CROWDSEC_KEY}
12+
update_frequency: ${UPDATE_FREQUENCY:-10s}
13+
insecure_skip_verify: ${INSECURE_SKIP_VERIFY:-false}
14+
15+
## SPOA listener configuration
16+
## TCP listener - recommended for Docker networking
17+
listen_tcp: ${LISTEN_TCP:-0.0.0.0:9000}
18+
## Unix socket - uncomment if using shared volume with HAProxy
19+
#listen_unix: ${LISTEN_UNIX:-/run/crowdsec-spoa/spoa.sock}
20+
21+
## GeoIP databases (optional, mount as volumes)
22+
#asn_database_path: ${ASN_DB_PATH:-/var/lib/crowdsec/data/GeoLite2-ASN.mmdb}
23+
#city_database_path: ${CITY_DB_PATH:-/var/lib/crowdsec/data/GeoLite2-City.mmdb}
24+
25+
## Global AppSec configuration (optional)
26+
#appsec_url: ${APPSEC_URL}
27+
#appsec_timeout: ${APPSEC_TIMEOUT:-200ms}
28+
29+
## Prometheus metrics endpoint
30+
prometheus:
31+
enabled: ${PROMETHEUS_ENABLED:-true}
32+
listen_addr: ${PROMETHEUS_ADDR:-0.0.0.0}
33+
listen_port: ${PROMETHEUS_PORT:-6060}
34+
35+
## pprof debug endpoint (disabled by default)
36+
## WARNING: Only enable for debugging, exposes internal runtime data
37+
#pprof:
38+
# enabled: ${PPROF_ENABLED:-false}
39+
# listen_addr: ${PPROF_ADDR:-0.0.0.0}
40+
# listen_port: ${PPROF_PORT:-6070}
41+

docker/README.md

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,35 @@ This is a minimal scratch-based Docker image containing only the statically-link
1717
```bash
1818
docker run -d \
1919
--name crowdsec-spoa-bouncer \
20-
-e API_KEY=your-api-key \
20+
-e CROWDSEC_KEY=your-api-key \
21+
-e CROWDSEC_URL=http://crowdsec:8080/ \
2122
-p 9000:9000 \
23+
-p 6060:6060 \
2224
crowdsecurity/spoa-bouncer
2325
```
2426

2527
## Configuration
2628

2729
### Environment Variables
2830

29-
The default config supports environment variable substitution for `API_KEY`. For other settings, mount a custom config file.
31+
The Docker image uses a configuration file optimized for containers with extensive environment variable support:
32+
33+
| Variable | Default | Description |
34+
|----------|---------|-------------|
35+
| `CROWDSEC_KEY` | *(required)* | API key for CrowdSec LAPI |
36+
| `CROWDSEC_URL` | `http://crowdsec:8080/` | CrowdSec LAPI URL |
37+
| `LOG_MODE` | `stdout` | Log output: `stdout` or `file` |
38+
| `LOG_LEVEL` | `info` | Log level: `trace`, `debug`, `info`, `warn`, `error` |
39+
| `UPDATE_FREQUENCY` | `10s` | How often to poll LAPI for decisions |
40+
| `INSECURE_SKIP_VERIFY` | `false` | Skip TLS verification for LAPI |
41+
| `LISTEN_TCP` | `0.0.0.0:9000` | TCP listener address |
42+
| `LISTEN_UNIX` | *(disabled)* | Unix socket path (uncomment in config) |
43+
| `PROMETHEUS_ENABLED` | `true` | Enable Prometheus metrics |
44+
| `PROMETHEUS_ADDR` | `0.0.0.0` | Prometheus listen address |
45+
| `PROMETHEUS_PORT` | `6060` | Prometheus listen port |
46+
| `APPSEC_URL` | *(disabled)* | AppSec endpoint URL |
47+
| `APPSEC_TIMEOUT` | `200ms` | AppSec request timeout |
48+
| `GOMEMLIMIT` | *(unset)* | Go memory limit (e.g., `200MiB`) |
3049

3150
### Custom Configuration
3251

@@ -68,32 +87,33 @@ services:
6887
image: crowdsecurity/spoa-bouncer
6988
restart: unless-stopped
7089
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
90+
- CROWDSEC_KEY=${CROWDSEC_API_KEY}
91+
- CROWDSEC_URL=http://crowdsec:8080/
92+
- LOG_LEVEL=info
93+
- GOMEMLIMIT=200MiB
94+
ports:
95+
- "6060:6060" # Prometheus metrics
96+
networks:
97+
- crowdsec
7698
deploy:
7799
resources:
78100
limits:
79101
memory: 256M
80-
# Optional: set GOMEMLIMIT for better memory management
81-
# environment:
82-
# - GOMEMLIMIT=200MiB
83102

84103
haproxy:
85104
image: haproxy:latest
86105
volumes:
87106
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
88-
- spoa-socket:/run/crowdsec-spoa
89107
ports:
90108
- "80:80"
91109
- "443:443"
110+
networks:
111+
- crowdsec
92112
depends_on:
93113
- crowdsec-spoa-bouncer
94114

95-
volumes:
96-
spoa-socket:
115+
networks:
116+
crowdsec:
97117
```
98118
99119
## Running as Non-Root
@@ -112,36 +132,37 @@ Note: Ensure mounted volumes have appropriate permissions for the specified user
112132

113133
## Health Checks
114134

115-
The bouncer exposes Prometheus metrics when enabled in config:
135+
Prometheus metrics are enabled by default on port 6060. Since this is a scratch image with no shell, use external health checks:
116136

117137
```yaml
118-
prometheus:
119-
enabled: true
120-
listen_addr: 0.0.0.0
121-
listen_port: 60601
138+
# Docker Compose with healthcheck via curl sidecar
139+
services:
140+
crowdsec-spoa-bouncer:
141+
image: crowdsecurity/spoa-bouncer
142+
environment:
143+
- CROWDSEC_KEY=${API_KEY}
144+
# Use depends_on with service_healthy for dependent services
145+
146+
healthcheck:
147+
image: curlimages/curl:latest
148+
command: ["sh", "-c", "while true; do curl -sf http://crowdsec-spoa-bouncer:6060/metrics > /dev/null && echo healthy || echo unhealthy; sleep 30; done"]
149+
depends_on:
150+
- crowdsec-spoa-bouncer
122151
```
123152
124-
Then use for health checks:
153+
Or check from the host:
125154
126155
```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-
crowdsecurity/spoa-bouncer
156+
curl -sf http://localhost:6060/metrics > /dev/null && echo "healthy" || echo "unhealthy"
134157
```
135158

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-
138159
## Ports
139160

140-
| Port | Description |
141-
|------|-------------|
142-
| 9000 | SPOA TCP listener (default) |
143-
| 60601 | Prometheus metrics (when enabled) |
144-
| 6060 | pprof debug endpoint (when enabled) |
161+
| Port | Default | Description |
162+
|------|---------|-------------|
163+
| 9000 | Yes | SPOA TCP listener |
164+
| 6060 | Yes | Prometheus metrics (enabled by default) |
165+
| 6070 | No | pprof debug endpoint (disabled by default) |
145166

146167
## Troubleshooting
147168

@@ -153,7 +174,11 @@ docker logs -f crowdsec-spoa-bouncer
153174

154175
### Debug Mode
155176

156-
Set `log_level: debug` in your config file for verbose logging.
177+
Set the `LOG_LEVEL` environment variable:
178+
179+
```bash
180+
docker run -e LOG_LEVEL=debug -e CROWDSEC_KEY=... crowdsecurity/spoa-bouncer
181+
```
157182

158183
### Connection Issues
159184

0 commit comments

Comments
 (0)