index.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. .. _acl-eauth:
  2. ==============================
  3. External Authentication System
  4. ==============================
  5. Salt's External Authentication System (eAuth) allows for Salt to pass through
  6. command authorization to any external authentication system, such as PAM or LDAP.
  7. .. note::
  8. eAuth using the PAM external auth system requires salt-master to be run as
  9. root as this system needs root access to check authentication.
  10. External Authentication System Configuration
  11. ============================================
  12. The external authentication system allows for specific users to be granted
  13. access to execute specific functions on specific minions. Access is configured
  14. in the master configuration file and uses the :ref:`access control system
  15. <acl>`:
  16. .. code-block:: yaml
  17. external_auth:
  18. pam:
  19. thatch:
  20. - 'web*':
  21. - test.*
  22. - network.*
  23. steve|admin.*:
  24. - .*
  25. The above configuration allows the user ``thatch`` to execute functions in the
  26. test and network modules on the minions that match the web* target. User
  27. ``steve`` and the users whose logins start with ``admin``, are granted
  28. unrestricted access to minion commands.
  29. Salt respects the current PAM configuration in place, and uses the 'login'
  30. service to authenticate.
  31. .. note:: The PAM module does not allow authenticating as ``root``.
  32. .. note:: state.sls and state.highstate will return "Failed to authenticate!"
  33. if the request timeout is reached. Use -t flag to increase the timeout
  34. To allow access to :ref:`wheel modules <all-salt.wheel>` or :ref:`runner
  35. modules <all-salt.runners>` the following ``@`` syntax must be used:
  36. .. code-block:: yaml
  37. external_auth:
  38. pam:
  39. thatch:
  40. - '@wheel' # to allow access to all wheel modules
  41. - '@runner' # to allow access to all runner modules
  42. - '@jobs' # to allow access to the jobs runner and/or wheel module
  43. .. note::
  44. The runner/wheel markup is different, since there are no minions to scope the
  45. acl to.
  46. .. note::
  47. Globs will not match wheel or runners! They must be explicitly
  48. allowed with @wheel or @runner.
  49. .. warning::
  50. All users that have external authentication privileges are allowed to run
  51. :mod:`saltutil.findjob <salt.modules.saltutil.find_job>`. Be aware
  52. that this could inadvertently expose some data such as minion IDs.
  53. Matching syntax
  54. ---------------
  55. The structure of the ``external_auth`` dictionary can take the following
  56. shapes. User and function matches are exact matches, shell glob patterns or
  57. regular expressions; minion matches are compound targets.
  58. By user:
  59. .. code-block:: yaml
  60. external_auth:
  61. <eauth backend>:
  62. <user or group%>:
  63. - <regex to match function>
  64. By user, by minion:
  65. .. code-block:: yaml
  66. external_auth:
  67. <eauth backend>:
  68. <user or group%>:
  69. <minion compound target>:
  70. - <regex to match function>
  71. By user, by runner/wheel:
  72. .. code-block:: yaml
  73. external_auth:
  74. <eauth backend>:
  75. <user or group%>:
  76. <@runner or @wheel>:
  77. - <regex to match function>
  78. By user, by runner+wheel module:
  79. .. code-block:: yaml
  80. external_auth:
  81. <eauth backend>:
  82. <user or group%>:
  83. <@module_name>:
  84. - <regex to match function without module_name>
  85. Groups
  86. ------
  87. To apply permissions to a group of users in an external authentication system,
  88. append a ``%`` to the ID:
  89. .. code-block:: yaml
  90. external_auth:
  91. pam:
  92. admins%:
  93. - '*':
  94. - 'pkg.*'
  95. Limiting by function arguments
  96. ------------------------------
  97. Positional arguments or keyword arguments to functions can also be whitelisted.
  98. .. versionadded:: 2016.3.0
  99. .. code-block:: yaml
  100. external_auth:
  101. pam:
  102. my_user:
  103. - '*':
  104. - 'my_mod.*':
  105. args:
  106. - 'a.*'
  107. - 'b.*'
  108. kwargs:
  109. 'kwa': 'kwa.*'
  110. 'kwb': 'kwb'
  111. - '@runner':
  112. - 'runner_mod.*':
  113. args:
  114. - 'a.*'
  115. - 'b.*'
  116. kwargs:
  117. 'kwa': 'kwa.*'
  118. 'kwb': 'kwb'
  119. The rules:
  120. 1. The arguments values are matched as regexp.
  121. 2. If arguments restrictions are specified the only matched are allowed.
  122. 3. If an argument isn't specified any value is allowed.
  123. 4. To skip an arg use "everything" regexp ``.*``. I.e. if ``arg0`` and ``arg2``
  124. should be limited but ``arg1`` and other arguments could have any value use:
  125. .. code-block:: yaml
  126. args:
  127. - 'value0'
  128. - '.*'
  129. - 'value2'
  130. Usage
  131. =====
  132. The external authentication system can then be used from the command-line by
  133. any user on the same system as the master with the ``-a`` option:
  134. .. code-block:: bash
  135. $ salt -a pam web\* test.version
  136. The system will ask the user for the credentials required by the
  137. authentication system and then publish the command.
  138. .. _salt-token-generation:
  139. Tokens
  140. ------
  141. With external authentication alone, the authentication credentials will be
  142. required with every call to Salt. This can be alleviated with Salt tokens.
  143. Tokens are short term authorizations and can be easily created by just
  144. adding a ``-T`` option when authenticating:
  145. .. code-block:: bash
  146. $ salt -T -a pam web\* test.version
  147. Now a token will be created that has an expiration of 12 hours (by default).
  148. This token is stored in a file named ``salt_token`` in the active user's home
  149. directory.
  150. Once the token is created, it is sent with all subsequent communications.
  151. User authentication does not need to be entered again until the token expires.
  152. Token expiration time can be set in the Salt master config file.
  153. LDAP and Active Directory
  154. =========================
  155. .. note::
  156. LDAP usage requires that you have installed python-ldap.
  157. Salt supports both user and group authentication for LDAP (and Active Directory
  158. accessed via its LDAP interface)
  159. OpenLDAP and similar systems
  160. ----------------------------
  161. LDAP configuration happens in the Salt master configuration file.
  162. Server configuration values and their defaults:
  163. .. code-block:: yaml
  164. # Server to auth against
  165. auth.ldap.server: localhost
  166. # Port to connect via
  167. auth.ldap.port: 389
  168. # Use TLS when connecting
  169. auth.ldap.tls: False
  170. # Use STARTTLS when connecting
  171. auth.ldap.starttls: False
  172. # LDAP scope level, almost always 2
  173. auth.ldap.scope: 2
  174. # Server specified in URI format
  175. auth.ldap.uri: '' # Overrides .ldap.server, .ldap.port, .ldap.tls above
  176. # Verify server's TLS certificate
  177. auth.ldap.no_verify: False
  178. # Bind to LDAP anonymously to determine group membership
  179. # Active Directory does not allow anonymous binds without special configuration
  180. # In addition, if auth.ldap.anonymous is True, empty bind passwords are not permitted.
  181. auth.ldap.anonymous: False
  182. # FOR TESTING ONLY, this is a VERY insecure setting.
  183. # If this is True, the LDAP bind password will be ignored and
  184. # access will be determined by group membership alone with
  185. # the group memberships being retrieved via anonymous bind
  186. auth.ldap.auth_by_group_membership_only: False
  187. # Require authenticating user to be part of this Organizational Unit
  188. # This can be blank if your LDAP schema does not use this kind of OU
  189. auth.ldap.groupou: 'Groups'
  190. # Object Class for groups. An LDAP search will be done to find all groups of this
  191. # class to which the authenticating user belongs.
  192. auth.ldap.groupclass: 'posixGroup'
  193. # Unique ID attribute name for the user
  194. auth.ldap.accountattributename: 'memberUid'
  195. # These are only for Active Directory
  196. auth.ldap.activedirectory: False
  197. auth.ldap.persontype: 'person'
  198. auth.ldap.minion_stripdomains: []
  199. # Redhat Identity Policy Audit
  200. auth.ldap.freeipa: False
  201. Authenticating to the LDAP Server
  202. +++++++++++++++++++++++++++++++++
  203. There are two phases to LDAP authentication. First, Salt authenticates to search for a users' Distinguished Name
  204. and group membership. The user it authenticates as in this phase is often a special LDAP system user with
  205. read-only access to the LDAP directory. After Salt searches the directory to determine the actual user's DN
  206. and groups, it re-authenticates as the user running the Salt commands.
  207. If you are already aware of the structure of your DNs and permissions in your LDAP store are set such that
  208. users can look up their own group memberships, then the first and second users can be the same. To tell Salt this is
  209. the case, omit the ``auth.ldap.bindpw`` parameter. Note this is not the same thing as using an anonymous bind.
  210. Most LDAP servers will not permit anonymous bind, and as mentioned above, if `auth.ldap.anonymous` is False you
  211. cannot use an empty password.
  212. You can template the ``binddn`` like this:
  213. .. code-block:: yaml
  214. auth.ldap.basedn: dc=saltstack,dc=com
  215. auth.ldap.binddn: uid={{ username }},cn=users,cn=accounts,dc=saltstack,dc=com
  216. Salt will use the password entered on the salt command line in place of the bindpw.
  217. To use two separate users, specify the LDAP lookup user in the binddn directive, and include a bindpw like so
  218. .. code-block:: yaml
  219. auth.ldap.binddn: uid=ldaplookup,cn=sysaccounts,cn=etc,dc=saltstack,dc=com
  220. auth.ldap.bindpw: mypassword
  221. As mentioned before, Salt uses a filter to find the DN associated with a user. Salt
  222. substitutes the ``{{ username }}`` value for the username when querying LDAP
  223. .. code-block:: yaml
  224. auth.ldap.filter: uid={{ username }}
  225. Determining Group Memberships (OpenLDAP / non-Active Directory)
  226. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  227. For OpenLDAP, to determine group membership, one can specify an OU that contains
  228. group data. This is prepended to the basedn to create a search path. Then
  229. the results are filtered against ``auth.ldap.groupclass``, default
  230. ``posixGroup``, and the account's 'name' attribute, ``memberUid`` by default.
  231. .. code-block:: yaml
  232. auth.ldap.groupou: Groups
  233. Note that as of 2017.7, auth.ldap.groupclass can refer to either a groupclass or an objectClass.
  234. For some LDAP servers (notably OpenLDAP without the ``memberOf`` overlay enabled) to determine group
  235. membership we need to know both the ``objectClass`` and the ``memberUid`` attributes. Usually for these
  236. servers you will want a ``auth.ldap.groupclass`` of ``posixGroup`` and an ``auth.ldap.groupattribute`` of
  237. ``memberUid``.
  238. LDAP servers with the ``memberOf`` overlay will have entries similar to ``auth.ldap.groupclass: person`` and
  239. ``auth.ldap.groupattribute: memberOf``.
  240. When using the ``ldap('DC=domain,DC=com')`` eauth operator, sometimes the records returned
  241. from LDAP or Active Directory have fully-qualified domain names attached, while minion IDs
  242. instead are simple hostnames. The parameter below allows the administrator to strip
  243. off a certain set of domain names so the hostnames looked up in the directory service
  244. can match the minion IDs.
  245. .. code-block:: yaml
  246. auth.ldap.minion_stripdomains: ['.external.bigcorp.com', '.internal.bigcorp.com']
  247. Determining Group Memberships (Active Directory)
  248. ++++++++++++++++++++++++++++++++++++++++++++++++
  249. Active Directory handles group membership differently, and does not utilize the
  250. ``groupou`` configuration variable. AD needs the following options in
  251. the master config:
  252. .. code-block:: yaml
  253. auth.ldap.activedirectory: True
  254. auth.ldap.filter: sAMAccountName={{username}}
  255. auth.ldap.accountattributename: sAMAccountName
  256. auth.ldap.groupclass: group
  257. auth.ldap.persontype: person
  258. To determine group membership in AD, the username and password that is entered
  259. when LDAP is requested as the eAuth mechanism on the command line is used to
  260. bind to AD's LDAP interface. If this fails, then it doesn't matter what groups
  261. the user belongs to, he or she is denied access. Next, the ``distinguishedName``
  262. of the user is looked up with the following LDAP search:
  263. .. code-block:: text
  264. (&(<value of auth.ldap.accountattributename>={{username}})
  265. (objectClass=<value of auth.ldap.persontype>)
  266. )
  267. This should return a distinguishedName that we can use to filter for group
  268. membership. Then the following LDAP query is executed:
  269. .. code-block:: text
  270. (&(member=<distinguishedName from search above>)
  271. (objectClass=<value of auth.ldap.groupclass>)
  272. )
  273. .. code-block:: yaml
  274. external_auth:
  275. ldap:
  276. test_ldap_user:
  277. - '*':
  278. - test.ping
  279. To configure a LDAP group, append a ``%`` to the ID:
  280. .. code-block:: yaml
  281. external_auth:
  282. ldap:
  283. test_ldap_group%:
  284. - '*':
  285. - test.echo
  286. In addition, if there are a set of computers in the directory service that should
  287. be part of the eAuth definition, they can be specified like this:
  288. .. code-block:: yaml
  289. external_auth:
  290. ldap:
  291. test_ldap_group%:
  292. - ldap('DC=corp,DC=example,DC=com'):
  293. - test.echo
  294. The string inside ``ldap()`` above is any valid LDAP/AD tree limiter. ``OU=`` in
  295. particular is permitted as long as it would return a list of computer objects.