Debian Codegraph @

ansible_collections/microsoft/ad/plugins/modules/service_account.yml

raw
1 # Copyright: (c) 2024, Ansible Project
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3
4 DOCUMENTATION:
5 module: service_account
6 short_description: Manage Active Directory service account objects
7 description:
8 - Manages Active Directory service account objects and their attributes.
9 - Currently this module only supports group managed service accounts
10 (gMSA).
11 - Before creating a gMSA, the AD environment must have created a KDS root
12 key. See
13 L(KDS Key,https://learn.microsoft.com/en-us/windows-server/security/group-managed-service-accounts/create-the-key-distribution-services-kds-root-key)
14 for more details. For the key to be effective immediately, set the
15 effective time for 10 hours ago and do not use the
16 C(-EffectiveImmediately) parameter. See the examples for more details.
17 version_added: 1.7.0
18 options:
19 allowed_to_retrieve_password:
20 description:
21 - The principals that are allowed to retrieve the password for the
22 service account to either add, remove, or set.
23 - Each subkey value is a list of values in the form of a
24 C(distinguishedName), C(objectGUID), C(objectSid), c(sAMAccountName),
25 or C(userPrincipalName) string or a dictionary with the I(name) and
26 optional I(server) key.
27 - This value is built into a security descriptor by the ActiveDirectory
28 cmdlet and set on the C(msDS-GroupMSAMembership) LDAP attribute.
29 - This corresponds to the C(-PrincipalsAllowedToRetrieveManagedPassword)
30 parameter on the AD cmdlets.
31 - To clear all principals, use I(set) with an empty list.
32 - See
33 R(DN Lookup Attributes,ansible_collections.microsoft.ad.docsite.guide_attributes.dn_lookup_attributes)
34 for more information on how DN lookups work.
35 - See
36 R(Setting list option values,ansible_collections.microsoft.ad.docsite.guide_list_values)
37 for more information on how to add/remove/set list options.
38 type: dict
39 suboptions:
40 add:
41 description:
42 - Adds the principals specified as principals allowed to retrieve
43 the service account password.
44 - Any existing principals not specified by I(add) will be untouched
45 unless specified by I(remove) or not in I(set).
46 type: list
47 elements: raw
48 lookup_failure_action:
49 description:
50 - Control the action to take when the lookup fails to find the DN.
51 - C(fail) will cause the task to fail.
52 - C(ignore) will ignore the value and continue.
53 - C(warn) will ignore the value and display a warning.
54 choices:
55 - fail
56 - ignore
57 - warn
58 default: fail
59 type: str
60 remove:
61 description:
62 - Removes the principals specified as principals allowed to
63 retrieve the service account password.
64 - Any existing pricipals not specified by I(remove) will be
65 untouched unless I(set) is defined.
66 type: list
67 elements: raw
68 set:
69 description:
70 - Sets the principals specified as principals allowed to retrieve
71 the service account password.
72 - This will remove any existing principals if not specified in this
73 list.
74 - Specify an empty list to remove all principals allowed to
75 delegate.
76 type: list
77 elements: raw
78 delegates:
79 description:
80 - The principal objects that the current AD object can trust for
81 delegation to either add, remove or set.
82 - This is also known as resource-based constrained delegation.
83 - Each subkey value is a list of values in the form of a
84 C(distinguishedName), C(objectGUID), C(objectSid), C(sAMAccountName),
85 or C(userPrincipalName) string or a dictionary with the I(name) and
86 optional I(server) key.
87 - This is the value set on the
88 C(msDS-AllowedToActOnBehalfOfOtherIdentity) LDAP attribute.
89 - This is a highly sensitive attribute as it allows the principals
90 specified to impersonate any account when authenticating with a
91 service running as this managed account.
92 - To clear all principals, use I(set) with an empty list.
93 - See
94 R(DN Lookup Attributes,ansible_collections.microsoft.ad.docsite.guide_attributes.dn_lookup_attributes)
95 for more information on how DN lookups work.
96 - See
97 R(Setting list option values,ansible_collections.microsoft.ad.docsite.guide_list_values)
98 for more information on how to add/remove/set list options.
99 aliases:
100 - principals_allowed_to_delegate
101 type: dict
102 suboptions:
103 add:
104 description:
105 - Adds the principals specified as principals allowed to delegate
106 to.
107 - Any existing principals not specified by I(add) will be untouched
108 unless specified by I(remove) or not in I(set).
109 type: list
110 elements: raw
111 lookup_failure_action:
112 description:
113 - Control the action to take when the lookup fails to find the DN.
114 - C(fail) will cause the task to fail.
115 - C(ignore) will ignore the value and continue.
116 - C(warn) will ignore the value and display a warning.
117 choices:
118 - fail
119 - ignore
120 - warn
121 default: fail
122 type: str
123 remove:
124 description:
125 - Removes the principals specified as principals allowed to
126 delegate to.
127 - Any existing pricipals not specified by I(remove) will be
128 untouched unless I(set) is defined.
129 type: list
130 elements: raw
131 set:
132 description:
133 - Sets the principals specified as principals allowed to delegate
134 to.
135 - This will remove any existing principals if not specified in this
136 list.
137 - Specify an empty list to remove all principals allowed to
138 delegate.
139 type: list
140 elements: raw
141 dns_hostname:
142 description:
143 - Specifies the DNS name of the service account.
144 - This is the value set on the C(dNSHostName) LDAP attribute.
145 - This cannot be set when C(outbound_auth_only=True), otherwise it
146 must be defined.
147 type: str
148 do_not_append_dollar_to_sam:
149 description:
150 - Do not automatically append C($) to the I(sam_account_name) value.
151 - This only applies when I(sam_account_name) is explicitly set and can
152 be used to create a service account without the C($) suffix.
153 default: false
154 type: bool
155 enabled:
156 description:
157 - C(yes) will enable the service account.
158 - C(no) will disable the service account.
159 type: bool
160 kerberos_encryption_types:
161 description:
162 - Specifies the Kerberos encryption types supported the AD service
163 account.
164 - This is the value set on the C(msDS-SupportedEncryptionTypes) LDAP
165 attribute.
166 - Avoid using C(rc4) or C(des) as they are older an insecure encryption
167 protocols.
168 - To clear all encryption types, use I(set) with an empty list.
169 - See R(Setting list option values,ansible_collections.microsoft.ad.docsite.guide_list_values)
170 for more information on how to add/remove/set list options.
171 type: dict
172 suboptions:
173 add:
174 description:
175 - The encryption types to add to the existing set.
176 - Any existing encryption types not specified by I(add) will be
177 untouched unless specified by I(remove) or not in I(set).
178 choices:
179 - aes128
180 - aes256
181 - des
182 - rc4
183 type: list
184 elements: str
185 remove:
186 description:
187 - The encryption types to remove from the existing set.
188 - Any existing encryption types not specified by I(remove) will be
189 untouched unless I(set) is defined.
190 choices:
191 - aes128
192 - aes256
193 - des
194 - rc4
195 type: list
196 elements: str
197 set:
198 description:
199 - The encryption types to set as the only encryption types allowed
200 by the AD service account.
201 - This will remove any existing encryption types if not specified
202 in this list.
203 - Specify an empty list to remove all encryption types.
204 choices:
205 - aes128
206 - aes256
207 - des
208 - rc4
209 type: list
210 elements: str
211 outbound_auth_only:
212 description:
213 - Marks the service account for use with client outbound authentication
214 only.
215 - When set the service account can only be used for client roles only.
216 For example it can only be used for outbound authentication attempts
217 and cannot be used as a target authentication service principal.
218 - If set then I(dns_hostname) cannot be set.
219 default: false
220 type: bool
221 sam_account_name:
222 description:
223 - The C(sAMAccountName) value to set for the service account.
224 - It has a maximum of 256 characters, 15 is advised for older operating
225 systems compatibility.
226 - If ommitted the value is the same as C(name$) when the service
227 account is created.
228 - Note that service account C(sAMAccountName) values typically end with
229 a C($).
230 - By default if the C($) suffix is omitted, it will be added to the
231 end. If I(do_not_append_dollar_to_sam=True) then the provided value
232 will be used as is without adding C($) to the end.
233 type: str
234 spn:
235 description:
236 - Specifies the service principal name(s) for the account to add,
237 remove or set.
238 - This is the value set on the C(servicePrincipalName) LDAP attribute.
239 - To clear all service principal names, use I(set) with an empty list.
240 - See
241 R(Setting list option values,ansible_collections.microsoft.ad.docsite.guide_list_values)
242 for more information on how to add/remove/set list options.
243 aliases:
244 - spns
245 type: dict
246 suboptions:
247 add:
248 description:
249 - The SPNs to add to C(servicePrincipalName).
250 type: list
251 elements: str
252 remove:
253 description:
254 - The SPNs to remove from C(servicePrincipalName).
255 type: list
256 elements: str
257 set:
258 description:
259 - The SPNs to set as the only values in C(servicePrincipalName).
260 - This will clear out any existing SPNs if not in the specified
261 list.
262 - Set to an empty list to clear all SPNs on the AD object.
263 type: list
264 elements: str
265 trusted_for_delegation:
266 description:
267 - Specifies whether an account is trusted for Kerberos delegation.
268 - This is also known as unconstrained Kerberos delegation.
269 - This sets the C(ADS_UF_TRUSTED_FOR_DELEGATION) flag in the
270 C(userAccountControl) LDAP attribute.
271 type: bool
272 upn:
273 description:
274 - Configures the User Principal Name (UPN) for the account.
275 - The format is C(<username>@<domain>).
276 - This is the value set on the C(userPrincipalName) LDAP attribute.
277 type: str
278 notes:
279 - This module must be run on a Windows target host with the
280 C(ActiveDirectory) module installed.
281 - When matching by I(identity) with a C(sAMAccountName) value, the value
282 should endd with C($). If the provided value does not end with C($) the
283 module will still attempt to find the service account with the provided
284 value before attempting a fallback lookup with C($) appended to the end.
285 extends_documentation_fragment:
286 - microsoft.ad.ad_object
287 - ansible.builtin.action_common_attributes
288 attributes:
289 check_mode:
290 support: full
291 diff_mode:
292 support: full
293 platform:
294 platforms:
295 - windows
296 seealso:
297 - module: microsoft.ad.object_info
298 - module: microsoft.ad.object
299 author:
300 - Jordan Borean (@jborean93)
301
302 EXAMPLES: |
303 # A gMSA requires a KDS root key to be created. This key must be valid for
304 # 10 hours before it can be used. This example creates the key and sets the
305 # time for 10 hours ago to let it be used immediately. If your environment
306 # uses multiple DCs you will still need to wait 10 hours for replication to
307 # occur or target the DC you created the key on. Required Domain Admin or
308 # Enterprise Admin privileges.
309 - name: Create KDS root key if not present
310 ansible.windows.win_powershell:
311 error_action: stop
312 script: |
313 $Ansible.Changed = $false
314 if (-not (Get-KdsRootKey)) {
315 Add-KdsRootKey -EffectiveTime ((Get-Date).AddHours(-10))
316 $Ansible.Changed = $true
317 }
318
319 - name: Create gMSA that allows Domain Admins to use
320 microsoft.ad.service_account:
321 identity: MyGMSA
322 dns_hostname: MyGMSA.my_org.local
323 description: GMSA for Domin Admins
324 state: present
325 allowed_to_retrieve_password:
326 set:
327 - Domain Admins
328
329 - name: create gMSA that allows the ITFarmHosts computer account to retrieve the pass
330 microsoft.ad.service_account:
331 identity: ITFarm1
332 dns_hostname: ITFarm1.contoso.com
333 allowed_to_retrieve_password:
334 set:
335 - ITFarmHosts$
336 kerberos_encryption_types:
337 set:
338 - aes128
339 - aes256
340 spn:
341 add:
342 - http/ITFarm1.contoso.com/contoso.com
343 - http/ITFarm1.contoso.com/contoso
344 - http/ITFarm1.contoso.com
345 - http/ITFarm1.contoso
346
347 - name: Remove gMSA by identity
348 microsoft.ad.service_account:
349 identity: ITFarm1$
350 state: absent
351
352 - name: Add SPNs to service account
353 microsoft.ad.service_account:
354 identity: MySA$
355 spn:
356 add:
357 - HOST/MySA
358 - HOST/MySA.domain.test
359 - HOST/MySA.domain.test:1234
360
361 - name: Remove SPNs on the service account
362 microsoft.ad.service_account:
363 identity: MySA$
364 spn:
365 remove:
366 - HOST/MySA
367 - HOST/MySA.domain.test
368 - HOST/MySA.domain.test:1234
369
370 - name: Add gMSA with sAMAccountName without $ suffix
371 microsoft.ad.service_account:
372 identity: MySA
373 dns_hostname: MySA.contoso.com
374 sam_account_name: MySA
375 do_not_append_dollar_to_sam: true
376
377 RETURN:
378 object_guid:
379 description:
380 - The C(objectGUID) of the AD object that was created, removed, or
381 edited.
382 - If a new object was created in check mode, a GUID of 0s will be
383 returned.
384 returned: always
385 type: str
386 sample: d84a141f-2b99-4f08-9da0-ed2d26864ba1
387 distinguished_name:
388 description:
389 - The C(distinguishedName) of the AD object that was created, removed,
390 or edited.
391 returned: always
392 type: str
393 sample: CN=act,CN=Managed Service Accounts,DC=domain,DC=test
394 sid:
395 description:
396 - The Security Identifier (SID) of the account managed.
397 - If a new serivce account was created in check mode, the SID will be
398 C(S-1-5-0000).
399 returned: always
400 type: str
401 sample: S-1-5-21-4151808797-3430561092-2843464588-1104