Debian Codegraph @

ansible_collections/ibm/storage_virtualize/plugins/modules/ibm_sv_manage_security.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright (C) 2023 IBM CORPORATION
5 # Author(s): Sumit Kumar Gupta <[email protected]>
6 # Sandip Gulab Rajbanshi <[email protected]>
7 #
8 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
9
10 from __future__ import absolute_import, division, print_function
11 __metaclass__ = type
12
13 DOCUMENTATION = r'''
14 ---
15 module: ibm_sv_manage_security
16 short_description: This module manages security options on IBM Storage Virtualize family storage systems
17 description:
18 - Ansible interface to manage 'chsecurity' command.
19 version_added: "2.1.0"
20 options:
21 clustername:
22 description:
23 - The hostname or management IP of the Storage Virtualize storage system.
24 required: true
25 type: str
26 domain:
27 description:
28 - Domain for the Storage Virtualize storage system.
29 - Valid when hostname is used for the parameter I(clustername).
30 type: str
31 username:
32 description:
33 - REST API username for the Storage Virtualize storage system.
34 - The parameters I(username) and I(password) are required if not using I(token) to authenticate a user.
35 type: str
36 password:
37 description:
38 - REST API password for the Storage Virtualize storage system.
39 - The parameters I(username) and I(password) are required if not using I(token) to authenticate a user.
40 type: str
41 token:
42 description:
43 - The authentication token to verify a user on the Storage Virtualize storage system.
44 - To generate a token, use the ibm_svc_auth module.
45 type: str
46 sshprotocol:
47 description:
48 - Specifies the numeric value for the SSH security level setting in range 1 - 4.
49 - The level 1 Allows the following key exchange methods
50 curve25519-sha256
51 [email protected]
52 ecdh-sha2-nistp256
53 ecdh-sha2-nistp384
54 ecdh-sha2-nistp521
55 diffie-hellman-group-exchange-sha256
56 diffie-hellman-group16-sha512
57 diffie-hellman-group18-sha512
58 diffie-hellman-group14-sha256
59 diffie-hellman-group14-sha1
60 diffie-hellman-group1-sha1
61 diffie-hellman-group-exchange-sha1
62 - The level 2 Allows the following key exchange methods
63 curve25519-sha256
64 [email protected]
65 ecdh-sha2-nistp256
66 ecdh-sha2-nistp384
67 ecdh-sha2-nistp521
68 diffie-hellman-group-exchange-sha256
69 diffie-hellman-group16-sha512
70 diffie-hellman-group18-sha512
71 diffie-hellman-group14-sha256
72 diffie-hellman-group14-sha1
73 - The level 3 Allows the following key exchange methods
74 curve25519-sha256
75 [email protected]
76 ecdh-sha2-nistp256
77 ecdh-sha2-nistp384
78 ecdh-sha2-nistp521
79 diffie-hellman-group-exchange-sha256
80 diffie-hellman-group16-sha512
81 diffie-hellman-group18-sha512
82 diffie-hellman-group14-sha256
83 - The level 4 Allows the following key exchange methods
84 curve25519-sha256
85 [email protected]
86 ecdh-sha2-nistp256
87 ecdh-sha2-nistp384
88 ecdh-sha2-nistp521
89 type: int
90 guitimeout:
91 description:
92 - Specifies the amount of time (in minutes) in range 5 - 240 before a session expires and the user is logged
93 out of the GUI for inactivity.
94 type: int
95 clitimeout:
96 description:
97 - Specifies the amount of time (in minutes) in range 5 - 240 before a session expires and the user is logged
98 out of the CLI for inactivity.
99 type: int
100 minpasswordlength:
101 description:
102 - Specifies the minimum length requirement in range 6 -64 for user account passwords on the system.
103 type: int
104 passwordspecialchars:
105 description:
106 - Specifies number of minimum required special characters in range 0 - 3 in passwords for local users.
107 type: int
108 passworduppercase:
109 description:
110 - Specifies number of minimum uppercase characters in range 0 - 3 in passwords for local users.
111 type: int
112 passwordlowercase:
113 description:
114 - Specifies number of minimum lowercase characters in range 0 - 3 required in passwords for local users.
115 type: int
116 passworddigits:
117 description:
118 - Specifies mimimum number of digits in range 0 -3 required in passwords for local users.
119 type: int
120 checkpasswordhistory:
121 description:
122 - Specifies whether the system prevents the user from reusing a previous password.
123 choices: ['yes', 'no']
124 type: str
125 maxpasswordhistory:
126 description:
127 - Specifies the number of previous passwords in range 0 - 10 to compare with if checkpasswordhistory is
128 enabled. A value of 0 means that the new password is compared with the current password only.
129 type: int
130 minpasswordage:
131 description:
132 - Specifies the minimum number of days between password changes in range 0 -365. This setting is enforced if
133 checkpasswordhistory is enabled. This restriction is ignored if the password is expired. The setting does
134 nothing if the value is greater than the passwordexpiry value.
135 type: int
136 passwordexpiry:
137 description:
138 - Specifies the number of days in range 0 - 365 before a password expires. A value of 0 means the feature is
139 disabled and passwords do not expire.
140 type: int
141 expirywarning:
142 description:
143 - Specifies the number of days in range 0 -30 before a password expires to raise a warning. The warning is
144 displayed on every CLI login until the password is changed. A value of 0 means that the feature is
145 disabled and warnings are not displayed.
146 type: int
147 superuserlocking:
148 description:
149 - Specifies whether the locking policy configured on the system also applies to the superuser. The value is
150 either enable or disable. This parameter is only supported on systems with a dedicated technician port.
151 choices: ['enable', 'disable']
152 type: str
153 maxfailedlogins:
154 description:
155 - Specifies the number of failed login attempts in range 0 -10 before the user account is locked for the
156 amount of time that is specified in lockout period. A value of 0 means that the feature is disabled and
157 accounts are not locked out after failed login attempts.
158 type: int
159 lockoutperiod:
160 description:
161 - Specifies the number of minutes in range 0 - 10080 that a user is locked out for if the max failed logins
162 value is reached. A value of 0 implies the user is indefinitely locked out when the max failed login
163 attempts are reached.
164 type: int
165 restapitimeout:
166 description:
167 - Specifies token expiry time in minutes in the range 10 - 120.
168 type: int
169 superusermultifactor:
170 description:
171 - Specifies whether the superuser should be prompted for multifactor authentication.
172 choices: ['yes', 'no']
173 type: str
174 sshmaxtries:
175 description:
176 - Specifies the amount of allowed login attempts (in range 1-10) per a single SSH connection.
177 type: int
178 sshgracetime:
179 description:
180 - Specifies the duration of time in seconds in range 15-1800, a user has to enter login factors per SSH
181 connection before the connection is
182 terminated.
183 type: int
184 superuserpasswordkeyrequired:
185 description:
186 - Specifies whether the superuser must provide both a password and SSH key for authentication.
187 type: str
188 choices: ['yes', 'no']
189 disablesuperusergui:
190 description:
191 - Specifies whether GUI access must be disabled for the superuser.
192 choices: ['yes', 'no']
193 type: str
194 disablesuperuserrest:
195 description:
196 - Specifies whether REST API access must be disabled for the superuser.
197 choices: ['yes', 'no']
198 type: str
199 disablesuperusercim:
200 description:
201 - Specifies whether CIMOM access must be disabled for the superuser.
202 choices: ['yes', 'no']
203 type: str
204 resetsshprotocol:
205 description:
206 - Resets the SSH protocol security level to the default value 3 and configures the system to automatically
207 follow the suggested level.
208 type: bool
209 patchautoupdate:
210 description:
211 - Enables or disables the patch auto updater service.
212 choices: ['yes', 'no']
213 type: str
214 log_path:
215 description:
216 - Path of debug log file.
217 type: str
218 validate_certs:
219 description:
220 - Validates certification.
221 default: false
222 type: bool
223
224 author:
225 - Sumit Kumar Gupta (@sumitguptaibm)
226 - Lavanya C R (@lavanyacr)
227 - Sandip Gulab Rajbanshi (@Sandip-Rajbanshi)
228 notes:
229 - This module supports C(check_mode).
230 - The 3-site-orchestrator does not support SSH protocol level 4.
231 '''
232
233 EXAMPLES = r'''
234 - name: Change max failed login limit
235 ibm.storage_virtualize.ibm_sv_manage_security:
236 clustername: "{{ cluster }}"
237 username: "{{ username }}"
238 password: "{{ password }}"
239 log_path: /tmp/playbook.debug
240 maxfailedlogins: 5
241
242 - name: Change SSH protocol level
243 ibm.storage_virtualize.ibm_sv_manage_security:
244 clustername: "{{ cluster }}"
245 username: "{{ username }}"
246 password: "{{ password }}"
247 log_path: /tmp/playbook.debug
248 sshprotocol: 2
249
250 - name: Enables the patch auto updater service
251 ibm.storage_virtualize.ibm_sv_manage_security:
252 clustername: "{{ cluster }}"
253 username: "{{ username }}"
254 password: "{{ password }}"
255 log_path: /tmp/playbook.debug
256 patchautoupdate: 'yes'
257 '''
258
259 RETURN = r'''#'''
260
261 from traceback import format_exc
262 from ansible.module_utils.basic import AnsibleModule
263 from ansible_collections.ibm.storage_virtualize.plugins.module_utils.ibm_svc_utils import (IBMSVCRestApi,
264 svc_argument_spec,
265 get_logger)
266 from ansible.module_utils._text import to_native
267
268
269 class IBMSVSecurityMgmt(object):
270 def __init__(self):
271 argument_spec = svc_argument_spec()
272 argument_spec.update(
273 dict(
274 sshprotocol=dict(type='int'),
275 guitimeout=dict(type='int'),
276 clitimeout=dict(type='int'),
277 minpasswordlength=dict(type='int', no_log=False),
278 passwordspecialchars=dict(type='int', no_log=False),
279 passworduppercase=dict(type='int', no_log=False),
280 passwordlowercase=dict(type='int', no_log=False),
281 passworddigits=dict(type='int', no_log=False),
282 checkpasswordhistory=dict(type='str', choices=['yes', 'no'], no_log=False),
283 maxpasswordhistory=dict(type='int', no_log=False),
284 minpasswordage=dict(type='int', no_log=False),
285 passwordexpiry=dict(type='int', no_log=False),
286 expirywarning=dict(type='int'),
287 superuserlocking=dict(type='str', choices=['enable', 'disable']),
288 maxfailedlogins=dict(type='int'),
289 lockoutperiod=dict(type='int'),
290 restapitimeout=dict(type='int'),
291 superusermultifactor=dict(type='str', choices=['yes', 'no']),
292 sshmaxtries=dict(type='int'),
293 sshgracetime=dict(type='int'),
294 superuserpasswordkeyrequired=dict(type='str', choices=['yes', 'no']),
295 disablesuperusergui=dict(type='str', choices=['yes', 'no']),
296 disablesuperuserrest=dict(type='str', choices=['yes', 'no']),
297 disablesuperusercim=dict(type='str', choices=['yes', 'no']),
298 resetsshprotocol=dict(type='bool'),
299 patchautoupdate=dict(type='str', choices=['yes', 'no'])
300 )
301 )
302
303 self.module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
304
305 for param, value in self.module.params.items():
306 setattr(self, param, value)
307
308 # logging setup
309 log_path = self.module.params['log_path']
310 log = get_logger(self.__class__.__name__, log_path)
311 self.log = log.info
312
313 # Initialize changed variable
314 self.changed = False
315
316 # creating an instance of IBMSVCRestApi
317 self.restapi = IBMSVCRestApi(
318 module=self.module,
319 clustername=self.module.params['clustername'],
320 domain=self.module.params['domain'],
321 username=self.module.params['username'],
322 password=self.module.params['password'],
323 validate_certs=self.module.params['validate_certs'],
324 log_path=log_path,
325 token=self.module.params['token']
326 )
327
328 def change_security_settings(self):
329 cmd = 'chsecurity'
330 cmd_opts = {}
331
332 for attr, value in vars(self).items():
333 if attr in ['restapi', 'log', 'module', 'clustername', 'domain', 'username', 'password', 'validate_certs',
334 'token', 'log_path']:
335 continue
336 cmd_opts[attr] = value
337
338 result = self.restapi.svc_run_command(cmd, cmd_opts, cmdargs=None)
339 if result == "":
340 self.changed = True
341 self.log("chsecurity successful !!")
342 else:
343 self.module.fail_json(msg="chsecurity failed !!")
344
345 def apply(self):
346 msg = None
347 if self.module.check_mode:
348 self.changed = True
349 else:
350 self.change_security_settings()
351 self.module.exit_json(msg=msg, changed=self.changed)
352
353
354 def main():
355 v = IBMSVSecurityMgmt()
356 try:
357 v.apply()
358 except Exception as e:
359 v.log("Exception in apply(): \n%s", format_exc())
360 v.module.fail_json(msg="Module failed. Error [%s]." % to_native(e))
361
362
363 if __name__ == '__main__':
364 main()