mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-06-12 05:15:26 +02:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 80c39d612c | |||
| f03f0155f4 | |||
| 0cc94980af | |||
| b8bf684077 | |||
| f083db67e4 | |||
| 4741cc92bd | |||
| 46655860e9 | |||
| 289ddda5e8 | |||
| f905afbc6f | |||
| bd5e77afc5 | |||
| 944e773759 | |||
| eb82f9ea9d |
@@ -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}"
|
||||
@@ -101,6 +101,17 @@ so-elastic-fleet:
|
||||
- file: trusttheca
|
||||
- x509: etc_elasticfleet_key
|
||||
- x509: etc_elasticfleet_crt
|
||||
|
||||
wait_for_so-elastic-fleet:
|
||||
http.wait_for_successful_query:
|
||||
- name: "https://localhost:8220/api/status"
|
||||
- ssl: True
|
||||
- verify_ssl: False
|
||||
- status: 200
|
||||
- wait_for: 300
|
||||
- request_interval: 15
|
||||
- require:
|
||||
- docker_container: so-elastic-fleet
|
||||
{% endif %}
|
||||
|
||||
delete_so-elastic-fleet_so-status.disabled:
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
include:
|
||||
- elasticfleet.config
|
||||
- kibana.enabled
|
||||
|
||||
# If enabled, automatically update Fleet Logstash Outputs
|
||||
{% if ELASTICFLEETMERGED.config.server.enable_auto_configuration %}
|
||||
@@ -19,6 +20,8 @@ so-elastic-fleet-auto-configure-logstash-outputs:
|
||||
- retry:
|
||||
attempts: 4
|
||||
interval: 30
|
||||
- require:
|
||||
- http: wait_for_so-kibana
|
||||
{% endif %}
|
||||
|
||||
# If enabled, automatically update Fleet Server URLs & ES Connection
|
||||
@@ -28,6 +31,8 @@ so-elastic-fleet-auto-configure-server-urls:
|
||||
- retry:
|
||||
attempts: 4
|
||||
interval: 30
|
||||
- require:
|
||||
- http: wait_for_so-kibana
|
||||
{% endif %}
|
||||
|
||||
# Automatically update Fleet Server Elasticsearch URLs & Agent Artifact URLs
|
||||
@@ -37,6 +42,8 @@ so-elastic-fleet-auto-configure-elasticsearch-urls:
|
||||
- retry:
|
||||
attempts: 4
|
||||
interval: 30
|
||||
- require:
|
||||
- http: wait_for_so-kibana
|
||||
|
||||
so-elastic-fleet-auto-configure-artifact-urls:
|
||||
cmd.run:
|
||||
@@ -44,6 +51,8 @@ so-elastic-fleet-auto-configure-artifact-urls:
|
||||
- retry:
|
||||
attempts: 4
|
||||
interval: 30
|
||||
- require:
|
||||
- http: wait_for_so-kibana
|
||||
|
||||
so-elastic-fleet-package-statefile:
|
||||
file.managed:
|
||||
@@ -55,7 +64,9 @@ so-elastic-fleet-package-upgrade:
|
||||
- name: /usr/sbin/so-elastic-fleet-package-upgrade
|
||||
- retry:
|
||||
attempts: 3
|
||||
interval: 10
|
||||
interval: 30
|
||||
- require:
|
||||
- http: wait_for_so-kibana
|
||||
- onchanges:
|
||||
- file: /opt/so/state/elastic_fleet_packages.txt
|
||||
|
||||
@@ -65,6 +76,8 @@ so-elastic-fleet-integrations:
|
||||
- retry:
|
||||
attempts: 3
|
||||
interval: 10
|
||||
- require:
|
||||
- http: wait_for_so-kibana
|
||||
|
||||
so-elastic-agent-grid-upgrade:
|
||||
cmd.run:
|
||||
@@ -72,6 +85,8 @@ so-elastic-agent-grid-upgrade:
|
||||
- retry:
|
||||
attempts: 12
|
||||
interval: 5
|
||||
- require:
|
||||
- http: wait_for_so-kibana
|
||||
|
||||
so-elastic-fleet-integration-upgrade:
|
||||
cmd.run:
|
||||
@@ -79,16 +94,22 @@ so-elastic-fleet-integration-upgrade:
|
||||
- retry:
|
||||
attempts: 3
|
||||
interval: 10
|
||||
- require:
|
||||
- http: wait_for_so-kibana
|
||||
|
||||
{# Optional integrations script doesn't need the retries like so-elastic-fleet-integration-upgrade which loads the default integrations #}
|
||||
so-elastic-fleet-addon-integrations:
|
||||
cmd.run:
|
||||
- name: /usr/sbin/so-elastic-fleet-optional-integrations-load
|
||||
- require:
|
||||
- http: wait_for_so-kibana
|
||||
|
||||
{% if ELASTICFLEETMERGED.config.defend_filters.enable_auto_configuration %}
|
||||
so-elastic-defend-manage-filters-file-watch:
|
||||
cmd.run:
|
||||
- name: python3 /sbin/so-elastic-defend-manage-filters.py -c /opt/so/conf/elasticsearch/curl.config -d /opt/so/conf/elastic-fleet/defend-exclusions/disabled-filters.yaml -i /nsm/securityonion-resources/event_filters/ -i /opt/so/conf/elastic-fleet/defend-exclusions/rulesets/custom-filters/ &>> /opt/so/log/elasticfleet/elastic-defend-manage-filters.log
|
||||
- require:
|
||||
- http: wait_for_so-kibana
|
||||
- onchanges:
|
||||
- file: elasticdefendcustom
|
||||
- file: elasticdefenddisabled
|
||||
|
||||
@@ -108,9 +108,12 @@ if [ ! -f /opt/so/state/eaintegrations.txt ]; then
|
||||
done
|
||||
|
||||
# Only create the state file if all policies were created/updated successfully
|
||||
if [[ "$RETURN_CODE" != "1" ]]; then
|
||||
if [[ $RETURN_CODE -eq 0 ]]; then
|
||||
touch /opt/so/state/eaintegrations.txt
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
exit $RETURN_CODE
|
||||
echo "Fleet integration policies already loaded."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -8,18 +8,33 @@
|
||||
|
||||
. /usr/sbin/so-elastic-fleet-common
|
||||
|
||||
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
|
||||
# exit 1 on failure to upgrade a default package, allow salt to handle retries
|
||||
echo -e "\nERROR: Failed to upgrade $PACKAGE to version: $VERSION"
|
||||
exit 1
|
||||
PKG_LOAD_FAILURES=$((PKG_LOAD_FAILURES + 1))
|
||||
PKG_LOAD_FAILURES_NAMES+=("{{ PACKAGE }}")
|
||||
fi
|
||||
else
|
||||
echo -e "\nERROR: 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
|
||||
echo "ERROR: Failed to upgrade $PKG_LOAD_FAILURES package(s):"
|
||||
for PKG in "${PKG_LOAD_FAILURES_NAMES[@]}"; do
|
||||
echo " - $PKG"
|
||||
done
|
||||
# exit 1 on failure to upgrade a default package, allow salt to handle retries
|
||||
exit 1
|
||||
else
|
||||
echo "Successfully upgraded all packages."
|
||||
fi
|
||||
|
||||
echo
|
||||
/usr/sbin/so-elasticsearch-templates-load
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
{% from 'allowed_states.map.jinja' import allowed_states %}
|
||||
{% if sls.split('.')[0] in allowed_states %}
|
||||
{% from 'docker/docker.map.jinja' import DOCKERMERGED %}
|
||||
{% from 'elasticsearch/config.map.jinja' import ELASTICSEARCHMERGED %}
|
||||
{% from 'vars/globals.map.jinja' import GLOBALS %}
|
||||
|
||||
include:
|
||||
@@ -60,6 +61,19 @@ so-kibana:
|
||||
- watch:
|
||||
- file: kibanaconfig
|
||||
|
||||
wait_for_so-kibana:
|
||||
http.wait_for_successful_query:
|
||||
- name: "http://localhost:5601/api/status"
|
||||
- username: 'so_elastic'
|
||||
- password: '{{ ELASTICSEARCHMERGED.auth.users.so_elastic_user.pass }}'
|
||||
- ssl: True
|
||||
- verify_ssl: False
|
||||
- status: 200
|
||||
- wait_for: 300
|
||||
- request_interval: 15
|
||||
- require:
|
||||
- docker_container: so-kibana
|
||||
|
||||
delete_so-kibana_so-status.disabled:
|
||||
file.uncomment:
|
||||
- name: /opt/so/conf/so-status/so-status.conf
|
||||
|
||||
@@ -223,6 +223,8 @@ if [ -n "$test_profile" ]; then
|
||||
WEBPASSWD1=0n10nus3r
|
||||
WEBPASSWD2=0n10nus3r
|
||||
NODE_DESCRIPTION="${HOSTNAME} - ${install_type} - ${MSRVIP_OFFSET}"
|
||||
# opt out of telemetry for automated testing
|
||||
telemetry=1
|
||||
|
||||
update_sudoers_for_testing
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user