fetch_security_inputs.yml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. # Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. ---
  15. - name: Include security variable file security_vars.yml
  16. include_vars: "{{ security_vars_filename }}"
  17. no_log: true
  18. tags: init
  19. - name: Validate input parameters of security vars are not empty
  20. fail:
  21. msg: "{{ input_security_failure_msg }}"
  22. register: input_base_check
  23. tags: [ validate, security ]
  24. when:
  25. - domain_name | length < 1 or
  26. realm_name | length < 1
  27. - name: Validate the domain name
  28. assert:
  29. that:
  30. - domain_name is regex("^(?!-)[A-Za-z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Za-z]{2,}$")
  31. success_msg: "{{ dom_name_success_msg }}"
  32. fail_msg: "{{ dom_name_fail_msg }}"
  33. tags: [ validate, security ]
  34. - name: Validate the realm name
  35. assert:
  36. that:
  37. - realm_name is regex("^(?!-)[A-Z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Z]{2,}$")
  38. - '"." in realm_name'
  39. success_msg: "{{ realm_success_msg }}"
  40. fail_msg: "{{ realm_fail_msg }}"
  41. tags: [ validate, security ]
  42. - name: Fetch the short hostname
  43. command: hostname -s
  44. register: short_hostname
  45. changed_when: false
  46. tags: security
  47. - name: Verify the hostname is not blank in hostname
  48. fail:
  49. msg: " {{ hostname_blank_msg }}"
  50. when: short_hostname.stdout | length < 1
  51. tags: [ validate, security ]
  52. - name: Validate the host name
  53. assert:
  54. that:
  55. - short_hostname.stdout is regex(("^(([a-z]|[a-z][a-z0-9\-]*[a-z0-9])\.)*([a-z]|[a-z][a-z0-9\-]*[a-z0-9])$"))
  56. - short_hostname.stdout != "localhost"
  57. success_msg: "{{ server_hostname_success }}"
  58. fail_msg: "{{ server_hostname_fail }}"
  59. tags: [ validate, security ]
  60. - name: Fetch the domain name
  61. command: hostname -d
  62. register: domain_name_set
  63. changed_when: false
  64. failed_when: false
  65. tags: security
  66. - name: Verify the domain name is not blank in hostname
  67. fail:
  68. msg: " {{ domain_name_blank_msg }}"
  69. when: domain_name_set.stdout | length < 1
  70. tags: [ validate, security ]
  71. - name: Set fact for the domain name in hostname
  72. set_fact:
  73. ms_domain_name: "{{ domain_name_set.stdout }}"
  74. tags: security
  75. - name: Validate the domain name set on the host
  76. assert:
  77. that:
  78. - domain_name == ms_domain_name
  79. success_msg: "{{ server_domain_name_success }}"
  80. fail_msg: "{{ server_domain_name_fail }}"
  81. tags: [ validate, security ]
  82. - name: Get the hostname
  83. command: hostname
  84. register: machine_hostname
  85. changed_when: false
  86. tags: security
  87. - name: Add host name in hosts file
  88. lineinfile:
  89. dest: "{{ hosts_file_path }}"
  90. line: "{{ public_ip }} {{ machine_hostname.stdout }}"
  91. state: present
  92. create: yes
  93. mode: "{{ hosts_file_mode }}"
  94. tags: [ validate, security ]
  95. - name: Validate max_failures
  96. assert:
  97. that:
  98. - max_failures | int == max_failures_default_value
  99. success_msg: "{{ max_failures_success_msg }}"
  100. fail_msg: "{{ max_failures_fail_msg }}"
  101. tags: [ validate, security ]
  102. - name: Validate failure_reset_interval
  103. assert:
  104. that:
  105. - failure_reset_interval | int
  106. - failure_reset_interval | int <= failure_reset_interval_max_value
  107. - failure_reset_interval | int >= failure_reset_interval_min_value
  108. success_msg: "{{ failure_reset_interval_success_msg }}"
  109. fail_msg: "{{ failure_reset_interval_fail_msg }}"
  110. tags: [ validate, security ]
  111. - name: Validate lockout_duration
  112. assert:
  113. that:
  114. - lockout_duration | int
  115. - lockout_duration | int <= lockout_duration_max_value
  116. - lockout_duration | int >= lockout_duration_min_value
  117. success_msg: "{{ lockout_duration_success_msg }}"
  118. fail_msg: "{{ lockout_duration_fail_msg }}"
  119. tags: [ validate, security ]
  120. - name: Validate session_timeout
  121. assert:
  122. that:
  123. - session_timeout | int
  124. - session_timeout | int <= session_timeout_max_value
  125. - session_timeout | int >= session_timeout_min_value
  126. success_msg: "{{ session_timeout_success_msg }}"
  127. fail_msg: "{{ session_timeout_fail_msg }}"
  128. tags: [ validate, security ]
  129. - name: Validate alert_email_address
  130. assert:
  131. that:
  132. - email_search_key in alert_email_address
  133. - alert_email_address | length < email_max_length
  134. success_msg: "{{ alert_email_success_msg }}"
  135. fail_msg: "{{ alert_email_fail_msg }}"
  136. tags: [ validate, security ]
  137. when: alert_email_address | length > 1
  138. - name: Warning - alert_email_address is empty
  139. debug:
  140. msg: "{{ alert_email_warning_msg }}"
  141. tags: security
  142. when: alert_email_address | length < 1
  143. - name: Prepare user list
  144. set_fact:
  145. user_list: "{{ lookup('vars', 'user').split()| unique | select| list }}"
  146. when: user | length > 1
  147. tags: security
  148. - name: validate user
  149. assert:
  150. that:
  151. - item is regex("^(?!-)[a-zA-Z]+[0-9-]*[@]((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$") or
  152. item is regex("(?!-)[a-zA-Z]+[0-9-]*$")
  153. success_msg: "{{ user_success_msg }}"
  154. fail_msg: "{{ user_fail_msg }}"
  155. with_items: "{{ user_list }}"
  156. tags: [ validate, security ]
  157. when:
  158. - user | length > 1
  159. - name: Validate allow_deny
  160. assert:
  161. that:
  162. - allow_deny == 'Allow' or allow_deny == 'Deny'
  163. success_msg: "{{ allow_deny_success_msg }}"
  164. fail_msg: "{{ allow_deny_fail_msg }}"
  165. tags: [ validate, security ]
  166. - name: Assert restrict_program_support
  167. assert:
  168. that:
  169. - restrict_program_support == true or restrict_program_support == false
  170. success_msg: "{{ restrict_program_support_success_msg }}"
  171. fail_msg: "{{ restrict_program_support_failure_msg }}"
  172. tags: [ validate, security ]
  173. - name: Initialize variables for restrict_softwares
  174. set_fact:
  175. restrict_program_status: false
  176. disable_services: []
  177. tags: security
  178. - block:
  179. - name: The services needs to be disabled are appending to list
  180. set_fact:
  181. services_list: "{{ lookup('vars', 'restrict_softwares').split(',')| map('trim') | unique | select| list }}"
  182. tags: security
  183. - name: Assert restrict_softwares variable
  184. assert:
  185. that:
  186. - item == 'telnet' or
  187. item == 'lpd' or
  188. item == 'bluetooth' or
  189. item == 'rlogin' or
  190. item == 'rexec'
  191. success_msg: "{{ restrict_softwares_success_msg }}"
  192. fail_msg: "{{ restrict_softwares_failure_msg }}"
  193. failed_when: false
  194. with_items: "{{ services_list }}"
  195. tags: [ validate, security ]
  196. - name: Creating a list for disabling services
  197. set_fact:
  198. disable_services: "{{ disable_services + [ item ] }}"
  199. when:
  200. - item == 'telnet' or
  201. item == 'lpd' or
  202. item == 'bluetooth' or
  203. item == 'rlogin' or
  204. item == 'rexec'
  205. with_items: "{{ services_list }}"
  206. tags: security
  207. - name: Setting restrict_program_status
  208. set_fact:
  209. restrict_program_status: true
  210. when:
  211. - disable_services | length > 0
  212. tags: security
  213. when: restrict_program_support