Compare commits

..
Author SHA1 Message Date
Josh Patterson aba2f5ea43 FIX: retry the push orchestration's refresh_pillar step
Holding dispatch in the drainer cannot help an orchestration that is
already running when salt-master restarts: its first action raises, and
the next action's refresh_pillar is published seconds after the restart,
before minions have rejoined the publisher, so it fails with "No minions
responded".

refresh_pillar now retries (3 attempts, 10s apart; a failed attempt takes
about 15s to time out, so the later attempts land after the reconnect
window). It also runs ahead of highstate actions, which now require it,
so they get the same reachability check. Retrying the highstate step
itself is not an option because it would re-run a fleetwide highstate
whenever any state failed.

Run straight after a salt-master restart on a standalone 3.5.0 install,
the orchestration previously failed with "No minions responded"; it now
succeeds on the second attempt. A target that is genuinely offline takes
about 65s to fail instead of 15s.
2026-11-18 10:27:34 -05:00
Josh Patterson 65816ae717 FIX: hold push dispatch while salt-master has only just started
A push dispatched seconds after a salt-master restart was lost: minions
rejoin the new publisher on a randomized ZeroMQ reconnect delay (up to
~22s with the default recon_default/recon_max), and a job published
before then reaches nobody. The orchestration's refresh_pillar step timed
out with "No minions responded", the drainer logged "push failed" as an
ERROR, and so-log-check failed the run.

Seen on a standalone 3.5.0 install: a highstate restarted salt-master
(new reactor/engine config), the drainer dispatched a soc push 8s later,
and the job cache shows the refresh_pillar job matched the minion but got
no return. Measured on the same host over five restarts, jobs published
in the first 4-9s were lost every time.

The drainer now leaves ready intents in place for a later pass while
/var/run/salt-master.pid is less than 45s old. On a multi-node grid this
also avoids a batch state run silently skipping the minions that have
not reconnected yet, since batch only sends the job to minions that
answer its ping.
2026-11-18 10:27:34 -05:00
12 changed files with 61 additions and 68 deletions

No files matched your search

+1 -2
View File
@@ -11,8 +11,7 @@
{% set DATA_RETENTION_METHOD = ELASTICSEARCHMERGED.data_retention_method %}
{% set PILLAR_GLOBAL_OVERRIDES = {} %}
{# merge into a copy: pillar.get returns a live reference and this map pops/updates ES_INDEX_PILLAR #}
{% set ES_INDEX_PILLAR = salt['defaults.merge'](salt['pillar.get']('elasticsearch:index_settings', {}), {}, in_place=False) %}
{% set ES_INDEX_PILLAR = salt['pillar.get']('elasticsearch:index_settings', {}) %}
{% if ES_INDEX_PILLAR.global_overrides is defined %}
{% set PILLAR_GLOBAL_OVERRIDES = ES_INDEX_PILLAR.pop('global_overrides') %}
{% endif %}
@@ -140,23 +140,7 @@
}
}
}
},
"dynamic_templates": [
{
"event_data_scalars_as_keyword": {
"path_match": "event_data.*",
"match_mapping_type": [
"long",
"double",
"boolean"
],
"mapping": {
"type": "keyword",
"ignore_above": 1024
}
}
}
]
}
}
},
"_meta": {
+19
View File
@@ -17,6 +17,7 @@ is older than debounce_seconds, this script:
* concatenates the actions lists from every ready intent
* dedupes by (state or __highstate__, tgt, tgt_type)
* drops actions whose target matches no accepted minion (e.g. a role with no nodes yet)
* holds everything for a later pass while salt-master has only just started
* dispatches a single `salt-run state.orchestrate orch.push_batch --async`
with the deduped actions list passed as pillar kwargs
* deletes the contributed intent files on successful dispatch
@@ -46,6 +47,12 @@ PENDING_DIR = '/opt/so/state/push_pending'
LOCK_FILE = os.path.join(PENDING_DIR, '.lock')
LOG_FILE = '/opt/so/log/salt/so-push-drainer.log'
MASTER_CONFIG = '/etc/salt/master'
MASTER_PIDFILE = '/var/run/salt-master.pid'
# Minions rejoin a restarted master's publisher up to ~22s after it returns (zmq reconnect interval
# plus jitter, each up to recon_default + recon_max) and a job published before then reaches nobody.
# Doubled to allow for a slow master start.
MASTER_SETTLE_SECONDS = 45
DISPATCHED_DIR = '/opt/so/state/push_dispatched'
@@ -140,6 +147,14 @@ def _targeted(actions, log):
return targeted
def _master_settling(now):
try:
age = now - os.path.getmtime(MASTER_PIDFILE)
except OSError:
return False
return 0 <= age < MASTER_SETTLE_SECONDS
def _dispatch(actions, log):
pillar_arg = json.dumps({'actions': actions})
cmd = [
@@ -410,6 +425,10 @@ def main():
log.debug('no ready intents (%d still in debounce window)', skipped)
return 0
if _master_settling(now):
log.info('salt-master just started; holding %d intent(s) until minions reconnect', len(ready))
return 0
combined_actions = []
oldest_first_touch = now
all_paths = []
@@ -199,6 +199,17 @@ class TestHelpers(DrainerTestCase):
drainer._unlink(self.tmpdir, self.log)
self.log.exception.assert_called_once()
def test_master_settling(self):
pidfile = os.path.join(self.tmpdir, 'salt-master.pid')
now = time.time()
with patch.object(drainer, 'MASTER_PIDFILE', pidfile):
self.assertFalse(drainer._master_settling(now))
self.write_json(self.tmpdir, 'salt-master.pid', '1100')
for age, settling in ((0, True), (drainer.MASTER_SETTLE_SECONDS - 1, True),
(drainer.MASTER_SETTLE_SECONDS, False), (-60, False)):
os.utime(pidfile, (now - age, now - age))
self.assertIs(drainer._master_settling(now), settling, age)
class TestDispatch(DrainerTestCase):
@@ -475,6 +486,7 @@ class TestMain(DrainerTestCase):
('_load_push_cfg', {'side_effect': lambda: self.cfg}),
('_check_dispatched', {}),
('_targeted', {'side_effect': lambda actions, log: actions}),
('_master_settling', {'return_value': False}),
):
patcher = patch.object(drainer, name, **kwargs)
setattr(self, name, patcher.start())
@@ -528,6 +540,16 @@ class TestMain(DrainerTestCase):
with patch.object(drainer.os, 'unlink', side_effect=OSError('busy')):
self.assertEqual(drainer.main(), 0)
def test_holds_while_master_settling(self):
path = self.intent('pillar_soc.json')
self._master_settling.return_value = True
with patch.object(drainer, '_dispatch') as dispatch:
self.assertEqual(drainer.main(), 0)
dispatch.assert_not_called()
self._check_dispatched.assert_called_once()
self.assertTrue(os.path.exists(path))
self.assertIn('holding 1 intent(s)', self.logged('info'))
def test_dispatch_failure_keeps_intents(self):
path = self.intent('pillar_soc.json')
with patch.object(drainer, '_dispatch', return_value=None):
-2
View File
@@ -1241,8 +1241,6 @@ remove_localrules_portgroup() {
post_to_3.5.0() {
telegraf_repair
rollover_index "logs-detections.alerts-so"
set_postversion 3.5.0
}
### 3.5.0 End ###
+13 -6
View File
@@ -4,8 +4,19 @@
{% set BATCH_WAIT = AUTOAPPLY.batch_wait %}
{# queue must be a top-level salt.state arg (kwarg is ignored); an int is max_queue and still fails on conflict #}
{# refresh_pillar doubles as the reachability check: minions take up to ~22s to rejoin a restarted master's
publisher, and a job published before then reaches nobody. Each failed attempt takes ~15s to time out. #}
{% for action in actions %}
refresh_pillar_{{ loop.index }}:
salt.function:
- name: saltutil.refresh_pillar
- tgt: '{{ action.tgt }}'
- tgt_type: {{ action.get('tgt_type', 'compound') }}
- retry:
attempts: 3
interval: 10
{% if action.get('highstate') %}
apply_highstate_{{ loop.index }}:
salt.state:
@@ -15,13 +26,9 @@ apply_highstate_{{ loop.index }}:
- batch: {{ action.get('batch', BATCH) }}
- batch_wait: {{ action.get('batch_wait', BATCH_WAIT) }}
- queue: True
- require:
- salt: refresh_pillar_{{ loop.index }}
{% else %}
refresh_pillar_{{ loop.index }}:
salt.function:
- name: saltutil.refresh_pillar
- tgt: '{{ action.tgt }}'
- tgt_type: {{ action.get('tgt_type', 'compound') }}
apply_{{ action.state | replace('.', '_') }}_{{ loop.index }}:
salt.state:
- tgt: '{{ action.tgt }}'
+1 -3
View File
@@ -19,8 +19,6 @@ so-redis:
docker_container.running:
- image: {{ GLOBALS.registry_host }}:5000/{{ GLOBALS.image_repo }}/so-redis:{{ GLOBALS.so_version }}
- restart_policy: unless-stopped
- shutdown_timeout: 180
- stop_timeout: 180
- hostname: so-redis
- user: socore
- networks:
@@ -62,7 +60,7 @@ so-redis:
- {{ ULIMIT.name }}={{ ULIMIT.soft }}:{{ ULIMIT.hard }}
{% endfor %}
{% endif %}
- entrypoint: "redis-server /usr/local/etc/redis/redis.conf --rdb-version-check relaxed"
- entrypoint: "redis-server /usr/local/etc/redis/redis.conf"
- watch:
- cmd: ca_trust_extract
- file: trusttheca
+1 -1
View File
@@ -18,7 +18,7 @@ include:
# Install the registry container
so-dockerregistry:
docker_container.running:
- image: ghcr.io/security-onion-solutions/registry:3.1.2
- image: ghcr.io/security-onion-solutions/registry:3.1.1
# Intentionally `always`-- registry is critical and must
# come back up even if it was manually stopped.
- restart_policy: always
-6
View File
@@ -1638,12 +1638,6 @@ soc:
- "user.effective.name"
- "weird.name"
- "tags"
queryNotifications:
defaultLimit: 10
maxLimit: 50
summaryMaxLength: 1000
fieldValueMaxLength: 200
maxEntries: 25
onionconfig:
saltstackDir: /opt/so/saltstack
bypassEnabled: false
-26
View File
@@ -1112,32 +1112,6 @@ soc:
description: A whitelist of fields to return when OnionAI uses the query_events tool. All other fields are removed. One field per line.
global: True
multiline: True
queryNotifications:
defaultLimit:
description: Number of notifications Onion AI reads with the query_notifications tool when it doesn't ask for a specific number. Must be greater than 0. Values above maxLimit use maxLimit.
global: True
advanced: True
forcedType: int
maxLimit:
description: Maximum number of notifications Onion AI may read with one query_notifications call. Must be greater than 0. Higher values put more notification text into the model's context.
global: True
advanced: True
forcedType: int
summaryMaxLength:
description: Maximum number of characters of each notification summary that query_notifications returns to Onion AI. Must be greater than 0. Longer summaries are shortened.
global: True
advanced: True
forcedType: int
fieldValueMaxLength:
description: Maximum number of characters of each notification field value that query_notifications returns to Onion AI. Must be greater than 0. Longer values are shortened. Link values are never shortened.
global: True
advanced: True
forcedType: int
maxEntries:
description: Maximum number of fields, of links, and of attachment names, each counted separately, per notification that query_notifications returns to Onion AI. Must be greater than 0. The result tells Onion AI how many were left out.
global: True
advanced: True
forcedType: int
client:
assistant:
enabled:
-2
View File
@@ -24,8 +24,6 @@ so-telegraf:
- environment:
- HOST_ETC=/host/etc
- HOST_SYS=/host/sys
- HOST_PROC=/host/proc
- HOST_PROC_MOUNTINFO=/proc/1
- HOST_MOUNT_PREFIX=/host
- GODEBUG=x509ignoreCN=0
{% if DOCKERMERGED.containers['so-telegraf'].extra_env %}
+3 -3
View File
@@ -9,9 +9,9 @@ export REDISCLI_AUTH={{ REDIS_PASS }}
# if this script isn't already running
if [[ ! "`pidof -x $(basename $0) -o %PPID`" ]]; then
UNPARSED=$(valkey-cli llen logstash:unparsed | awk '{print $1}')
PARSED=$(valkey-cli llen logstash:parsed | awk '{print $1}')
MEM_USED=$(valkey-cli info memory | grep used_memory_peak_perc | cut -d ":" -f2 | sed "s/%//")
UNPARSED=$(redis-cli llen logstash:unparsed | awk '{print $1}')
PARSED=$(redis-cli llen logstash:parsed | awk '{print $1}')
MEM_USED=$(redis-cli info memory | grep used_memory_peak_perc | cut -d ":" -f2 | sed "s/%//")
echo "redisqueue unparsed=$UNPARSED,parsed=$PARSED,mem_used=$MEM_USED"