Debian Codegraph @

ansible_collections/microsoft/ad/docs/docsite/rst/guide_ad_module_authentication.rst

raw
1 .. _ansible_collections.microsoft.ad.docsite.guide_ad_module_authentication:
2
3 ****************************
4 AD Authentication in Modules
5 ****************************
6
7 A key requirement of the modules used inside this collection is being able to authenticate a user to the domain controller when managing a resource. This guide will cover the different options available for this scenario.
8
9 .. note::
10 This guide covers authentication to a domain controller when using a module on a Windows host. See :ref:`LDAP Authentication <ansible_collections.microsoft.ad.docsite.guide_ldap_connection.authentication>` for information on how authentication is done when using plugins running on Linux.
11
12 .. contents::
13 :local:
14 :depth: 1
15
16 .. _ansible_collections.microsoft.ad.docsite.guide_ad_module_authentication.implicit_auth:
17
18 Implicit Authentication
19 =======================
20
21 The first and simplest option is to use the connection user's existing credentials during authentication. This avoids having to specify a username and password in the module's parameters, but it does require that the connection method used by Ansible supports credential delegation. For example using CredSSP authentication with the ``winrm`` and ``psrp`` connection plugin, or using Kerberos delegation. Other authentication options, like NTLM, do not support credential delegation and will not work with implicit authentication.
22
23 The only way to test out if implicit authentication is available is to run the module and see if it works. If it does not work then the error will most likely contain the message ``Failed to contact the AD server``.
24
25 .. _ansible_collections.microsoft.ad.docsite.guide_ad_module_authentication.become:
26
27 Become
28 ======
29
30 If implicit authentication is not available, the module can be run with ``become`` that specifies the username and password to use for authentication.
31
32 .. code-block:: yaml
33
34 - name: Use become with connection credentials
35 microsoft.ad.user:
36 name: MyUser
37 state: present
38 become: true
39 become_method: runas
40 become_flags: logon_type=new_credentials logon_flags=netcredentials_only
41 vars:
42 ansible_become_user: '{{ ansible_user }}'
43 ansible_become_pass: '{{ ansible_password }}'
44
45 The ``runas`` method is used on Windows and the ``become_flags`` will specify that the credentials should be used for network authentication only. The ``ansible_become_user`` and ``ansible_become_pass`` variables specify the username and password to use for authentication. It is important that both of these variables are set to a valid username and password or else the authentication will fail.
46
47 It is also possible to use the ``SYSTEM`` account for become. This will have the module use the AD computer account for that host when authenticating with the target DC rather than an explicit username and password. The AD computer account must still have the required rights to perform the operation requested.
48
49 .. code-block:: yaml
50
51 - name: Use machine account for authentication
52 microsoft.ad.user:
53 name: MyUser
54 state: present
55 become: true
56 become_method: runas
57 become_user: SYSTEM
58
59 .. _ansible_collections.microsoft.ad.docsite.guide_ad_module_authentication.explicit_creds:
60
61 Explicit Credentials
62 ====================
63
64 The final option is to specify the username and password as module options. This can be done in two ways; with the ``domain_username`` and ``domain_password`` options, or with the ``domain_credentials`` option. An example of both methods is shown below.
65
66 .. code-block:: yaml
67
68 - name: Use domain_username and domain_password
69 microsoft.ad.user:
70 name: MyUser
71 state: present
72 domain_username: '{{ ansible_user }}'
73 domain_password: '{{ ansible_password }}'
74
75 - name: Use domain_credentials
76 name: MyUser
77 state: present
78 domain_credentials:
79 - username: '{{ ansible_user }}'
80 password: '{{ ansible_password }}'
81
82 .. note::
83 The ``domain_credentials`` option was added in version 1.6.0 of this collection.
84
85 The ``domain_credentials`` option without the ``name`` key, like in the above example, will be the credentials used for authentication with the default domain controller just like ``domain_username`` and ``domain_password``. Using both options together is not supported and will result in an error.
86
87 The ``domain_credentials`` option can also be used to specify server specific credentials. For example when attempting to lookup the identity of an AD object:
88
89 .. code-block:: yaml
90
91 - name: Set member with lookup on different server
92 microsoft.ad.group:
93 name: MyGroup
94 state: present
95 members:
96 add:
97 - GroupOnDefaultDC
98 - name: GroupOnDefaultDC2
99 - name: GroupOnOtherDC
100 server: OtherDC
101 - name: GroupOnThirdDC
102 server: ThirdDC
103 domain_credentials:
104 - username: UserForDefaultDC
105 password: PasswordForDefaultDC
106 - name: OtherDC
107 username: UserForOtherDC
108 password: PasswordForOtherDC
109
110 In the case above there are three members being added to the group:
111
112 * ``GroupOnDefaultDC`` - Will be looked up on the default domain controller using ``UserForDefaultDC`` and ``PasswordForDefaultDC``
113 * ``GroupOnDefaultDC2`` - Same as the above just specified as a dictionary
114 * ``GroupOnOtherDC`` - Will be looked up on ``OtherDC`` using ``UserForOtherDC`` and ``PasswordForOtherDC``
115 * ``GroupOnThirdDC`` - Will be looked up on ``ThirdDC`` using the implicit user authentication context
116
117 The value for ``server`` must correspond to a ``name`` entry in ``domain_credentials``. If the server is not specified in ``domain_credentials``, the module will default to using the ``domain_username/domain_password`` or implicit user authentication.
118
119 .. note::
120 The default (no ``name`` key) entry in ``domain_credentials`` is only used for lookups without an explicit server set. The ``domain_username`` and ``domain_password`` credential will be used for all connections unless there is an explicit server entry in ``domain_credentials``.