Skip to content

Commit 70cfbbd

Browse files
committed
refactor of pillar masking simplifying the whole thing
1 parent 5940bc4 commit 70cfbbd

52 files changed

Lines changed: 806 additions & 896 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/topics/tutorials/pillar.rst

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,6 @@ Arbitrary Data:
4040
so a key/value store can be defined making it easy to iterate over a group
4141
of values in sls formulas.
4242

43-
.. versionadded:: 3008
44-
45-
On the minion, compiled pillar is stored using :mod:`salt.utils.secret`
46-
containers: string and bytes leaves are wrapped with Pydantic ``SecretStr`` and
47-
``SecretBytes``, and mappings/lists use ``SecretDict`` / ``SecretList`` so later
48-
in-place updates stay wrapped. State returns and minion logs redact known pillar
49-
literals where possible. States may set ``no_log: true`` (runtime keyword, not
50-
passed to the state function) to mask that state's ``comment`` and ``changes``
51-
in output.
52-
53-
The execution functions ``pillar.raw`` and ``pillar.get`` are exceptions: they
54-
return plain Python strings, bytes, dicts, and lists (unwrapped) because the
55-
operator explicitly asked for pillar data. Other code paths use wrapped
56-
in-memory pillar unless they call those functions.
57-
5843
Pillar is therefore one of the most important systems when using Salt. This
5944
walkthrough is designed to get a simple Pillar up and running in a few minutes
6045
and then to dive into the capabilities of Pillar and where the data is

salt/cache/localfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_storage_id(kwargs):
4242
return ("localfs", __cachedir(kwargs))
4343

4444

45-
def store(bank, key, data, cachedir, **kwargs):
45+
def store(bank, key, data, cachedir):
4646
"""
4747
Store information in a file.
4848
"""

salt/client/ssh/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import salt.utils.path
4545
import salt.utils.platform
4646
import salt.utils.relenv
47-
import salt.utils.secret
4847
import salt.utils.stringutils
4948
import salt.utils.thin
5049
import salt.utils.timeutil
@@ -1653,7 +1652,7 @@ def _run_wfunc_thin(self):
16531652
if grains_updates:
16541653
opts["grains"] = {**opts["grains"], **grains_updates}
16551654

1656-
opts["pillar"] = salt.utils.secret.expose(data.get("pillar"))
1655+
opts["pillar"] = data.get("pillar")
16571656

16581657
# Restore --wipe. Note: Since it is also a CLI option, it should not
16591658
# be read from cache, hence it is restored here. This is currently only
@@ -1691,9 +1690,7 @@ def _run_wfunc_thin(self):
16911690
elif opts["pillar"] and self.fun in opts["pillar"].get(
16921691
"mine_functions", {}
16931692
):
1694-
mine_fun_data = salt.utils.secret.expose(
1695-
opts["pillar"]["mine_functions"][self.fun]
1696-
)
1693+
mine_fun_data = opts["pillar"]["mine_functions"][self.fun]
16971694
elif self.fun in self.context["master_opts"].get("mine_functions", {}):
16981695
mine_fun_data = self.context["master_opts"]["mine_functions"][self.fun]
16991696

salt/client/ssh/wrapper/config.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import salt.utils.data
1313
import salt.utils.files
1414
import salt.utils.sdb as sdb
15-
import salt.utils.secret
1615

1716
log = logging.getLogger(__name__)
1817

@@ -192,7 +191,7 @@ def option(
192191
return __grains__[value]
193192
if not omit_pillar:
194193
if value in __pillar__:
195-
return salt.utils.secret.expose(__pillar__[value])
194+
return __pillar__[value]
196195
if not omit_master:
197196
if value in __pillar__.get("master", {}):
198197
return __pillar__["master"][value]
@@ -207,7 +206,7 @@ def option(
207206
ret = {}
208207
for omit, data in (
209208
(omit_master, __pillar__.get("master", {})),
210-
(omit_pillar, salt.utils.secret.expose(__pillar__)),
209+
(omit_pillar, __pillar__),
211210
(omit_grains, __grains__),
212211
(omit_opts, __opts__),
213212
):
@@ -254,7 +253,7 @@ def merge(value, default="", omit_opts=False, omit_master=False, omit_pillar=Fal
254253
ret = list(ret) + list(tmp)
255254
if not omit_pillar:
256255
if value in __pillar__:
257-
tmp = salt.utils.secret.expose(__pillar__[value])
256+
tmp = __pillar__[value]
258257
if ret is None:
259258
ret = tmp
260259
if isinstance(ret, str):
@@ -436,17 +435,14 @@ def get(
436435

437436
if not omit_pillar:
438437
ret = salt.utils.data.traverse_dict_and_list(
439-
salt.utils.secret.expose(__pillar__), key, "_|-", delimiter=delimiter
438+
__pillar__, key, "_|-", delimiter=delimiter
440439
)
441440
if ret != "_|-":
442441
return sdb.sdb_get(ret, __opts__)
443442

444443
if not omit_master:
445444
ret = salt.utils.data.traverse_dict_and_list(
446-
__pillar__.get("master", {}),
447-
key,
448-
"_|-",
449-
delimiter=delimiter,
445+
__pillar__.get("master", {}), key, "_|-", delimiter=delimiter
450446
)
451447
if ret != "_|-":
452448
return sdb.sdb_get(ret, __opts__)
@@ -469,16 +465,10 @@ def get(
469465

470466
data = copy.copy(DEFAULTS)
471467
data = salt.utils.dictupdate.merge(
472-
data,
473-
__pillar__.get("master", {}),
474-
strategy=merge,
475-
merge_lists=merge_lists,
468+
data, __pillar__.get("master", {}), strategy=merge, merge_lists=merge_lists
476469
)
477470
data = salt.utils.dictupdate.merge(
478-
data,
479-
salt.utils.secret.expose(__pillar__),
480-
strategy=merge,
481-
merge_lists=merge_lists,
471+
data, __pillar__, strategy=merge, merge_lists=merge_lists
482472
)
483473
data = salt.utils.dictupdate.merge(
484474
data, __grains__, strategy=merge, merge_lists=merge_lists

salt/client/ssh/wrapper/cp.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import salt.client.ssh
3939
import salt.fileclient
4040
import salt.utils.files
41-
import salt.utils.secret
4241
import salt.utils.stringutils
4342
import salt.utils.templates
4443
from salt.exceptions import CommandExecutionError
@@ -206,7 +205,7 @@ def get_template(
206205
if "salt" not in kwargs:
207206
kwargs["salt"] = __salt__.value()
208207
if "pillar" not in kwargs:
209-
kwargs["pillar"] = salt.utils.secret.expose(__pillar__.value())
208+
kwargs["pillar"] = __pillar__.value()
210209
if "grains" not in kwargs:
211210
kwargs["grains"] = __grains__.value()
212211
if "opts" not in kwargs:
@@ -828,7 +827,7 @@ def _gather_pillar(pillarenv, pillar_override):
828827
pillar_override=pillar_override,
829828
pillarenv=pillarenv,
830829
)
831-
return salt.utils.secret.expose(pillar.compile_pillar())
830+
return pillar.compile_pillar()
832831

833832

834833
def _render_filenames(path, dest, saltenv, template, **kw):
@@ -852,7 +851,7 @@ def _render_filenames(path, dest, saltenv, template, **kw):
852851
pillarenv = kw.get("pillarenv", __opts__.get("pillarenv"))
853852
kwargs["pillar"] = _gather_pillar(pillarenv, kw.get("pillar"))
854853
else:
855-
kwargs["pillar"] = salt.utils.secret.expose(__pillar__.value())
854+
kwargs["pillar"] = __pillar__.value()
856855
kwargs["grains"] = __grains__.value()
857856
kwargs["opts"] = __opts__
858857
kwargs["saltenv"] = saltenv

salt/fileclient.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import salt.utils.http
3131
import salt.utils.path
3232
import salt.utils.platform
33-
import salt.utils.secret
3433
import salt.utils.stringutils
3534
import salt.utils.templates
3635
import salt.utils.url
@@ -1487,11 +1486,7 @@ def master_tops(self):
14871486
"""
14881487
Return the metadata derived from the master_tops system
14891488
"""
1490-
load = {
1491-
"cmd": "_master_tops",
1492-
"id": self.opts["id"],
1493-
"opts": salt.utils.secret.expose(self.opts),
1494-
}
1489+
load = {"cmd": "_master_tops", "id": self.opts["id"], "opts": self.opts}
14951490
return self._channel_send(
14961491
load,
14971492
)

salt/master.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import salt.utils.platform
5353
import salt.utils.process
5454
import salt.utils.schedule
55-
import salt.utils.secret
5655
import salt.utils.ssdp
5756
import salt.utils.stringutils
5857
import salt.utils.user
@@ -2105,7 +2104,7 @@ def _pillar(self, load):
21052104
{"Minion data cache refresh": load["id"]},
21062105
tagify(load["id"], "refresh", "minion"),
21072106
)
2108-
return salt.utils.secret.expose(data)
2107+
return data
21092108

21102109
def _minion_event(self, load):
21112110
"""

salt/matchers/pillar_exact_match.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import logging
66

77
import salt.utils.data
8-
import salt.utils.secret
98

109
log = logging.getLogger(__name__)
1110

@@ -32,7 +31,6 @@ def match(tgt, delimiter=":", opts=None, minion_id=None):
3231
else:
3332
pillar = {}
3433

35-
pillar = salt.utils.secret.expose(pillar)
3634
return salt.utils.data.subdict_match(
3735
pillar, tgt, delimiter=delimiter, exact_match=True
3836
)

salt/matchers/pillar_match.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import logging
66

77
import salt.utils.data
8-
import salt.utils.secret
98
from salt.defaults import DEFAULT_TARGET_DELIM
109

1110
log = logging.getLogger(__name__)
@@ -33,5 +32,4 @@ def match(tgt, delimiter=DEFAULT_TARGET_DELIM, opts=None, minion_id=None):
3332
else:
3433
pillar = {}
3534

36-
pillar = salt.utils.secret.expose(pillar)
3735
return salt.utils.data.subdict_match(pillar, tgt, delimiter=delimiter)

salt/matchers/pillar_pcre_match.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def match(tgt, delimiter=DEFAULT_TARGET_DELIM, opts=None, minion_id=None):
3434
else:
3535
pillar = {}
3636

37-
pillar = salt.utils.secret.expose(pillar)
3837
return salt.utils.data.subdict_match(
3938
pillar, tgt, delimiter=delimiter, regex_match=True
4039
)

0 commit comments

Comments
 (0)