Files
Charon/configs/crowdsec/register_bouncer.sh
GitHub Actions 4b49ec5f2b feat: Enhance LiveLogViewer with Security Mode and related tests
- Updated LiveLogViewer to support a new security mode, allowing for the display of security logs.
- Implemented mock functions for connecting to security logs in tests.
- Added tests for rendering, filtering, and displaying security log entries, including blocked requests and source filtering.
- Modified Security page to utilize the new security mode in LiveLogViewer.
- Updated Security page tests to reflect changes in log viewer and ensure proper rendering of security-related components.
- Introduced a new script for CrowdSec startup testing, ensuring proper configuration and parser installation.
- Added pre-flight checks in the CrowdSec integration script to verify successful startup and configuration.
2025-12-12 22:18:28 +00:00

45 lines
1.2 KiB
Bash

#!/bin/sh
# Register the Caddy bouncer with CrowdSec LAPI
# This script is idempotent - safe to run multiple times
# POSIX-compatible - do not use bash-specific syntax
set -e
BOUNCER_NAME="${CROWDSEC_BOUNCER_NAME:-caddy-bouncer}"
API_KEY_FILE="/etc/crowdsec/bouncers/${BOUNCER_NAME}.key"
# Ensure bouncer directory exists
mkdir -p /etc/crowdsec/bouncers
# Check if bouncer already registered
if cscli bouncers list 2>/dev/null | grep -q "${BOUNCER_NAME}"; then
echo "Bouncer '${BOUNCER_NAME}' already registered"
# If key file exists, use it
if [ -f "$API_KEY_FILE" ]; then
echo "Using existing API key from ${API_KEY_FILE}"
cat "$API_KEY_FILE"
exit 0
fi
# Key file missing but bouncer registered - re-register
echo "API key file missing, re-registering bouncer..."
cscli bouncers delete "${BOUNCER_NAME}" 2>/dev/null || true
fi
# Register new bouncer and capture API key
echo "Registering bouncer '${BOUNCER_NAME}'..."
API_KEY=$(cscli bouncers add "${BOUNCER_NAME}" -o raw 2>/dev/null)
if [ -z "$API_KEY" ]; then
echo "ERROR: Failed to register bouncer" >&2
exit 1
fi
# Save API key to file
echo "$API_KEY" > "$API_KEY_FILE"
chmod 600 "$API_KEY_FILE"
echo "Bouncer registered successfully"
echo "$API_KEY"