Skip to content

Make whitelist_modules only apply to remote dispatch - #69974

Merged
dwoz merged 1 commit into
saltstack:3008.xfrom
dwoz:sectest
Aug 11, 2026
Merged

Make whitelist_modules only apply to remote dispatch#69974
dwoz merged 1 commit into
saltstack:3008.xfrom
dwoz:sectest

Conversation

@dwoz

@dwoz dwoz commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Closes #69983

What this changes

Splits the minion module loader into two views of the same set of modules:

  • An outer, whitelist-filtered loader used for wire dispatch. A minion
    with whitelist_modules: [test, mycompany, saltutil] will refuse a
    remote publish of any module not in that list.
  • An inner, unfiltered loader that is packed as __salt__ inside every
    loaded module. So mycompany.deploy can still do __salt__["cmd.run"](...)
    internally even when cmd is off the whitelist.

Combined with the existing per-command cmd_blacklist_glob, this gives a
useful defense-in-depth story for minions that don't fully trust the master:

  • Whitelist [test, mycompany, saltutil, cmd] off → master can't publish
    arbitrary cmd.run calls
  • cmd_blacklist_glob: ["*rm -rf*"] → even calls that reach cmd (through
    internal composition or if cmd is later whitelisted) refuse specific
    dangerous strings

Adjacent fixes

  • salt/modules/saltcheck.py: moves the __context__["global_scheck"] = None
    initialisation out of module-level code and into __init__(opts) with
    setdefault. The old pattern re-ran on every exec_module and clobbered
    state that a running function had already set — exposed by the two-loader
    work above, but a pre-existing violation of the __context__ usage the
    developing-modules docs prescribe (check-then-populate).
  • salt/utils/optsdict.py: caches the per-key DictProxy/ListProxy
    instead of allocating a new one on every read. opts["grains"] drops from
    413 ns to 208 ns per read; no allocation churn on hot loops.

Tests

New:

  • tests/pytests/integration/loader/test_module_whitelist_dunder.py — 5
    tests covering direct-wire block, whitelisted-module reaches
    non-whitelisted via __salt__, and SLS render still respects whitelist
  • tests/pytests/integration/renderers/test_renderer_whitelist.py — 2
    tests for the renderer_whitelist setting (defense in depth against
    #!py in SLS)

Broader-slice local run (tests/pytests/unit/loader/,
tests/pytests/functional/loader/, tests/pytests/integration/{loader,renderers,minion,states}/,
tests/pytests/functional/modules/state/, tests/integration/modules/test_saltcheck.py):
401 passed, 23 skipped, 1 unrelated env-permission failure
(test_directory_recurse calls chown -h nobody as unprivileged user).

Historical context

@dwoz
dwoz requested a review from a team as a code owner August 8, 2026 08:21
@dwoz dwoz added the test:full Run the full test suite label Aug 8, 2026
@dwoz
dwoz merged commit ccecccf into saltstack:3008.x Aug 11, 2026
1413 of 1417 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants