index.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. .. _pillar:
  2. =================================
  3. Storing Static Data in the Pillar
  4. =================================
  5. Pillar is an interface for Salt designed to offer global values that can be
  6. distributed to minions. Pillar data is managed in a similar way as
  7. the Salt State Tree.
  8. Pillar was added to Salt in version 0.9.8
  9. .. note:: Storing sensitive data
  10. Pillar data is compiled on the master. Additionally, pillar data for a
  11. given minion is only accessible by the minion for which it is targeted in
  12. the pillar configuration. This makes pillar useful for storing sensitive
  13. data specific to a particular minion.
  14. Declaring the Master Pillar
  15. ===========================
  16. The Salt Master server maintains a :conf_master:`pillar_roots` setup that
  17. matches the structure of the :conf_master:`file_roots` used in the Salt file
  18. server. Like :conf_master:`file_roots`, the :conf_master:`pillar_roots` option
  19. maps environments to directories. The pillar data is then mapped to minions
  20. based on matchers in a top file which is laid out in the same way as the state
  21. top file. Salt pillars can use the same matcher types as the standard :ref:`top
  22. file <states-top>`.
  23. conf_master:`pillar_roots` is configured just like :conf_master:`file_roots`.
  24. For example:
  25. .. code-block:: yaml
  26. pillar_roots:
  27. base:
  28. - /srv/pillar
  29. This example configuration declares that the base environment will be located
  30. in the ``/srv/pillar`` directory. It must not be in a subdirectory of the
  31. state tree.
  32. The top file used matches the name of the top file used for States,
  33. and has the same structure:
  34. ``/srv/pillar/top.sls``
  35. .. code-block:: yaml
  36. base:
  37. '*':
  38. - packages
  39. In the above top file, it is declared that in the ``base`` environment, the
  40. glob matching all minions will have the pillar data found in the ``packages``
  41. pillar available to it. Assuming the ``pillar_roots`` value of ``/srv/pillar``
  42. taken from above, the ``packages`` pillar would be located at
  43. ``/srv/pillar/packages.sls``.
  44. Any number of matchers can be added to the base environment. For example, here
  45. is an expanded version of the Pillar top file stated above:
  46. /srv/pillar/top.sls:
  47. .. code-block:: yaml
  48. base:
  49. '*':
  50. - packages
  51. 'web*':
  52. - vim
  53. In this expanded top file, minions that match ``web*`` will have access to the
  54. ``/srv/pillar/packages.sls`` file, as well as the ``/srv/pillar/vim.sls`` file.
  55. Another example shows how to use other standard top matching types
  56. to deliver specific salt pillar data to minions with different properties.
  57. Here is an example using the ``grains`` matcher to target pillars to minions
  58. by their ``os`` grain:
  59. .. code-block:: yaml
  60. dev:
  61. 'os:Debian':
  62. - match: grain
  63. - servers
  64. ``/srv/pillar/packages.sls``
  65. .. code-block:: jinja
  66. {% if grains['os'] == 'RedHat' %}
  67. apache: httpd
  68. git: git
  69. {% elif grains['os'] == 'Debian' %}
  70. apache: apache2
  71. git: git-core
  72. {% endif %}
  73. company: Foo Industries
  74. .. important::
  75. See :ref:`Is Targeting using Grain Data Secure? <faq-grain-security>` for
  76. important security information.
  77. The above pillar sets two key/value pairs. If a minion is running RedHat, then
  78. the ``apache`` key is set to ``httpd`` and the ``git`` key is set to the value
  79. of ``git``. If the minion is running Debian, those values are changed to
  80. ``apache2`` and ``git-core`` respectively. All minions that have this pillar
  81. targeting to them via a top file will have the key of ``company`` with a value
  82. of ``Foo Industries``.
  83. Consequently this data can be used from within modules, renderers, State SLS
  84. files, and more via the shared pillar dictionary:
  85. .. code-block:: jinja
  86. apache:
  87. pkg.installed:
  88. - name: {{ pillar['apache'] }}
  89. .. code-block:: jinja
  90. git:
  91. pkg.installed:
  92. - name: {{ pillar['git'] }}
  93. Finally, the above states can utilize the values provided to them via Pillar.
  94. All pillar values targeted to a minion are available via the 'pillar'
  95. dictionary. As seen in the above example, Jinja substitution can then be
  96. utilized to access the keys and values in the Pillar dictionary.
  97. Note that you cannot just list key/value-information in ``top.sls``. Instead,
  98. target a minion to a pillar file and then list the keys and values in the
  99. pillar. Here is an example top file that illustrates this point:
  100. .. code-block:: yaml
  101. base:
  102. '*':
  103. - common_pillar
  104. And the actual pillar file at '/srv/pillar/common_pillar.sls':
  105. .. code-block:: yaml
  106. foo: bar
  107. boo: baz
  108. .. note::
  109. When working with multiple pillar environments, assuming that each pillar
  110. environment has its own top file, the jinja placeholder ``{{ saltenv }}``
  111. can be used in place of the environment name:
  112. .. code-block:: jinja
  113. {{ saltenv }}:
  114. '*':
  115. - common_pillar
  116. Yes, this is ``{{ saltenv }}``, and not ``{{ pillarenv }}``. The reason for
  117. this is because the Pillar top files are parsed using some of the same code
  118. which parses top files when :ref:`running states <running-highstate>`, so
  119. the pillar environment takes the place of ``{{ saltenv }}`` in the jinja
  120. context.
  121. Dynamic Pillar Environments
  122. ===========================
  123. If environment ``__env__`` is specified in :conf_master:`pillar_roots`, all
  124. environments that are not explicitly specified in :conf_master:`pillar_roots`
  125. will map to the directories from ``__env__``. This allows one to use dynamic
  126. git branch based environments for state/pillar files with the same file-based
  127. pillar applying to all environments. For example:
  128. .. code-block:: yaml
  129. pillar_roots:
  130. __env__:
  131. - /srv/pillar
  132. ext_pillar:
  133. - git:
  134. - __env__ https://example.com/git-pillar.git
  135. .. versionadded:: 2017.7.5,2018.3.1
  136. Pillar Namespace Flattening
  137. ===========================
  138. The separate pillar SLS files all merge down into a single dictionary of
  139. key-value pairs. When the same key is defined in multiple SLS files, this can
  140. result in unexpected behavior if care is not taken to how the pillar SLS files
  141. are laid out.
  142. For example, given a ``top.sls`` containing the following:
  143. .. code-block:: yaml
  144. base:
  145. '*':
  146. - packages
  147. - services
  148. with ``packages.sls`` containing:
  149. .. code-block:: yaml
  150. bind: bind9
  151. and ``services.sls`` containing:
  152. .. code-block:: yaml
  153. bind: named
  154. Then a request for the ``bind`` pillar key will only return ``named``. The
  155. ``bind9`` value will be lost, because ``services.sls`` was evaluated later.
  156. .. note::
  157. Pillar files are applied in the order they are listed in the top file.
  158. Therefore conflicting keys will be overwritten in a 'last one wins' manner!
  159. For example, in the above scenario conflicting key values in ``services``
  160. will overwrite those in ``packages`` because it's at the bottom of the list.
  161. It can be better to structure your pillar files with more hierarchy. For
  162. example the ``package.sls`` file could be configured like so:
  163. .. code-block:: yaml
  164. packages:
  165. bind: bind9
  166. This would make the ``packages`` pillar key a nested dictionary containing a
  167. ``bind`` key.
  168. Pillar Dictionary Merging
  169. =========================
  170. If the same pillar key is defined in multiple pillar SLS files, and the keys in
  171. both files refer to nested dictionaries, then the content from these
  172. dictionaries will be recursively merged.
  173. For example, keeping the ``top.sls`` the same, assume the following
  174. modifications to the pillar SLS files:
  175. ``packages.sls``:
  176. .. code-block:: yaml
  177. bind:
  178. package-name: bind9
  179. version: 9.9.5
  180. ``services.sls``:
  181. .. code-block:: yaml
  182. bind:
  183. port: 53
  184. listen-on: any
  185. The resulting pillar dictionary will be:
  186. .. code-block:: bash
  187. $ salt-call pillar.get bind
  188. local:
  189. ----------
  190. listen-on:
  191. any
  192. package-name:
  193. bind9
  194. port:
  195. 53
  196. version:
  197. 9.9.5
  198. Since both pillar SLS files contained a ``bind`` key which contained a nested
  199. dictionary, the pillar dictionary's ``bind`` key contains the combined contents
  200. of both SLS files' ``bind`` keys.
  201. .. _pillar-include:
  202. Including Other Pillars
  203. =======================
  204. .. versionadded:: 0.16.0
  205. Pillar SLS files may include other pillar files, similar to State files. Two
  206. syntaxes are available for this purpose. The simple form simply includes the
  207. additional pillar as if it were part of the same file:
  208. .. code-block:: yaml
  209. include:
  210. - users
  211. The full include form allows two additional options -- passing default values
  212. to the templating engine for the included pillar file as well as an optional
  213. key under which to nest the results of the included pillar:
  214. .. code-block:: yaml
  215. include:
  216. - users:
  217. defaults:
  218. sudo: ['bob', 'paul']
  219. key: users
  220. With this form, the included file (users.sls) will be nested within the 'users'
  221. key of the compiled pillar. Additionally, the 'sudo' value will be available
  222. as a template variable to users.sls.
  223. .. _pillar-in-memory:
  224. In-Memory Pillar Data vs. On-Demand Pillar Data
  225. ===============================================
  226. Since compiling pillar data is computationally expensive, the minion will
  227. maintain a copy of the pillar data in memory to avoid needing to ask the master
  228. to recompile and send it a copy of the pillar data each time pillar data is
  229. requested. This in-memory pillar data is what is returned by the
  230. :py:func:`pillar.item <salt.modules.pillar.item>`, :py:func:`pillar.get
  231. <salt.modules.pillar.get>`, and :py:func:`pillar.raw <salt.modules.pillar.raw>`
  232. functions.
  233. Also, for those writing custom execution modules, or contributing to Salt's
  234. existing execution modules, the in-memory pillar data is available as the
  235. ``__pillar__`` dunder dictionary.
  236. The in-memory pillar data is generated on minion start, and can be refreshed
  237. using the :py:func:`saltutil.refresh_pillar
  238. <salt.modules.saltutil.refresh_pillar>` function:
  239. .. code-block:: bash
  240. salt '*' saltutil.refresh_pillar
  241. This function triggers the minion to asynchronously refresh the in-memory
  242. pillar data and will always return ``None``.
  243. In contrast to in-memory pillar data, certain actions trigger pillar data to be
  244. compiled to ensure that the most up-to-date pillar data is available. These
  245. actions include:
  246. - Running states
  247. - Running :py:func:`pillar.items <salt.modules.pillar.items>`
  248. Performing these actions will *not* refresh the in-memory pillar data. So, if
  249. pillar data is modified, and then states are run, the states will see the
  250. updated pillar data, but :py:func:`pillar.item <salt.modules.pillar.item>`,
  251. :py:func:`pillar.get <salt.modules.pillar.get>`, and :py:func:`pillar.raw
  252. <salt.modules.pillar.raw>` will not see this data unless refreshed using
  253. :py:func:`saltutil.refresh_pillar <salt.modules.saltutil.refresh_pillar>`.
  254. .. _pillar-environments:
  255. How Pillar Environments Are Handled
  256. ===================================
  257. When multiple pillar environments are used, the default behavior is for the
  258. pillar data from all environments to be merged together. The pillar dictionary
  259. will therefore contain keys from all configured environments.
  260. The :conf_minion:`pillarenv` minion config option can be used to force the
  261. minion to only consider pillar configuration from a single environment. This
  262. can be useful in cases where one needs to run states with alternate pillar
  263. data, either in a testing/QA environment or to test changes to the pillar data
  264. before pushing them live.
  265. For example, assume that the following is set in the minion config file:
  266. .. code-block:: yaml
  267. pillarenv: base
  268. This would cause that minion to ignore all other pillar environments besides
  269. ``base`` when compiling the in-memory pillar data. Then, when running states,
  270. the ``pillarenv`` CLI argument can be used to override the minion's
  271. :conf_minion:`pillarenv` config value:
  272. .. code-block:: bash
  273. salt '*' state.apply mystates pillarenv=testing
  274. The above command will run the states with pillar data sourced exclusively from
  275. the ``testing`` environment, without modifying the in-memory pillar data.
  276. .. note::
  277. When running states, the ``pillarenv`` CLI option does not require a
  278. :conf_minion:`pillarenv` option to be set in the minion config file. When
  279. :conf_minion:`pillarenv` is left unset, as mentioned above all configured
  280. environments will be combined. Running states with ``pillarenv=testing`` in
  281. this case would still restrict the states' pillar data to just that of the
  282. ``testing`` pillar environment.
  283. Starting in the 2017.7.0 release, it is possible to pin the pillarenv to the
  284. effective saltenv, using the :conf_minion:`pillarenv_from_saltenv` minion
  285. config option. When this is set to ``True``, if a specific saltenv is specified
  286. when running states, the ``pillarenv`` will be the same. This essentially makes
  287. the following two commands equivalent:
  288. .. code-block:: bash
  289. salt '*' state.apply mystates saltenv=dev
  290. salt '*' state.apply mystates saltenv=dev pillarenv=dev
  291. However, if a pillarenv is specified, it will override this behavior. So, the
  292. following command will use the ``qa`` pillar environment but source the SLS
  293. files from the ``dev`` saltenv:
  294. .. code-block:: bash
  295. salt '*' state.apply mystates saltenv=dev pillarenv=qa
  296. So, if a ``pillarenv`` is set in the minion config file,
  297. :conf_minion:`pillarenv_from_saltenv` will be ignored, and passing a
  298. ``pillarenv`` on the CLI will temporarily override
  299. :conf_minion:`pillarenv_from_saltenv`.
  300. Viewing Pillar Data
  301. ===================
  302. To view pillar data, use the :mod:`pillar <salt.modules.pillar>` execution
  303. module. This module includes several functions, each of them with their own
  304. use. These functions include:
  305. - :py:func:`pillar.item <salt.modules.pillar.item>` - Retrieves the value of
  306. one or more keys from the :ref:`in-memory pillar datj <pillar-in-memory>`.
  307. - :py:func:`pillar.items <salt.modules.pillar.items>` - Compiles a fresh pillar
  308. dictionary and returns it, leaving the :ref:`in-memory pillar data
  309. <pillar-in-memory>` untouched. If pillar keys are passed to this function
  310. however, this function acts like :py:func:`pillar.item
  311. <salt.modules.pillar.item>` and returns their values from the :ref:`in-memory
  312. pillar data <pillar-in-memory>`.
  313. - :py:func:`pillar.raw <salt.modules.pillar.raw>` - Like :py:func:`pillar.items
  314. <salt.modules.pillar.items>`, it returns the entire pillar dictionary, but
  315. from the :ref:`in-memory pillar data <pillar-in-memory>` instead of compiling
  316. fresh pillar data.
  317. - :py:func:`pillar.get <salt.modules.pillar.get>` - Described in detail below.
  318. The :py:func:`pillar.get <salt.modules.pillar.get>` Function
  319. ============================================================
  320. .. versionadded:: 0.14.0
  321. The :mod:`pillar.get <salt.modules.pillar.get>` function works much in the same
  322. way as the ``get`` method in a python dict, but with an enhancement: nested
  323. dictonaries can be traversed using a colon as a delimiter.
  324. If a structure like this is in pillar:
  325. .. code-block:: yaml
  326. foo:
  327. bar:
  328. baz: qux
  329. Extracting it from the raw pillar in an sls formula or file template is done
  330. this way:
  331. .. code-block:: jinja
  332. {{ pillar['foo']['bar']['baz'] }}
  333. Now, with the new :mod:`pillar.get <salt.modules.pillar.get>` function the data
  334. can be safely gathered and a default can be set, allowing the template to fall
  335. back if the value is not available:
  336. .. code-block:: jinja
  337. {{ salt['pillar.get']('foo:bar:baz', 'qux') }}
  338. This makes handling nested structures much easier.
  339. .. note:: ``pillar.get()`` vs ``salt['pillar.get']()``
  340. It should be noted that within templating, the ``pillar`` variable is just
  341. a dictionary. This means that calling ``pillar.get()`` inside of a
  342. template will just use the default dictionary ``.get()`` function which
  343. does not include the extra ``:`` delimiter functionality. It must be
  344. called using the above syntax (``salt['pillar.get']('foo:bar:baz',
  345. 'qux')``) to get the salt function, instead of the default dictionary
  346. behavior.
  347. Setting Pillar Data at the Command Line
  348. =======================================
  349. Pillar data can be set at the command line like the following example:
  350. .. code-block:: bash
  351. salt '*' state.apply pillar='{"cheese": "spam"}'
  352. This will add a pillar key of ``cheese`` with its value set to ``spam``.
  353. .. note::
  354. Be aware that when sending sensitive data via pillar on the command-line
  355. that the publication containing that data will be received by all minions
  356. and will not be restricted to the targeted minions. This may represent
  357. a security concern in some cases.
  358. .. _pillar-encryption:
  359. Pillar Encryption
  360. =================
  361. Salt's renderer system can be used to decrypt pillar data. This allows for
  362. pillar items to be stored in an encrypted state, and decrypted during pillar
  363. compilation.
  364. Encrypted Pillar SLS
  365. --------------------
  366. .. versionadded:: 2017.7.0
  367. Consider the following pillar SLS file:
  368. .. code-block:: yaml
  369. secrets:
  370. vault:
  371. foo: |
  372. -----BEGIN PGP MESSAGE-----
  373. hQEMAw2B674HRhwSAQgAhTrN8NizwUv/VunVrqa4/X8t6EUulrnhKcSeb8sZS4th
  374. W1Qz3K2NjL4lkUHCQHKZVx/VoZY7zsddBIFvvoGGfj8+2wjkEDwFmFjGE4DEsS74
  375. ZLRFIFJC1iB/O0AiQ+oU745skQkU6OEKxqavmKMrKo3rvJ8ZCXDC470+i2/Hqrp7
  376. +KWGmaDOO422JaSKRm5D9bQZr9oX7KqnrPG9I1+UbJyQSJdsdtquPWmeIpamEVHb
  377. VMDNQRjSezZ1yKC4kCWm3YQbBF76qTHzG1VlLF5qOzuGI9VkyvlMaLfMibriqY73
  378. zBbPzf6Bkp2+Y9qyzuveYMmwS4sEOuZL/PetqisWe9JGAWD/O+slQ2KRu9hNww06
  379. KMDPJRdyj5bRuBVE4hHkkP23KrYr7SuhW2vpe7O/MvWEJ9uDNegpMLhTWruGngJh
  380. iFndxegN9w==
  381. =bAuo
  382. -----END PGP MESSAGE-----
  383. bar: this was unencrypted already
  384. baz: |
  385. -----BEGIN PGP MESSAGE-----
  386. hQEMAw2B674HRhwSAQf+Ne+IfsP2IcPDrUWct8sTJrga47jQvlPCmO+7zJjOVcqz
  387. gLjUKvMajrbI/jorBWxyAbF+5E7WdG9WHHVnuoywsyTB9rbmzuPqYCJCe+ZVyqWf
  388. 9qgJ+oUjcvYIFmH3h7H68ldqbxaAUkAOQbTRHdr253wwaTIC91ZeX0SCj64HfTg7
  389. Izwk383CRWonEktXJpientApQFSUWNeLUWagEr/YPNFA3vzpPF5/Ia9X8/z/6oO2
  390. q+D5W5mVsns3i2HHbg2A8Y+pm4TWnH6mTSh/gdxPqssi9qIrzGQ6H1tEoFFOEq1V
  391. kJBe0izlfudqMq62XswzuRB4CYT5Iqw1c97T+1RqENJCASG0Wz8AGhinTdlU5iQl
  392. JkLKqBxcBz4L70LYWyHhYwYROJWjHgKAywX5T67ftq0wi8APuZl9olnOkwSK+wrY
  393. 1OZi
  394. =7epf
  395. -----END PGP MESSAGE-----
  396. qux:
  397. - foo
  398. - bar
  399. - |
  400. -----BEGIN PGP MESSAGE-----
  401. hQEMAw2B674HRhwSAQgAg1YCmokrweoOI1c9HO0BLamWBaFPTMblOaTo0WJLZoTS
  402. ksbQ3OJAMkrkn3BnnM/djJc5C7vNs86ZfSJ+pvE8Sp1Rhtuxh25EKMqGOn/SBedI
  403. gR6N5vGUNiIpG5Tf3DuYAMNFDUqw8uY0MyDJI+ZW3o3xrMUABzTH0ew+Piz85FDA
  404. YrVgwZfqyL+9OQuu6T66jOIdwQNRX2NPFZqvon8liZUPus5VzD8E5cAL9OPxQ3sF
  405. f7/zE91YIXUTimrv3L7eCgU1dSxKhhfvA2bEUi+AskMWFXFuETYVrIhFJAKnkFmE
  406. uZx+O9R9hADW3hM5hWHKH9/CRtb0/cC84I9oCWIQPdI+AaPtICxtsD2N8Q98hhhd
  407. 4M7I0sLZhV+4ZJqzpUsOnSpaGyfh1Zy/1d3ijJi99/l+uVHuvmMllsNmgR+ZTj0=
  408. =LrCQ
  409. -----END PGP MESSAGE-----
  410. When the pillar data is compiled, the results will be decrypted:
  411. .. code-block:: bash
  412. # salt myminion pillar.items
  413. myminion:
  414. ----------
  415. secrets:
  416. ----------
  417. vault:
  418. ----------
  419. bar:
  420. this was unencrypted already
  421. baz:
  422. rosebud
  423. foo:
  424. supersecret
  425. qux:
  426. - foo
  427. - bar
  428. - baz
  429. Salt must be told what portions of the pillar data to decrypt. This is done
  430. using the :conf_master:`decrypt_pillar` config option:
  431. .. code-block:: yaml
  432. decrypt_pillar:
  433. - 'secrets:vault': gpg
  434. The notation used to specify the pillar item(s) to be decrypted is the same as
  435. the one used in :py:func:`pillar.get <salt.modules.pillar.get>` function.
  436. If a different delimiter is needed, it can be specified using the
  437. :conf_master:`decrypt_pillar_delimiter` config option:
  438. .. code-block:: yaml
  439. decrypt_pillar:
  440. - 'secrets|vault': gpg
  441. decrypt_pillar_delimiter: '|'
  442. The name of the renderer used to decrypt a given pillar item can be omitted,
  443. and if so it will fall back to the value specified by the
  444. :conf_master:`decrypt_pillar_default` config option, which defaults to ``gpg``.
  445. So, the first example above could be rewritten as:
  446. .. code-block:: yaml
  447. decrypt_pillar:
  448. - 'secrets:vault'
  449. Encrypted Pillar Data on the CLI
  450. --------------------------------
  451. .. versionadded:: 2016.3.0
  452. The following functions support passing pillar data on the CLI via the
  453. ``pillar`` argument:
  454. - :py:func:`pillar.items <salt.modules.pillar.items>`
  455. - :py:func:`state.apply <salt.modules.state.apply_>`
  456. - :py:func:`state.highstate <salt.modules.state.highstate>`
  457. - :py:func:`state.sls <salt.modules.state.sls>`
  458. Triggerring decryption of this CLI pillar data can be done in one of two ways:
  459. 1. Using the ``pillar_enc`` argument:
  460. .. code-block:: bash
  461. # salt myminion pillar.items pillar_enc=gpg pillar='{foo: "-----BEGIN PGP MESSAGE-----\n\nhQEMAw2B674HRhwSAQf+OvPqEdDoA2fk15I5dYUTDoj1yf/pVolAma6iU4v8Zixn\nRDgWsaAnFz99FEiFACsAGDEFdZaVOxG80T0Lj+PnW4pVy0OXmXHnY2KjV9zx8FLS\nQxfvmhRR4t23WSFybozfMm0lsN8r1vfBBjbK+A72l0oxN78d1rybJ6PWNZiXi+aC\nmqIeunIbAKQ21w/OvZHhxH7cnIiGQIHc7N9nQH7ibyoKQzQMSZeilSMGr2abAHun\nmLzscr4wKMb+81Z0/fdBfP6g3bLWMJga3hSzSldU9ovu7KR8rDJI1qOlENj3Wm8C\nwTpDOB33kWIKMqiAjY3JFtb5MCHrafyggwQL7cX1+tI+AbSO6kZpbcDfzetb77LZ\nxc5NWnnGK4pGoqq4MAmZshw98RpecSHKMosto2gtiuWCuo9Zn5cV/FbjZ9CTWrQ=\n=0hO/\n-----END PGP MESSAGE-----"}'
  462. The newlines in this example are specified using a literal ``\n``. Newlines
  463. can be replaced with a literal ``\n`` using ``sed``:
  464. .. code-block:: bash
  465. $ echo -n bar | gpg --armor --trust-model always --encrypt -r user@domain.tld | sed ':a;N;$!ba;s/\n/\\n/g'
  466. .. note::
  467. Using ``pillar_enc`` will perform the decryption minion-side, so for
  468. this to work it will be necessary to set up the keyring in
  469. ``/etc/salt/gpgkeys`` on the minion just as one would typically do on
  470. the master. The easiest way to do this is to first export the keys from
  471. the master:
  472. .. code-block:: bash
  473. # gpg --homedir /etc/salt/gpgkeys --export-secret-key -a user@domain.tld >/tmp/keypair.gpg
  474. Then, copy the file to the minion, setup the keyring, and import:
  475. .. code-block:: bash
  476. # mkdir -p /etc/salt/gpgkeys
  477. # chmod 0700 /etc/salt/gpgkeys
  478. # gpg --homedir /etc/salt/gpgkeys --list-keys
  479. # gpg --homedir /etc/salt/gpgkeys --import --allow-secret-key-import keypair.gpg
  480. The ``--list-keys`` command is run create a keyring in the newly-created
  481. directory.
  482. Pillar data which is decrypted minion-side will still be securely
  483. transferred to the master, since the data sent between minion and master is
  484. encrypted with the master's public key.
  485. 2. Use the :conf_master:`decrypt_pillar` option. This is less flexible in that
  486. the pillar key passed on the CLI must be pre-configured on the master, but
  487. it doesn't require a keyring to be setup on the minion. One other caveat to
  488. this method is that pillar decryption on the master happens at the end of
  489. pillar compilation, so if the encrypted pillar data being passed on the CLI
  490. needs to be referenced by pillar or ext_pillar *during pillar compilation*,
  491. it *must* be decrypted minion-side.
  492. Adding New Renderers for Decryption
  493. -----------------------------------
  494. Those looking to add new renderers for decryption should look at the :mod:`gpg
  495. <salt.renderers.gpg>` renderer for an example of how to do so. The function
  496. that performs the decryption should be recursive and be able to traverse a
  497. mutable type such as a dictionary, and modify the values in-place.
  498. Once the renderer has been written, :conf_master:`decrypt_pillar_renderers`
  499. should be modified so that Salt allows it to be used for decryption.
  500. If the renderer is being submitted upstream to the Salt project, the renderer
  501. should be added in `salt/renderers/`_. Additionally, the following should be
  502. done:
  503. - Both occurrences of :conf_master:`decrypt_pillar_renderers` in
  504. `salt/config/__init__.py`_ should be updated to include the name of the new
  505. renderer so that it is included in the default value for this config option.
  506. - The documentation for the :conf_master:`decrypt_pillar_renderers` config
  507. option in the `master config file`_ and `minion config file`_ should be
  508. updated to show the correct new default value.
  509. - The commented example for the :conf_master:`decrypt_pillar_renderers` config
  510. option in the `master config template`_ should be updated to show the correct
  511. new default value.
  512. .. _`salt/renderers/`: https://github.com/saltstack/salt/tree/develop/salt/renderers/
  513. .. _`salt/config/__init__.py`: https://github.com/saltstack/salt/tree/develop/salt/config/__init__.py
  514. .. _`master config file`: https://github.com/saltstack/salt/tree/develop/doc/ref/configuration/master.rst
  515. .. _`minion config file`: https://github.com/saltstack/salt/tree/develop/doc/ref/configuration/minion.rst
  516. .. _`master config template`: https://github.com/saltstack/salt/tree/develop/conf/master
  517. Master Config in Pillar
  518. =======================
  519. For convenience the data stored in the master configuration file can be made
  520. available in all minion's pillars. This makes global configuration of services
  521. and systems very easy but may not be desired if sensitive data is stored in the
  522. master configuration. This option is disabled by default.
  523. To enable the master config from being added to the pillar set
  524. :conf_minion:`pillar_opts` to ``True`` in the minion config file:
  525. .. code-block:: yaml
  526. pillar_opts: True
  527. Minion Config in Pillar
  528. =======================
  529. Minion configuration options can be set on pillars. Any option that you want
  530. to modify, should be in the first level of the pillars, in the same way you set
  531. the options in the config file. For example, to configure the MySQL root
  532. password to be used by MySQL Salt execution module, set the following pillar
  533. variable:
  534. .. code-block:: yaml
  535. mysql.pass: hardtoguesspassword
  536. Master Provided Pillar Error
  537. ============================
  538. By default if there is an error rendering a pillar, the detailed error is
  539. hidden and replaced with:
  540. .. code-block:: bash
  541. Rendering SLS 'my.sls' failed. Please see master log for details.
  542. The error is protected because it's possible to contain templating data
  543. which would give that minion information it shouldn't know, like a password!
  544. To have the master provide the detailed error that could potentially carry
  545. protected data set ``pillar_safe_render_error`` to ``False``:
  546. .. code-block:: yaml
  547. pillar_safe_render_error: False
  548. .. toctree::
  549. ../tutorials/pillar