Complete RedFlag codebase with two major security audit implementations.
== A-1: Ed25519 Key Rotation Support ==
Server:
- SignCommand sets SignedAt timestamp and KeyID on every signature
- signing_keys database table (migration 020) for multi-key rotation
- InitializePrimaryKey registers active key at startup
- /api/v1/public-keys endpoint for rotation-aware agents
- SigningKeyQueries for key lifecycle management
Agent:
- Key-ID-aware verification via CheckKeyRotation
- FetchAndCacheAllActiveKeys for rotation pre-caching
- Cache metadata with TTL and staleness fallback
- SecurityLogger events for key rotation and command signing
== A-2: Replay Attack Fixes (F-1 through F-7) ==
F-5 CRITICAL - RetryCommand now signs via signAndCreateCommand
F-1 HIGH - v3 format: "{agent_id}:{cmd_id}:{type}:{hash}:{ts}"
F-7 HIGH - Migration 026: expires_at column with partial index
F-6 HIGH - GetPendingCommands/GetStuckCommands filter by expires_at
F-2 HIGH - Agent-side executedIDs dedup map with cleanup
F-4 HIGH - commandMaxAge reduced from 24h to 4h
F-3 CRITICAL - Old-format commands rejected after 48h via CreatedAt
Verification fixes: migration idempotency (ETHOS #4), log format
compliance (ETHOS #1), stale comments updated.
All 24 tests passing. Docker --no-cache build verified.
See docs/ for full audit reports and deviation log (DEV-001 to DEV-019).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
71 lines
1.8 KiB
Bash
Executable File
71 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
# RedFlag Agent Uninstallation Script
|
|
# This script removes the RedFlag agent service and configuration
|
|
|
|
AGENT_USER="redflag-agent"
|
|
AGENT_HOME="/var/lib/redflag-agent"
|
|
AGENT_BINARY="/usr/local/bin/redflag-agent"
|
|
SUDOERS_FILE="/etc/sudoers.d/redflag-agent"
|
|
SERVICE_FILE="/etc/systemd/system/redflag-agent.service"
|
|
|
|
echo "=== RedFlag Agent Uninstallation ==="
|
|
echo ""
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "ERROR: This script must be run as root (use sudo)"
|
|
exit 1
|
|
fi
|
|
|
|
# Stop and disable service
|
|
if systemctl is-active --quiet redflag-agent; then
|
|
echo "Stopping redflag-agent service..."
|
|
systemctl stop redflag-agent
|
|
echo "✓ Service stopped"
|
|
fi
|
|
|
|
if systemctl is-enabled --quiet redflag-agent; then
|
|
echo "Disabling redflag-agent service..."
|
|
systemctl disable redflag-agent
|
|
echo "✓ Service disabled"
|
|
fi
|
|
|
|
# Remove service file
|
|
if [ -f "$SERVICE_FILE" ]; then
|
|
echo "Removing systemd service file..."
|
|
rm -f "$SERVICE_FILE"
|
|
systemctl daemon-reload
|
|
echo "✓ Service file removed"
|
|
fi
|
|
|
|
# Remove sudoers configuration
|
|
if [ -f "$SUDOERS_FILE" ]; then
|
|
echo "Removing sudoers configuration..."
|
|
rm -f "$SUDOERS_FILE"
|
|
echo "✓ Sudoers configuration removed"
|
|
fi
|
|
|
|
# Remove binary
|
|
if [ -f "$AGENT_BINARY" ]; then
|
|
echo "Removing agent binary..."
|
|
rm -f "$AGENT_BINARY"
|
|
echo "✓ Agent binary removed"
|
|
fi
|
|
|
|
# Optionally remove user (commented out by default to preserve logs/data)
|
|
# if id "$AGENT_USER" &>/dev/null; then
|
|
# echo "Removing user $AGENT_USER..."
|
|
# userdel -r "$AGENT_USER"
|
|
# echo "✓ User removed"
|
|
# fi
|
|
|
|
echo ""
|
|
echo "=== Uninstallation Complete ==="
|
|
echo ""
|
|
echo "Note: The $AGENT_USER user and $AGENT_HOME directory have been preserved."
|
|
echo "To completely remove them, run:"
|
|
echo " sudo userdel -r $AGENT_USER"
|
|
echo ""
|