mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-05-09 12:52:38 +02:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a6948e8dcb | |||
| 0ecc7ae594 | |||
| eadad6c163 | |||
| d5c0ec4404 | |||
| e616b4c120 | |||
| f240a99e22 | |||
| 614f32c5e0 | |||
| 724d76965f | |||
| dbf4fb66a4 | |||
| 5f28e9b191 | |||
| 1abfd77351 | |||
| 81c0f2b464 | |||
| d5dc28e526 |
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||||
|
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||||
|
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||||
|
# Elastic License 2.0.
|
||||||
|
|
||||||
|
# Per-minion Telegraf Postgres credentials. so-telegraf-cred on the manager is
|
||||||
|
# the single writer; it mutates /opt/so/saltstack/local/pillar/telegraf/creds.sls
|
||||||
|
# under flock. Pillar_roots order (local before default) means the populated
|
||||||
|
# copy shadows this default on any real grid; this file exists so the pillar
|
||||||
|
# key is always defined on fresh installs and when no minions have creds yet.
|
||||||
|
telegraf:
|
||||||
|
postgres_creds: {}
|
||||||
@@ -17,6 +17,7 @@ base:
|
|||||||
- sensoroni.adv_sensoroni
|
- sensoroni.adv_sensoroni
|
||||||
- telegraf.soc_telegraf
|
- telegraf.soc_telegraf
|
||||||
- telegraf.adv_telegraf
|
- telegraf.adv_telegraf
|
||||||
|
- telegraf.creds
|
||||||
- versionlock.soc_versionlock
|
- versionlock.soc_versionlock
|
||||||
- versionlock.adv_versionlock
|
- versionlock.adv_versionlock
|
||||||
- soc.license
|
- soc.license
|
||||||
|
|||||||
@@ -59,5 +59,4 @@ global:
|
|||||||
description: Allows use of Endgame with Security Onion. This feature requires a license from Endgame.
|
description: Allows use of Endgame with Security Onion. This feature requires a license from Endgame.
|
||||||
global: True
|
global: True
|
||||||
advanced: True
|
advanced: True
|
||||||
helpLink: influxdb
|
|
||||||
|
|
||||||
|
|||||||
@@ -281,6 +281,39 @@ function deleteMinionFiles () {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Remove this minion's postgres Telegraf credential from the shared creds
|
||||||
|
# pillar and drop the matching role in Postgres. Always returns 0 so a dead
|
||||||
|
# or unreachable so-postgres doesn't block minion deletion — in that case we
|
||||||
|
# log a warning and leave the role behind for manual cleanup.
|
||||||
|
function remove_postgres_telegraf_from_minion() {
|
||||||
|
local MINION_SAFE
|
||||||
|
MINION_SAFE=$(echo "$MINION_ID" | tr '.-' '__' | tr '[:upper:]' '[:lower:]')
|
||||||
|
local PG_USER="so_telegraf_${MINION_SAFE}"
|
||||||
|
|
||||||
|
log "INFO" "Removing postgres telegraf cred for $MINION_ID"
|
||||||
|
|
||||||
|
so-telegraf-cred remove "$MINION_ID" >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
if docker ps --format '{{.Names}}' 2>/dev/null | grep -q '^so-postgres$'; then
|
||||||
|
if ! docker exec -i so-postgres psql -v ON_ERROR_STOP=1 -U postgres -d so_telegraf >/dev/null 2>&1 <<EOSQL
|
||||||
|
DO \$\$
|
||||||
|
BEGIN
|
||||||
|
IF EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = '$PG_USER') THEN
|
||||||
|
EXECUTE format('REASSIGN OWNED BY %I TO so_telegraf', '$PG_USER');
|
||||||
|
EXECUTE format('DROP OWNED BY %I', '$PG_USER');
|
||||||
|
EXECUTE format('DROP ROLE %I', '$PG_USER');
|
||||||
|
END IF;
|
||||||
|
END
|
||||||
|
\$\$;
|
||||||
|
EOSQL
|
||||||
|
then
|
||||||
|
log "WARN" "Failed to drop postgres role $PG_USER; pillar entry was removed — drop manually if the role persists"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log "WARN" "so-postgres container is not running; skipping DB role cleanup for $PG_USER"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Create the minion file
|
# Create the minion file
|
||||||
function ensure_socore_ownership() {
|
function ensure_socore_ownership() {
|
||||||
log "INFO" "Setting socore ownership on minion files"
|
log "INFO" "Setting socore ownership on minion files"
|
||||||
@@ -542,6 +575,17 @@ function add_telegraf_to_minion() {
|
|||||||
log "ERROR" "Failed to add telegraf configuration to $PILLARFILE"
|
log "ERROR" "Failed to add telegraf configuration to $PILLARFILE"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Provision the per-minion postgres Telegraf credential in the shared
|
||||||
|
# telegraf/creds.sls pillar. so-telegraf-cred is the only writer; it
|
||||||
|
# generates a password on first add and is a no-op on re-add so the cred
|
||||||
|
# is stable across repeated so-minion runs. postgres.telegraf_users on the
|
||||||
|
# manager creates/updates the DB role from the same pillar.
|
||||||
|
so-telegraf-cred add "$MINION_ID"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
log "ERROR" "Failed to provision postgres telegraf cred for $MINION_ID"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_influxdb_to_minion() {
|
function add_influxdb_to_minion() {
|
||||||
@@ -1069,6 +1113,7 @@ case "$OPERATION" in
|
|||||||
|
|
||||||
"delete")
|
"delete")
|
||||||
log "INFO" "Removing minion $MINION_ID"
|
log "INFO" "Removing minion $MINION_ID"
|
||||||
|
remove_postgres_telegraf_from_minion
|
||||||
deleteMinionFiles || {
|
deleteMinionFiles || {
|
||||||
log "ERROR" "Failed to delete minion files for $MINION_ID"
|
log "ERROR" "Failed to delete minion files for $MINION_ID"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Executable
+54
@@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||||
|
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||||
|
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||||
|
# Elastic License 2.0.
|
||||||
|
|
||||||
|
# Single writer for the Telegraf Postgres credentials pillar. Thin wrapper
|
||||||
|
# around so-yaml.py that generates a password on first add and no-ops on
|
||||||
|
# re-add so the cred is stable across repeated so-minion runs.
|
||||||
|
#
|
||||||
|
# Note: so-yaml.py splits keys on '.' with no escape. SO minion ids are
|
||||||
|
# dot-free by construction (setup/so-functions:1884 takes the short_name
|
||||||
|
# before the first '.'), so using the raw minion id as the key is safe.
|
||||||
|
|
||||||
|
CREDS=/opt/so/saltstack/local/pillar/telegraf/creds.sls
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: $0 <add|remove> <minion_id>" >&2
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
|
||||||
|
seed_creds_file() {
|
||||||
|
mkdir -p "$(dirname "$CREDS")" || return 1
|
||||||
|
if [[ ! -f "$CREDS" ]]; then
|
||||||
|
(umask 027 && printf 'telegraf:\n postgres_creds: {}\n' > "$CREDS") || return 1
|
||||||
|
chown socore:socore "$CREDS" 2>/dev/null || true
|
||||||
|
chmod 640 "$CREDS" || return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
OP=$1
|
||||||
|
MID=$2
|
||||||
|
[[ -z "$OP" || -z "$MID" ]] && usage
|
||||||
|
|
||||||
|
case "$OP" in
|
||||||
|
add)
|
||||||
|
SAFE=$(echo "$MID" | tr '.-' '__' | tr '[:upper:]' '[:lower:]')
|
||||||
|
seed_creds_file || exit 1
|
||||||
|
if so-yaml.py get -r "$CREDS" "telegraf.postgres_creds.${MID}.user" >/dev/null 2>&1; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
PASS=$(tr -dc 'A-Za-z0-9~!@#^&*()_=+[]|;:,.<>?-' < /dev/urandom | head -c 72)
|
||||||
|
so-yaml.py replace "$CREDS" "telegraf.postgres_creds.${MID}.user" "so_telegraf_${SAFE}" >/dev/null
|
||||||
|
so-yaml.py replace "$CREDS" "telegraf.postgres_creds.${MID}.pass" "$PASS" >/dev/null
|
||||||
|
;;
|
||||||
|
remove)
|
||||||
|
[[ -f "$CREDS" ]] || exit 0
|
||||||
|
so-yaml.py remove "$CREDS" "telegraf.postgres_creds.${MID}" >/dev/null 2>&1 || true
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
@@ -39,9 +39,16 @@ def showUsage(args):
|
|||||||
|
|
||||||
|
|
||||||
def loadYaml(filename):
|
def loadYaml(filename):
|
||||||
file = open(filename, "r")
|
try:
|
||||||
content = file.read()
|
with open(filename, "r") as file:
|
||||||
return yaml.safe_load(content)
|
content = file.read()
|
||||||
|
return yaml.safe_load(content)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"File not found: {filename}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error reading file {filename}: {e}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def writeYaml(filename, content):
|
def writeYaml(filename, content):
|
||||||
@@ -285,7 +292,8 @@ def add(args):
|
|||||||
def removeKey(content, key):
|
def removeKey(content, key):
|
||||||
pieces = key.split(".", 1)
|
pieces = key.split(".", 1)
|
||||||
if len(pieces) > 1:
|
if len(pieces) > 1:
|
||||||
removeKey(content[pieces[0]], pieces[1])
|
if pieces[0] in content:
|
||||||
|
removeKey(content[pieces[0]], pieces[1])
|
||||||
else:
|
else:
|
||||||
content.pop(key, None)
|
content.pop(key, None)
|
||||||
|
|
||||||
|
|||||||
@@ -973,3 +973,21 @@ class TestReplaceListObject(unittest.TestCase):
|
|||||||
|
|
||||||
expected = "key1:\n- id: '1'\n status: updated\n- id: '2'\n status: inactive\n"
|
expected = "key1:\n- id: '1'\n status: updated\n- id: '2'\n status: inactive\n"
|
||||||
self.assertEqual(actual, expected)
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
|
|
||||||
|
class TestLoadYaml(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_load_yaml_missing_file(self):
|
||||||
|
with patch('sys.exit', new=MagicMock()) as sysmock:
|
||||||
|
with patch('sys.stderr', new=StringIO()) as mock_stderr:
|
||||||
|
soyaml.loadYaml("/tmp/so-yaml_test-does-not-exist.yaml")
|
||||||
|
sysmock.assert_called_with(1)
|
||||||
|
self.assertIn("File not found:", mock_stderr.getvalue())
|
||||||
|
|
||||||
|
def test_load_yaml_read_error(self):
|
||||||
|
with patch('sys.exit', new=MagicMock()) as sysmock:
|
||||||
|
with patch('sys.stderr', new=StringIO()) as mock_stderr:
|
||||||
|
with patch('builtins.open', side_effect=PermissionError("denied")):
|
||||||
|
soyaml.loadYaml("/tmp/so-yaml_test-unreadable.yaml")
|
||||||
|
sysmock.assert_called_with(1)
|
||||||
|
self.assertIn("Error reading file", mock_stderr.getvalue())
|
||||||
|
|||||||
@@ -477,7 +477,44 @@ elasticsearch_backup_index_templates() {
|
|||||||
tar -czf /nsm/backup/3.0.0_elasticsearch_index_templates.tar.gz -C /opt/so/conf/elasticsearch/templates/index/ .
|
tar -czf /nsm/backup/3.0.0_elasticsearch_index_templates.tar.gz -C /opt/so/conf/elasticsearch/templates/index/ .
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensure_postgres_local_pillar() {
|
||||||
|
# Postgres was added as a service after 3.0.0, so the new pillar/top.sls
|
||||||
|
# references postgres.soc_postgres / postgres.adv_postgres unconditionally.
|
||||||
|
# Managers upgrading from 3.0.0 have no /opt/so/saltstack/local/pillar/postgres/
|
||||||
|
# (make_some_dirs only runs at install time), so the stubs must be created
|
||||||
|
# here before salt-master restarts against the new top.sls.
|
||||||
|
echo "Ensuring postgres local pillar stubs exist."
|
||||||
|
local dir=/opt/so/saltstack/local/pillar/postgres
|
||||||
|
mkdir -p "$dir"
|
||||||
|
[[ -f "$dir/soc_postgres.sls" ]] || touch "$dir/soc_postgres.sls"
|
||||||
|
[[ -f "$dir/adv_postgres.sls" ]] || touch "$dir/adv_postgres.sls"
|
||||||
|
chown -R socore:socore "$dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_postgres_secret() {
|
||||||
|
# On a fresh install, generate_passwords + secrets_pillar seed
|
||||||
|
# secrets:postgres_pass in /opt/so/saltstack/local/pillar/secrets.sls. That
|
||||||
|
# code path is skipped on upgrade (secrets.sls already exists from 3.0.0
|
||||||
|
# with import_pass/influx_pass but no postgres_pass), so the postgres
|
||||||
|
# container's POSTGRES_PASSWORD_FILE and SOC's PG_ADMIN_PASS would be empty
|
||||||
|
# after highstate. Generate one now if missing.
|
||||||
|
local secrets_file=/opt/so/saltstack/local/pillar/secrets.sls
|
||||||
|
if [[ ! -f "$secrets_file" ]]; then
|
||||||
|
echo "WARNING: $secrets_file missing; skipping postgres_pass backfill."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if so-yaml.py get -r "$secrets_file" secrets.postgres_pass >/dev/null 2>&1; then
|
||||||
|
echo "secrets.postgres_pass already set; leaving as-is."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo "Seeding secrets.postgres_pass in $secrets_file."
|
||||||
|
so-yaml.py add "$secrets_file" secrets.postgres_pass "$(get_random_value)"
|
||||||
|
chown socore:socore "$secrets_file"
|
||||||
|
}
|
||||||
|
|
||||||
up_to_3.1.0() {
|
up_to_3.1.0() {
|
||||||
|
ensure_postgres_local_pillar
|
||||||
|
ensure_postgres_secret
|
||||||
determine_elastic_agent_upgrade
|
determine_elastic_agent_upgrade
|
||||||
elasticsearch_backup_index_templates
|
elasticsearch_backup_index_templates
|
||||||
# Clear existing component template state file.
|
# Clear existing component template state file.
|
||||||
@@ -490,31 +527,19 @@ up_to_3.1.0() {
|
|||||||
post_to_3.1.0() {
|
post_to_3.1.0() {
|
||||||
/usr/sbin/so-kibana-space-defaults
|
/usr/sbin/so-kibana-space-defaults
|
||||||
|
|
||||||
# One-time backfill for minions that existed before the postgres Telegraf
|
# Backfill the Telegraf creds pillar for every accepted minion. so-telegraf-cred
|
||||||
# feature shipped. Generate the aggregate pillar on the manager and create
|
# add is idempotent — it no-ops when an entry already exists — so this is safe
|
||||||
# the per-minion DB roles, then fan each minion's cred into its own pillar
|
# to run on every soup. The subsequent state.apply creates/updates the matching
|
||||||
# file. Going forward the reactor handles each new salt-key accept with a
|
# Postgres roles from the reconciled pillar.
|
||||||
# targeted fan-out, so a manager highstate no longer needs to iterate.
|
echo "Reconciling Telegraf Postgres creds for accepted minions."
|
||||||
echo "Provisioning Telegraf Postgres users for existing minions."
|
for mid in $(salt-key --out=json --list=accepted 2>/dev/null | jq -r '.minions[]?' 2>/dev/null); do
|
||||||
salt-call --local state.apply postgres.auth,postgres.telegraf_users queue=True || true
|
[[ -n "$mid" ]] || continue
|
||||||
|
/usr/sbin/so-telegraf-cred add "$mid" || echo " warning: so-telegraf-cred add $mid failed" >&2
|
||||||
AGGREGATE_PILLAR=/opt/so/saltstack/local/pillar/postgres/auth.sls
|
done
|
||||||
MINIONS_DIR=/opt/so/saltstack/local/pillar/minions
|
# Run through the master (not --local) so state compilation uses the
|
||||||
if [[ -f "$AGGREGATE_PILLAR" && -d "$MINIONS_DIR" ]]; then
|
# master's configured file_roots; the manager's /etc/salt/minion has no
|
||||||
for pillar_file in "$MINIONS_DIR"/*.sls; do
|
# file_roots of its own and --local would fail with "No matching sls found".
|
||||||
[[ -f "$pillar_file" ]] || continue
|
salt-call state.apply postgres.telegraf_users queue=True || true
|
||||||
mid=$(basename "$pillar_file" .sls)
|
|
||||||
[[ "$mid" == adv_* ]] && continue
|
|
||||||
safe=$(echo "$mid" | tr '.-' '__' | tr '[:upper:]' '[:lower:]')
|
|
||||||
existing_user=$(so-yaml.py get -r "$pillar_file" postgres.telegraf.user 2>/dev/null || true)
|
|
||||||
[[ "$existing_user" == "so_telegraf_${safe}" ]] && continue
|
|
||||||
user=$(so-yaml.py get -r "$AGGREGATE_PILLAR" "postgres.auth.users.telegraf_${safe}.user" 2>/dev/null || true)
|
|
||||||
pass=$(so-yaml.py get -r "$AGGREGATE_PILLAR" "postgres.auth.users.telegraf_${safe}.pass" 2>/dev/null || true)
|
|
||||||
[[ -z "$user" || -z "$pass" ]] && continue
|
|
||||||
so-yaml.py replace "$pillar_file" postgres.telegraf.user "$user" >/dev/null
|
|
||||||
so-yaml.py replace "$pillar_file" postgres.telegraf.pass "$pass" >/dev/null
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
POSTVERSION=3.1.0
|
POSTVERSION=3.1.0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,33 @@ manager_run_es_soc:
|
|||||||
- salt: {{NEWNODE}}_update_mine
|
- salt: {{NEWNODE}}_update_mine
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
# so-minion has already added the new minion's entry to telegraf/creds.sls
|
||||||
|
# via so-telegraf-cred before this orch fires. Reconcile the Postgres role
|
||||||
|
# on the manager so the new minion can authenticate on its first highstate,
|
||||||
|
# then refresh the minion's pillar so its telegraf.conf renders with the
|
||||||
|
# freshly-written cred.
|
||||||
|
manager_create_postgres_telegraf_role:
|
||||||
|
salt.state:
|
||||||
|
- tgt: {{ MANAGER }}
|
||||||
|
- sls:
|
||||||
|
- postgres.telegraf_users
|
||||||
|
- queue: True
|
||||||
|
- require:
|
||||||
|
- salt: {{NEWNODE}}_update_mine
|
||||||
|
|
||||||
|
{{NEWNODE}}_refresh_pillar:
|
||||||
|
salt.function:
|
||||||
|
- name: saltutil.refresh_pillar
|
||||||
|
- tgt: {{ NEWNODE }}
|
||||||
|
- kwarg:
|
||||||
|
wait: True
|
||||||
|
- require:
|
||||||
|
- salt: manager_create_postgres_telegraf_role
|
||||||
|
|
||||||
{{NEWNODE}}_run_highstate:
|
{{NEWNODE}}_run_highstate:
|
||||||
salt.state:
|
salt.state:
|
||||||
- tgt: {{ NEWNODE }}
|
- tgt: {{ NEWNODE }}
|
||||||
- highstate: True
|
- highstate: True
|
||||||
- queue: True
|
- queue: True
|
||||||
|
- require:
|
||||||
|
- salt: {{NEWNODE}}_refresh_pillar
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
|
||||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
|
||||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
|
||||||
# Elastic License 2.0.
|
|
||||||
|
|
||||||
# Fired by salt/reactor/telegraf_user_sync.sls when salt-key accepts a new
|
|
||||||
# minion. Only provisions the per-minion pillar entry and DB role on the
|
|
||||||
# manager; the minion itself will pick up its telegraf config on its first
|
|
||||||
# highstate during onboarding, so there's no need to push the telegraf state
|
|
||||||
# from here.
|
|
||||||
#
|
|
||||||
# Target the manager via role grains — same pattern as orch/delete_hypervisor.sls.
|
|
||||||
# The reactor doesn't know the manager's minion id, and grains.master on the
|
|
||||||
# runner is a hostname, not a targetable id.
|
|
||||||
{% set FANOUT_MINION = salt['pillar.get']('postgres_fanout_minion', '') %}
|
|
||||||
|
|
||||||
manager_sync_telegraf_pg_users:
|
|
||||||
salt.state:
|
|
||||||
- tgt: 'G@role:so-manager or G@role:so-managerhype or G@role:so-managersearch or G@role:so-standalone or G@role:so-eval'
|
|
||||||
- tgt_type: compound
|
|
||||||
- sls:
|
|
||||||
- postgres.auth
|
|
||||||
- postgres.telegraf_users
|
|
||||||
- queue: True
|
|
||||||
{% if FANOUT_MINION %}
|
|
||||||
- pillar:
|
|
||||||
postgres_fanout_minion: {{ FANOUT_MINION }}
|
|
||||||
{% endif %}
|
|
||||||
+2
-55
@@ -13,24 +13,8 @@
|
|||||||
{% set CHARS = DIGITS~LOWERCASE~UPPERCASE~SYMBOLS %}
|
{% set CHARS = DIGITS~LOWERCASE~UPPERCASE~SYMBOLS %}
|
||||||
{% set so_postgres_user_pass = salt['pillar.get']('postgres:auth:users:so_postgres_user:pass', salt['random.get_str'](72, chars=CHARS)) %}
|
{% set so_postgres_user_pass = salt['pillar.get']('postgres:auth:users:so_postgres_user:pass', salt['random.get_str'](72, chars=CHARS)) %}
|
||||||
|
|
||||||
{# Per-minion Telegraf Postgres credentials. Merge currently-up minions with any #}
|
# Admin cred only. Per-minion Telegraf creds live in telegraf/creds.sls,
|
||||||
{# previously-known entries in pillar so existing passwords persist across runs. #}
|
# managed by /usr/sbin/so-telegraf-cred (called from so-minion).
|
||||||
{% set existing = salt['pillar.get']('postgres:auth:users', {}) %}
|
|
||||||
{% set up_minions = salt['saltutil.runner']('manage.up') or [] %}
|
|
||||||
{% set telegraf_users = {} %}
|
|
||||||
{% for key, entry in existing.items() %}
|
|
||||||
{%- if key.startswith('telegraf_') and entry.get('user') and entry.get('pass') %}
|
|
||||||
{%- do telegraf_users.update({key: entry}) %}
|
|
||||||
{%- endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% for mid in up_minions %}
|
|
||||||
{%- set safe = mid | replace('.','_') | replace('-','_') | lower %}
|
|
||||||
{%- set key = 'telegraf_' ~ safe %}
|
|
||||||
{%- if key not in telegraf_users %}
|
|
||||||
{%- do telegraf_users.update({key: {'user': 'so_telegraf_' ~ safe, 'pass': salt['random.get_str'](72, chars=CHARS)}}) %}
|
|
||||||
{%- endif %}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
postgres_auth_pillar:
|
postgres_auth_pillar:
|
||||||
file.managed:
|
file.managed:
|
||||||
- name: /opt/so/saltstack/local/pillar/postgres/auth.sls
|
- name: /opt/so/saltstack/local/pillar/postgres/auth.sls
|
||||||
@@ -43,44 +27,7 @@ postgres_auth_pillar:
|
|||||||
so_postgres_user:
|
so_postgres_user:
|
||||||
user: so_postgres
|
user: so_postgres
|
||||||
pass: "{{ so_postgres_user_pass }}"
|
pass: "{{ so_postgres_user_pass }}"
|
||||||
{% for key, entry in telegraf_users.items() %}
|
|
||||||
{{ key }}:
|
|
||||||
user: {{ entry.user }}
|
|
||||||
pass: "{{ entry.pass }}"
|
|
||||||
{% endfor %}
|
|
||||||
- show_changes: False
|
- show_changes: False
|
||||||
|
|
||||||
{# Fan a specific minion's telegraf cred out to its own pillar file. Only
|
|
||||||
runs when postgres_fanout_minion pillar is provided — otherwise this state
|
|
||||||
is a no-op. That keeps manager highstates from doing N so-yaml.py forks
|
|
||||||
when nothing changed. The reactor passes postgres_fanout_minion through
|
|
||||||
the orch on salt-key accept; soup handles bulk backfill separately. #}
|
|
||||||
{% set fanout_mid = salt['pillar.get']('postgres_fanout_minion') %}
|
|
||||||
{% if fanout_mid %}
|
|
||||||
{%- set safe = fanout_mid | replace('.','_') | replace('-','_') | lower %}
|
|
||||||
{%- set key = 'telegraf_' ~ safe %}
|
|
||||||
{%- set entry = telegraf_users.get(key) %}
|
|
||||||
{%- if entry %}
|
|
||||||
|
|
||||||
postgres_telegraf_minion_pillar_{{ safe }}:
|
|
||||||
cmd.run:
|
|
||||||
- name: |
|
|
||||||
set -e
|
|
||||||
PILLAR_FILE=/opt/so/saltstack/local/pillar/minions/{{ fanout_mid }}.sls
|
|
||||||
if [ ! -f "$PILLAR_FILE" ]; then
|
|
||||||
echo '{}' > "$PILLAR_FILE"
|
|
||||||
chown socore:socore "$PILLAR_FILE" 2>/dev/null || true
|
|
||||||
chmod 640 "$PILLAR_FILE"
|
|
||||||
fi
|
|
||||||
/usr/sbin/so-yaml.py replace "$PILLAR_FILE" postgres.telegraf.user '{{ entry.user }}'
|
|
||||||
/usr/sbin/so-yaml.py replace "$PILLAR_FILE" postgres.telegraf.pass '{{ entry.pass }}'
|
|
||||||
- unless: |
|
|
||||||
[ "$(/usr/sbin/so-yaml.py get -r /opt/so/saltstack/local/pillar/minions/{{ fanout_mid }}.sls postgres.telegraf.user 2>/dev/null)" = '{{ entry.user }}' ]
|
|
||||||
- require:
|
|
||||||
- file: postgres_auth_pillar
|
|
||||||
|
|
||||||
{%- endif %}
|
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
{{sls}}_state_not_allowed:
|
{{sls}}_state_not_allowed:
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
{# postgres_wait_ready below requires `docker_container: so-postgres`, which is
|
{# postgres_wait_ready below requires `docker_container: so-postgres`, which is
|
||||||
declared in postgres.enabled. Include it here so state.apply postgres.telegraf_users
|
declared in postgres.enabled. Include it here so state.apply postgres.telegraf_users
|
||||||
on its own (from the reactor orch or from soup) still has that ID in scope. Salt
|
on its own (e.g. from orch.deploy_newnode) still has that ID in scope. Salt
|
||||||
de-duplicates the circular include. #}
|
de-duplicates the circular include. #}
|
||||||
include:
|
include:
|
||||||
- postgres.enabled
|
- postgres.enabled
|
||||||
@@ -96,9 +96,9 @@ postgres_telegraf_group_role:
|
|||||||
- require:
|
- require:
|
||||||
- cmd: postgres_create_telegraf_db
|
- cmd: postgres_create_telegraf_db
|
||||||
|
|
||||||
{% set users = salt['pillar.get']('postgres:auth:users', {}) %}
|
{% set creds = salt['pillar.get']('telegraf:postgres_creds', {}) %}
|
||||||
{% for key, entry in users.items() %}
|
{% for mid, entry in creds.items() %}
|
||||||
{% if key.startswith('telegraf_') and entry.get('user') and entry.get('pass') %}
|
{% if entry.get('user') and entry.get('pass') %}
|
||||||
{% set u = entry.user %}
|
{% set u = entry.user %}
|
||||||
{% set p = entry.pass | replace("'", "''") %}
|
{% set p = entry.pass | replace("'", "''") %}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
|
||||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
|
||||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
|
||||||
# Elastic License 2.0.
|
|
||||||
|
|
||||||
{# Fires on salt/key. Only act on successful key acceptance — not reauth. #}
|
|
||||||
{% if data.get('act') == 'accept' and data.get('result') == True and data.get('id') %}
|
|
||||||
|
|
||||||
{{ data['id'] }}_telegraf_pg_sync:
|
|
||||||
runner.state.orchestrate:
|
|
||||||
- args:
|
|
||||||
- mods: orch.telegraf_postgres_sync
|
|
||||||
- pillar:
|
|
||||||
postgres_fanout_minion: {{ data['id'] }}
|
|
||||||
|
|
||||||
{% do salt.log.info('telegraf_user_sync reactor: syncing telegraf PG user for minion %s' % data['id']) %}
|
|
||||||
|
|
||||||
{% endif %}
|
|
||||||
@@ -62,19 +62,6 @@ engines_config:
|
|||||||
- name: /etc/salt/master.d/engines.conf
|
- name: /etc/salt/master.d/engines.conf
|
||||||
- source: salt://salt/files/engines.conf
|
- source: salt://salt/files/engines.conf
|
||||||
|
|
||||||
reactor_config_telegraf:
|
|
||||||
file.managed:
|
|
||||||
- name: /etc/salt/master.d/reactor_telegraf.conf
|
|
||||||
- contents: |
|
|
||||||
reactor:
|
|
||||||
- 'salt/key':
|
|
||||||
- /opt/so/saltstack/default/salt/reactor/telegraf_user_sync.sls
|
|
||||||
- user: root
|
|
||||||
- group: root
|
|
||||||
- mode: 644
|
|
||||||
- watch_in:
|
|
||||||
- service: salt_master_service
|
|
||||||
|
|
||||||
# update the bootstrap script when used for salt-cloud
|
# update the bootstrap script when used for salt-cloud
|
||||||
salt_bootstrap_cloud:
|
salt_bootstrap_cloud:
|
||||||
file.managed:
|
file.managed:
|
||||||
|
|||||||
@@ -10,12 +10,12 @@
|
|||||||
{%- set LOGSTASH_ENABLED = LOGSTASH_MERGED.enabled %}
|
{%- set LOGSTASH_ENABLED = LOGSTASH_MERGED.enabled %}
|
||||||
{%- set TG_OUT = TELEGRAFMERGED.output | upper %}
|
{%- set TG_OUT = TELEGRAFMERGED.output | upper %}
|
||||||
{%- set PG_HOST = GLOBALS.manager_ip %}
|
{%- set PG_HOST = GLOBALS.manager_ip %}
|
||||||
{#- Per-minion telegraf creds are written into the minion's own pillar file
|
{#- Per-minion telegraf creds live in the grid-wide telegraf/creds.sls pillar,
|
||||||
(/opt/so/saltstack/local/pillar/minions/<id>.sls) by postgres.auth on the
|
written by /usr/sbin/so-telegraf-cred on the manager. Each minion looks up
|
||||||
manager. Each minion only sees its own password — the aggregate map in
|
its own entry by grains.id. #}
|
||||||
postgres:auth:users is manager-scoped. #}
|
{%- set PG_ENTRY = salt['pillar.get']('telegraf:postgres_creds:' ~ grains.id, {}) %}
|
||||||
{%- set PG_USER = salt['pillar.get']('postgres:telegraf:user', '') %}
|
{%- set PG_USER = PG_ENTRY.get('user', '') %}
|
||||||
{%- set PG_PASS = salt['pillar.get']('postgres:telegraf:pass', '') %}
|
{%- set PG_PASS = PG_ENTRY.get('pass', '') %}
|
||||||
# Global tags can be specified here in key="value" format.
|
# Global tags can be specified here in key="value" format.
|
||||||
[global_tags]
|
[global_tags]
|
||||||
role = "{{ GLOBALS.role.split('-') | last }}"
|
role = "{{ GLOBALS.role.split('-') | last }}"
|
||||||
@@ -96,7 +96,7 @@
|
|||||||
# insecure_skip_verify = false
|
# insecure_skip_verify = false
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- if TG_OUT in ['POSTGRES', 'BOTH'] %}
|
{%- if TG_OUT in ['POSTGRES', 'BOTH'] and PG_USER and PG_PASS %}
|
||||||
# Configuration for sending metrics to PostgreSQL.
|
# Configuration for sending metrics to PostgreSQL.
|
||||||
# options='-c role=so_telegraf' makes every connection SET ROLE to the shared
|
# options='-c role=so_telegraf' makes every connection SET ROLE to the shared
|
||||||
# group role so tables created on first write are owned by so_telegraf, and
|
# group role so tables created on first write are owned by so_telegraf, and
|
||||||
|
|||||||
Reference in New Issue
Block a user