refactor(wazuh): use official templates for shared directory
Extract agent-template.conf and default/agent.conf from official wazuh/wazuh-manager:4.14.1 image and store them in scripts/templates/. The init-manager.sh script now copies these files instead of creating them inline, ensuring consistency with official Wazuh configuration. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,43 +7,21 @@ echo "MANAGER_INIT: Starting manager initialization..."
|
|||||||
# AGENT GROUPS (SHARED) INITIALIZATION
|
# AGENT GROUPS (SHARED) INITIALIZATION
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# When /var/ossec/etc/shared is mounted as an empty volume, the default files
|
# When /var/ossec/etc/shared is mounted as an empty volume, the default files
|
||||||
# are missing. We need to create them for group management to work.
|
# are missing. We copy them from /scripts/templates/ (extracted from official image).
|
||||||
|
|
||||||
SHARED_DIR="/var/ossec/etc/shared"
|
SHARED_DIR="/var/ossec/etc/shared"
|
||||||
TEMPLATE_FILE="$SHARED_DIR/agent-template.conf"
|
TEMPLATES_DIR="/scripts/templates"
|
||||||
DEFAULT_DIR="$SHARED_DIR/default"
|
|
||||||
DEFAULT_AGENT_CONF="$DEFAULT_DIR/agent.conf"
|
|
||||||
|
|
||||||
echo "MANAGER_INIT: Checking agent groups shared directory..."
|
echo "MANAGER_INIT: Checking agent groups shared directory..."
|
||||||
|
|
||||||
# Create default group directory if it doesn't exist
|
# Copy templates if shared directory is empty or missing required files
|
||||||
if [ ! -d "$DEFAULT_DIR" ]; then
|
if [ ! -f "$SHARED_DIR/agent-template.conf" ] || [ ! -d "$SHARED_DIR/default" ]; then
|
||||||
echo "MANAGER_INIT: Creating default group directory..."
|
echo "MANAGER_INIT: Initializing shared directory from official Wazuh templates..."
|
||||||
mkdir -p "$DEFAULT_DIR"
|
cp -rn "$TEMPLATES_DIR/"* "$SHARED_DIR/" 2>/dev/null || cp -r "$TEMPLATES_DIR/"* "$SHARED_DIR/"
|
||||||
|
echo "MANAGER_INIT: Templates copied successfully"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create agent-template.conf if it doesn't exist (required for creating new groups)
|
# Set correct ownership
|
||||||
if [ ! -f "$TEMPLATE_FILE" ]; then
|
|
||||||
echo "MANAGER_INIT: Creating agent-template.conf..."
|
|
||||||
cat > "$TEMPLATE_FILE" << 'TEMPLATE_EOF'
|
|
||||||
<!-- Agent configuration template -->
|
|
||||||
<!-- This file is used as a template when creating new groups -->
|
|
||||||
<agent_config>
|
|
||||||
</agent_config>
|
|
||||||
TEMPLATE_EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create default/agent.conf if it doesn't exist
|
|
||||||
if [ ! -f "$DEFAULT_AGENT_CONF" ]; then
|
|
||||||
echo "MANAGER_INIT: Creating default/agent.conf..."
|
|
||||||
cat > "$DEFAULT_AGENT_CONF" << 'AGENT_EOF'
|
|
||||||
<!-- Default agent configuration -->
|
|
||||||
<agent_config>
|
|
||||||
</agent_config>
|
|
||||||
AGENT_EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set correct ownership (ossec:ossec = 1000:1000 in container)
|
|
||||||
chown -R wazuh:wazuh "$SHARED_DIR" 2>/dev/null || chown -R 1000:1000 "$SHARED_DIR" 2>/dev/null || true
|
chown -R wazuh:wazuh "$SHARED_DIR" 2>/dev/null || chown -R 1000:1000 "$SHARED_DIR" 2>/dev/null || true
|
||||||
|
|
||||||
echo "MANAGER_INIT: Agent groups directory ready"
|
echo "MANAGER_INIT: Agent groups directory ready"
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<agent_config>
|
||||||
|
|
||||||
|
<!-- Shared agent configuration here -->
|
||||||
|
|
||||||
|
</agent_config>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<agent_config>
|
||||||
|
|
||||||
|
<!-- Shared agent configuration here -->
|
||||||
|
|
||||||
|
</agent_config>
|
||||||
Reference in New Issue
Block a user