[3008.x] Add whitelist_state_modules minion option - #70193
Open
dwoz wants to merge 1 commit into
Open
Conversation
dwoz
force-pushed
the
dwoz/feat/whitelist-state-modules
branch
from
August 30, 2026 22:21
e172fad to
20b4fe7
Compare
twangboy
previously approved these changes
Aug 31, 2026
Add a new ``whitelist_state_modules`` minion option that gates which
state modules the state loader will load, complementing the existing
``whitelist_modules`` (which gates execution modules) and
``renderer_whitelist`` (which gates renderers).
Motivation
----------
``whitelist_modules`` prevents wire callers from invoking non-permitted
execution modules -- ``salt <tgt> cmd.run 'id'`` is denied -- but an
SLS author with write access to the state tree can still write::
run_shell:
cmd.run: # <-- STATE module named cmd, function run
- name: id
...and ``state.apply`` executes it unconditionally. For VCF-style
hardening the operator needs a symmetric control over which state
modules are loadable.
Implementation
--------------
* ``salt.loader.states`` now reads ``whitelist_state_modules`` from
opts when the caller doesn't pass an explicit ``whitelist=``,
mirroring the pattern that ``salt.loader.minion_mods`` already uses
for ``whitelist_modules``. The value flows through to the
underlying LazyLoader as ``whitelist=`` unchanged; ``LazyLoader._load``
already enforces the gate.
* ``salt.config``: new ``whitelist_state_modules: list`` entry in the
minion opts type dict and a default of ``[]`` in
``DEFAULT_MINION_OPTS``. Empty list (the default) is falsy and
results in no filtering -- backward compatible with pre-fix minions.
* Documentation: ``conf/minion`` gains a commented-out example of the
new opt directly below the existing ``whitelist_modules`` block.
Behaviour
---------
* SLS referencing a whitelisted state module -> compiles + runs
normally.
* SLS referencing a non-whitelisted state module -> per-chunk result
is ``{"result": False, "comment": "Specified state '...' was not
found", "changes": {}}`` -- no silent execution.
* ``whitelist_modules`` and ``whitelist_state_modules`` are strictly
orthogonal: setting one does not affect the other's loader.
Coverage
--------
* ``tests/pytests/unit/loader/test_state_whitelist.py`` -- 4 tests
(opt flow, explicit-kwarg precedence, unset-means-no-filter,
orthogonality to whitelist_modules).
* ``tests/pytests/functional/loader/test_state_whitelist.py`` -- 8
tests (real state loader; whitelisted resolves, non-whitelisted
KeyError; compile + template-string paths for both; backcompat
when opt unset; cross-contamination check vs whitelist_modules).
* ``tests/pytests/integration/states/test_whitelist.py`` -- 4 tests
(real master + minion pair; wire ``state.apply`` of whitelisted
and non-whitelisted; wire dispatch of exec modules unaffected;
trusted composition still works).
Signed-off-by: Daniel A. Wozniak <daniel.wozniak@broadcom.com>
dwoz
force-pushed
the
dwoz/feat/whitelist-state-modules
branch
from
August 31, 2026 21:32
20b4fe7 to
c04c780
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a new
whitelist_state_modulesminion option that restricts which state modules the state loader will load, complementing:whitelist_modules— gates execution modules on the wirerenderer_whitelist— gates renderersMotivation
whitelist_modulesprevents wire callers from invoking non-permitted execution modules (salt <tgt> cmd.run 'id'is denied), but an SLS author with write access to the state tree can still write:…and
state.applyexecutes it unconditionally. For VCF-style hardening the operator needs a symmetric control over which state modules are loadable.Design (minimal — single feature)
whitelist_state_modules: [test, file, pkg, service, ...]in minion config. Case-sensitive module-name (not function-name) allowlist. Unset / empty list = no filtering (backward compat).salt.loader.statesnow reads the opt when the caller doesn't pass an explicitwhitelist=kwarg, mirroringsalt.loader.minion_mods's pattern forwhitelist_modules.LazyLoaderaswhitelist=unchanged;LazyLoader._loadalready enforces the gate.{"result": False, "comment": "Specified state '...' was not found", "changes": {}}— no silent execution.whitelist_modulesandwhitelist_state_modulesare strictly orthogonal.Diff scope
salt/loader/__init__.pystates()readsopts["whitelist_state_modules"]whenwhitelistnot passed.salt/config/__init__.pywhitelist_state_modules: listtype entry +[]default inDEFAULT_MINION_OPTS.conf/minionwhitelist_modules.changelog/vcops-90587-state-whitelist.added.md<PR#>.added.mdafter review).Total: ~30 lines of code + docs, 4 tests.
Test coverage (three tiers, no unit-only)
tests/pytests/unit/loader/test_state_whitelist.pytests/pytests/functional/loader/test_state_whitelist.pytests/pytests/integration/states/test_whitelist.pyThe integration tier boots a real salt-master + salt-minion pair, dispatches
state.applyfrom the wire, and verifies both the allow path and the deny path — including a canary-file check to prove the non-whitelistedcmd.runstate does NOT silently execute.Merge requirements satisfied?
conf/minion, docstring update onsalt.loader.states.changelog/vcops-90587-state-whitelist.added.md(rename to<PR#>.added.mdafter review).Commits signed with GPG?
No — DCO sign-off only (
Signed-off-by:trailer).Relation to PR #70192
Independent of PR #70192 (whitelist_modules two-loader completion). This PR is strictly additive; the two overlap on
salt.loader.states()'s function signature and can be rebased if #70192 merges first.