mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-06-24 11:18:17 +02:00
Compare commits
13 Commits
reyesj2-jpp
...
3/dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 81c8d54589 | |||
| 4f3b57f495 | |||
| 84228a819b | |||
| a9f9d8bd0d | |||
| 953fdee3af | |||
| e2e3e690ca | |||
| 323491f58e | |||
| bcc60a4ae0 | |||
| b77103aa9f | |||
| 63a2e20698 | |||
| 22d5c96bd5 | |||
| 28fdd1eb6f | |||
| 80c39d612c |
@@ -130,6 +130,17 @@ common_sbin:
|
||||
- so-pcap-import
|
||||
{% endif %}
|
||||
|
||||
# Pin physical NIC names by MAC (run-once) so a kernel upgrade can't renumber the
|
||||
# interfaces SO binds by name. The marker keeps it a one-time setup; an admin can
|
||||
# pre-create the marker to opt out.
|
||||
pin_nic_names:
|
||||
cmd.run:
|
||||
- name: /usr/sbin/so-nic-pin
|
||||
- unless: 'test -e /opt/so/state/nic_names_pinned'
|
||||
- require:
|
||||
- file: common_sbin
|
||||
- file: statedir
|
||||
|
||||
common_sbin_jinja:
|
||||
file.recurse:
|
||||
- name: /usr/sbin
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# so-nic-pin — pin physical NIC names by permanent MAC via classic by-MAC udev
|
||||
# rules, so a kernel upgrade can't renumber them.
|
||||
#
|
||||
# Security Onion binds its management and monitor interfaces BY NAME in pillar
|
||||
# (host:mainint, sensor:mainint, and bond0 is built on a specific physical NIC).
|
||||
# A kernel upgrade can change the kernel/systemd-udevd predictable-naming output
|
||||
# and renumber those NICs (e.g. enp1s0 -> enp2s0), which breaks the grid: the
|
||||
# pillar references a name that no longer exists and bond/bridge bring-up fails.
|
||||
#
|
||||
# This writes /etc/udev/rules.d/70-persistent-net.rules pinning each PHYSICAL NIC
|
||||
# to its CURRENT name by its PERMANENT MAC, freezing the names across future kernel
|
||||
# changes. It only writes the rules file; it does NOT live-trigger a rename (the
|
||||
# rules apply on the next boot/kernel, and a live rename would be disruptive).
|
||||
#
|
||||
# Run-once: gated by the drop file /opt/so/state/nic_names_pinned. If the marker is
|
||||
# present the script does nothing, so an admin can pre-create it to opt out. Invoked
|
||||
# from the common state on every highstate; the marker keeps it a one-time setup.
|
||||
|
||||
NET_RULES_FILE="/etc/udev/rules.d/70-persistent-net.rules"
|
||||
MARKER="/opt/so/state/nic_names_pinned"
|
||||
|
||||
log() { echo -e "[so-nic-pin] $*"; }
|
||||
|
||||
# Echo "<name> <permanent-mac>" for every PHYSICAL NIC. A physical NIC is backed by a
|
||||
# real device (has device/driver), which excludes bond0/sobridge/docker0/veth*/lo whose
|
||||
# MACs are dynamic and must never be pinned. The PERMANENT MAC is used (ethtool -P, with
|
||||
# fallbacks), not the current one: an enslaved bond member's current MAC is rewritten to
|
||||
# the bond's, so matching on it would be wrong/ambiguous.
|
||||
physical_nics() {
|
||||
local path n mac
|
||||
for path in /sys/class/net/*; do
|
||||
n="${path##*/}"
|
||||
[ "$n" = "lo" ] && continue
|
||||
[ -e "${path}/device/driver" ] || continue # real device only
|
||||
mac="$(ethtool -P "$n" 2>/dev/null | awk '/Permanent address/{print $NF}')"
|
||||
case "$mac" in ""|00:00:00:00:00:00) mac="$(cat "${path}/bonding_slave/perm_hwaddr" 2>/dev/null)" ;; esac
|
||||
case "$mac" in ""|00:00:00:00:00:00) mac="$(cat "${path}/address" 2>/dev/null)" ;; esac
|
||||
case "$mac" in ""|00:00:00:00:00:00) continue ;; esac
|
||||
echo "$n $mac"
|
||||
done
|
||||
}
|
||||
|
||||
# Turn "<name> <mac>" lines on stdin into classic by-MAC persistent-net udev rules.
|
||||
render_net_rules() {
|
||||
echo "# Generated by so-nic-pin: pin NIC names by MAC so kernel upgrades can't renumber them."
|
||||
echo "# Security Onion binds its management/monitor interfaces by name; do not hand-edit."
|
||||
local n mac
|
||||
while read -r n mac; do
|
||||
[ -n "$n" ] || continue
|
||||
printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s"\n' \
|
||||
"$mac" "$n"
|
||||
done
|
||||
}
|
||||
|
||||
[ "$(id -u)" -eq 0 ] || exit 0 # salt runs us as root; bail quietly otherwise
|
||||
[ -e "${MARKER}" ] && exit 0 # run-once guard (mirrors the state's unless)
|
||||
|
||||
nics="$(physical_nics)"
|
||||
if [ -z "${nics}" ]; then
|
||||
log "no physical NICs detected — nothing to pin (will retry on next highstate)"
|
||||
exit 0 # do NOT drop the marker; let it retry later
|
||||
fi
|
||||
|
||||
log "pinning physical NICs by permanent MAC:"
|
||||
echo "${nics}" | sed 's/^/ /'
|
||||
|
||||
[ -f "${NET_RULES_FILE}" ] && cp -f "${NET_RULES_FILE}" "${NET_RULES_FILE}.bak"
|
||||
echo "${nics}" | render_net_rules > "${NET_RULES_FILE}" || {
|
||||
log "ERROR: failed to write ${NET_RULES_FILE}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
mkdir -p "$(dirname "${MARKER}")" && touch "${MARKER}"
|
||||
log "wrote ${NET_RULES_FILE} ($(grep -c '^SUBSYSTEM' "${NET_RULES_FILE}") NIC(s) pinned); dropped ${MARKER}"
|
||||
@@ -173,7 +173,7 @@ eaoptionalintegrationsdir:
|
||||
|
||||
{% for minion in node_data %}
|
||||
{% set role = node_data[minion]["role"] %}
|
||||
{% if role in [ "eval","fleet","heavynode","import","manager", "managerhype", "managersearch","standalone" ] %}
|
||||
{% if role in [ "eval","fleet","import","manager", "managerhype", "managersearch","standalone" ] %}
|
||||
{% set optional_integrations = ELASTICFLEETMERGED.optional_integrations %}
|
||||
{% set integration_keys = optional_integrations.keys() %}
|
||||
fleet_server_integrations_{{ minion }}:
|
||||
|
||||
@@ -67,8 +67,6 @@ so-elastic-fleet-package-upgrade:
|
||||
interval: 30
|
||||
- require:
|
||||
- http: wait_for_so-kibana
|
||||
- onchanges:
|
||||
- file: /opt/so/state/elastic_fleet_packages.txt
|
||||
|
||||
so-elastic-fleet-integrations:
|
||||
cmd.run:
|
||||
|
||||
@@ -9,13 +9,11 @@
|
||||
RETURN_CODE=0
|
||||
|
||||
if [ ! -f /opt/so/state/eaintegrations.txt ]; then
|
||||
# First, check for any package upgrades
|
||||
/usr/sbin/so-elastic-fleet-package-upgrade
|
||||
|
||||
# Second, update Fleet Server policies
|
||||
# update Fleet Server policies
|
||||
/usr/sbin/so-elastic-fleet-integration-policy-elastic-fleet-server
|
||||
|
||||
# Third, configure Elastic Defend Integration seperately
|
||||
# configure Elastic Defend Integration separately
|
||||
/usr/sbin/so-elastic-fleet-integration-policy-elastic-defend
|
||||
|
||||
# Each group fetches its agent policy once and dispatches create/update writes concurrently.
|
||||
@@ -32,9 +30,12 @@ if [ ! -f /opt/so/state/eaintegrations.txt ]; then
|
||||
elastic_fleet_load_integrations_dir "so-grid-nodes_heavy" \
|
||||
/opt/so/conf/elastic-fleet/integrations/grid-nodes_heavy "Grid Nodes Policy_Heavy" || RETURN_CODE=1
|
||||
|
||||
# Fleet Server - Optional integrations (one agent policy per FleetServer_* directory)
|
||||
# Fleet Server - Optional integrations (adds integration configuration to a given FleetServer_ policy)
|
||||
for FLEET_DIR in /opt/so/conf/elastic-fleet/integrations-optional/FleetServer*/; do
|
||||
[ -d "$FLEET_DIR" ] || continue
|
||||
INTEGRATIONS=("${FLEET_DIR%/}"/*.json)
|
||||
[ -e "${INTEGRATIONS[0]}" ] || continue
|
||||
|
||||
FLEET_POLICY=$(basename "$FLEET_DIR")
|
||||
elastic_fleet_load_integrations_dir "$FLEET_POLICY" \
|
||||
"${FLEET_DIR%/}" "Fleet Server Policy" "elasticsearch-logs" || RETURN_CODE=1
|
||||
|
||||
@@ -12,17 +12,22 @@ PKG_LOAD_FAILURES=0
|
||||
PKG_LOAD_FAILURES_NAMES=()
|
||||
|
||||
{%- for PACKAGE in SUPPORTED_PACKAGES %}
|
||||
echo "Upgrading {{ PACKAGE }} package..."
|
||||
if VERSION=$(elastic_fleet_package_latest_version_check "{{ PACKAGE }}"); then
|
||||
if ! elastic_fleet_package_install "{{ PACKAGE }}" "$VERSION"; then
|
||||
PKG_LOAD_FAILURES=$((PKG_LOAD_FAILURES + 1))
|
||||
PKG_LOAD_FAILURES_NAMES+=("{{ PACKAGE }}")
|
||||
if INSTALLED_VERSION=$(elastic_fleet_package_version_check "{{ PACKAGE }}") && LATEST_VERSION=$(elastic_fleet_package_latest_version_check "{{ PACKAGE }}"); then
|
||||
|
||||
if [ "$INSTALLED_VERSION" == "$LATEST_VERSION" ]; then
|
||||
echo "{{ PACKAGE }} integration version $INSTALLED_VERSION is already at the reported latest version $LATEST_VERSION, skipping upgrade."
|
||||
else
|
||||
echo "Upgrading {{ PACKAGE }} package to version $LATEST_VERSION..."
|
||||
if ! elastic_fleet_package_install "{{ PACKAGE }}" "$LATEST_VERSION"; then
|
||||
PKG_LOAD_FAILURES=$((PKG_LOAD_FAILURES + 1))
|
||||
PKG_LOAD_FAILURES_NAMES+=("{{ PACKAGE }}")
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "ERROR: Failed to get version information for integration {{ PACKAGE }}"
|
||||
PKG_LOAD_FAILURES=$((PKG_LOAD_FAILURES + 1))
|
||||
PKG_LOAD_FAILURES_NAMES+=("{{ PACKAGE }}")
|
||||
fi
|
||||
echo
|
||||
{%- endfor %}
|
||||
|
||||
if [ $PKG_LOAD_FAILURES -gt 0 ]; then
|
||||
@@ -35,6 +40,3 @@ if [ $PKG_LOAD_FAILURES -gt 0 ]; then
|
||||
else
|
||||
echo "Successfully upgraded all packages."
|
||||
fi
|
||||
|
||||
echo
|
||||
/usr/sbin/so-elasticsearch-templates-load
|
||||
|
||||
@@ -181,6 +181,9 @@ if ! elastic_fleet_policy_create "so-grid-nodes_heavy" "SO Grid Nodes - Heavy No
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for package upgrades
|
||||
so-elastic-fleet-package-upgrade
|
||||
|
||||
# Load Integrations for default policies
|
||||
so-elastic-fleet-integration-policy-load
|
||||
|
||||
|
||||
@@ -131,6 +131,8 @@ check_err() {
|
||||
# Collect bash error context before passing off to check_err()
|
||||
on_err() {
|
||||
local exit_code=$?
|
||||
# Ignore failures in blocks that explicitly disabled errexit with `set +e`.
|
||||
[[ $- == *e* ]] || return $exit_code
|
||||
# turn off xtrace to prevent added noise in debug log
|
||||
set +x 2>/dev/null || true
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ include:
|
||||
# Install the registry container
|
||||
so-dockerregistry:
|
||||
docker_container.running:
|
||||
- image: ghcr.io/security-onion-solutions/registry:3.0.0
|
||||
- image: ghcr.io/security-onion-solutions/registry:3.1.1
|
||||
- hostname: so-registry
|
||||
- networks:
|
||||
- sobridge:
|
||||
|
||||
Reference in New Issue
Block a user