2.4 KiB
Fix CrowdSec Persistence & Offline Status
Goal Description
The CrowdSec Security Engine is reported as "Offline" on the dashboard. This is caused by the lack of data persistence in the Docker container.
The docker-entrypoint.sh and Dockerfile currently configure CrowdSec to use ephemeral paths (/etc/crowdsec and /var/lib/crowdsec/data) which are not linked to the persistent volume /app/data/crowdsec.
Consequently, every container restart generates a new Machine ID and loses enrollment credentials, causing the dashboard to see the old instance as offline.
User Review Required
Important
Re-Enrollment Required: After this fix is applied, the user will need to re-enroll their instance once. The new identity will persist across future restarts. Mode Configuration: The user must ensure
CERBERUS_SECURITY_CROWDSEC_MODEis set tolocalin their environment ordocker-compose.yml.
Proposed Changes
Docker & Scripts
[MODIFY] docker-entrypoint.sh
- Update CrowdSec initialization logic to map runtime directories to persistence:
- Check for
/app/data/crowdsec/configand/app/data/crowdsec/data. - If missing, populate from
/etc/crowdsec(defaults). - Use symbolic links or environment variables (
DATA) to point to/app/data/crowdsec/.... - Ensure
csclicommands operate on the persistent configuration.
- Check for
[MODIFY] docker-compose.yml
- Update comments to explicitly recommend setting
CERBERUS_SECURITY_CROWDSEC_MODE=localto avoid confusion.
Verification Plan
Manual Verification
-
Persistence Test:
- Deploy the updated container.
- Enter container:
docker exec -it charon sh. - Run
cscli machines listand note the Machine ID. - Modify a file in
/etc/crowdsec(e.g.,touch /etc/crowdsec/test_persist). - Restart container:
docker restart charon. - Enter container again.
- Verify
cscli machines listshows the SAME Machine ID. - Verify
/etc/crowdsec/test_persiststill exists.
-
Online Enrollment Test:
- Enroll the instance:
cscli console enroll <enroll-key>. - Restart container.
- Check
cscli console status(if available) or verify on Dashboard that it remains "Online".
- Enroll the instance:
Automated Tests
- None (requires Docker runtime test, which is manual in this context).