CrowdSec Removal Script for pangolin users

CrowdSec Removal Script

This script safely removes CrowdSec from your Pangolin installation by cleaning up all related configurations and restarting the containers.

Supported Operating Systems

  • Ubuntu
  • Debian
  • Rocky Linux
  • RHEL (Red Hat Enterprise Linux)
  • CentOS
  • Fedora

What the script does

  1. Checks and installs dependencies automatically (Python 3, PyYAML, tar)
  2. Backs up all configuration files before making any changes (with timestamps)
  3. Stops all containers before making changes
  4. Removes CrowdSec service from docker-compose.yml
  5. Removes CrowdSec dependency from the Traefik service
  6. Removes CrowdSec plugin from config/traefik/traefik_config.yml
  7. Removes CrowdSec middlewares from config/traefik/dynamic_config.yml
  8. Removes Traefik log volume that was added for CrowdSec
  9. Reverts log format from JSON back to common format
  10. Validates all YAML files to ensure they’re syntactically correct
  11. Removes CrowdSec directories (with backup)
  12. Restarts containers with the updated configuration

Prerequisites

The script will automatically check for and install missing dependencies. If dependencies are missing and the script is not run as root, it will provide the exact commands needed to install them.

Required (automatically installed if missing):

  • Python 3
  • PyYAML (python3-yaml or python3-pyyaml)
  • tar

Container Runtime (you must have one installed):

  • Docker or Podman must already be installed
  • Run from your Pangolin installation directory (where docker-compose.yml is located)

Usage

If dependencies are already installed (or running as root):

wget https://gist.githubusercontent.com/hhftechnology/42308d1cde1cbb691cdf181997db8e0b/raw/b1bb221d3d12d77b584c71ca0039f3583ebd7e82/remove-crowdsec.sh -O remove-crowdsec.sh

# Make the script executable
chmod +x remove-crowdsec.sh

# Run the script from your Pangolin installation directory
./remove-crowdsec.sh

If you need to install dependencies first:

The script will check and attempt to install dependencies automatically. If not running as root, it will tell you exactly what to install:

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install -y python3 python3-yaml tar
./remove-crowdsec.sh

Rocky Linux/RHEL/CentOS/Fedora:

sudo dnf install -y python3 python3-pyyaml tar
./remove-crowdsec.sh

Running with automatic dependency installation (requires root):

# Run as root to allow automatic dependency installation
sudo ./remove-crowdsec.sh

What gets backed up

The script creates timestamped backups of:

  • docker-compose.yml.backup-YYYYMMDD-HHMMSS
  • config/traefik/traefik_config.yml.backup-YYYYMMDD-HHMMSS
  • config/traefik/dynamic_config.yml.backup-YYYYMMDD-HHMMSS
  • config/crowdsec-backup-YYYYMMDD-HHMMSS.tar.gz (entire CrowdSec directory)

Restoring from backup

If something goes wrong, you can restore your configuration:

# Restore docker-compose.yml
cp docker-compose.yml.backup-YYYYMMDD-HHMMSS docker-compose.yml

# Restore traefik configs
cp config/traefik/traefik_config.yml.backup-YYYYMMDD-HHMMSS config/traefik/traefik_config.yml
cp config/traefik/dynamic_config.yml.backup-YYYYMMDD-HHMMSS config/traefik/dynamic_config.yml

# Restore CrowdSec directory
tar -xzf config/crowdsec-backup-YYYYMMDD-HHMMSS.tar.gz

# Restart containers
docker compose down
docker compose up -d

Validation

The script includes YAML validation using:

  1. yamllint (if available)
  2. Python’s yaml module (fallback)

If validation fails, the script will:

  • Show error messages
  • Keep backups intact
  • Exit without starting containers

Troubleshooting

Missing dependencies

Problem: Python 3 or PyYAML not installed and script not running as root

Solution:
The script will tell you exactly what to install. Run the suggested commands, then run the script again.

For Ubuntu/Debian:

sudo apt-get update
sudo apt-get install -y python3 python3-yaml tar

For Rocky Linux/RHEL/CentOS/Fedora:

sudo dnf install -y python3 python3-pyyaml tar

Unsupported distribution

Problem: Your Linux distribution is not supported

Solution:
Manually install Python 3 and PyYAML:

  • Install Python 3 from your distribution’s package manager
  • Install PyYAML: pip3 install pyyaml or via your package manager

Script fails to detect container type

Problem: Neither docker nor podman found

Solution: Install Docker or Podman before running the script

YAML validation fails

Problem: Configuration files have syntax errors after modification

Solution:

  1. Check the error messages
  2. Restore from backups
  3. Report the issue with your specific configuration

Containers fail to start

Problem: Containers won’t start after CrowdSec removal

Solution:

# Check container logs
docker logs pangolin
docker logs traefik

# Verify configuration files are valid
docker compose config

# Restore from backup if needed

Permission denied

Problem: Script doesn’t have execute permissions

Solution:

chmod +x remove-crowdsec.sh

Files Modified

docker-compose.yml

  • Removes crowdsec service
  • Removes crowdsec dependency from traefik service
  • Removes traefik log volume ./config/traefik/logs:/var/log/traefik

config/traefik/traefik_config.yml

  • Removes crowdsec plugin from experimental.plugins
  • Removes crowdsec middleware from entryPoints
  • Changes log format from json back to common
  • Removes accessLog configuration

config/traefik/dynamic_config.yml

  • Removes crowdsec middleware definition
  • Removes security-headers middleware (added by CrowdSec)
  • Removes default-whitelist middleware (added by CrowdSec)
  • Removes crowdsec middleware references from all routers

Post-Removal

After running the script:

  1. Containers will be restarted automatically
  2. Traefik will no longer use CrowdSec for protection
  3. Access logs will no longer be generated in JSON format
  4. All CrowdSec-related middleware will be removed

Support

If you encounter issues:

  1. Check the backup files were created
  2. Review container logs for errors
  3. Verify all three YAML files are valid
  4. Restore from backups if necessary

Re-installing CrowdSec

If you want to reinstall CrowdSec later:

  1. Use the Pangolin installer’s CrowdSec installation option
  2. Or restore from the backup files created by this script

Will this uninstall crowdsec if I have already installed Middleware-Manager? I ask because the one thing that I saw might cause a problem ./config/traefik/dynamic_config.yml. with Middleware Manager installed, this file gets moved to ./config/traefik/rules/dynamic_config.yml. I think I messed up my install and want to clean things out.

thanks

app

you can, just a file tweak required.
Find the dynamic_config file references in the script and replace your path. traefik_config remains the same