add_scan_user_for_Nessus.yaml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ---
  2. - name: Add or modify the scan user for use by the Nessus scanner (ONLY if ansible_facts.system=='Linux')
  3. hosts: all
  4. gather_facts: true
  5. become: True
  6. tasks:
  7. - name: Create a group "sshprohibitpasswd"
  8. group:
  9. name: sshprohibitpasswd
  10. state: present
  11. # local: true
  12. system: true
  13. # gid: 967 <-- gid 967 is already in use by many systems
  14. when: ansible_facts.system == 'Linux'
  15. - name: Add or modify the the scan user
  16. user:
  17. name: scan
  18. state: present
  19. system: true
  20. comment: "user for internal security scans"
  21. create_home: true
  22. # local: true
  23. # group: scan <-- "Group scan does not exist"
  24. groups: sshprohibitpasswd
  25. shell: "/bin/bash"
  26. # uid: 968 <-- can't predict which systems are already using this UID
  27. #10-02-2024: New scan user passwrod created and stored by cmiloro
  28. password: "$6$00000000$00000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
  29. update_password: always
  30. password_lock: false
  31. expires: -1
  32. password_expire_max: 99999
  33. password_expire_min: 0
  34. when: ansible_facts.system == 'Linux'
  35. - name: Add the public keys for scan to the user scan
  36. authorized_key:
  37. user: scan
  38. manage_dir: true
  39. state: present
  40. key: '{{ item }}'
  41. with_file:
  42. - include/scan_user/id_rsa.pub
  43. - include/scan_user/id_ed25519.pub
  44. when: ansible_facts.system == 'Linux'
  45. - name: Add the scan user to the sudoers file (ALL commands, password Required) and validate
  46. sudoers:
  47. host: ALL
  48. name: "Allow the scan user to run commands using sudo"
  49. user: scan
  50. commands: ALL
  51. state: present
  52. nopassword: false
  53. validation: detect
  54. when: ansible_facts.system == 'Linux'
  55. - name: Enable public key authentication within /etc/ssh/sshd_config, backing file up if a change is made, and validate
  56. lineinfile:
  57. path: /etc/ssh/sshd_config
  58. regexp: '^#PubkeyAuthentication yes'
  59. line: PubkeyAuthentication yes
  60. state: present
  61. backup: yes
  62. validate: 'sshd -t -f %s'
  63. when: ansible_facts.system == 'Linux'
  64. - name: Ensure scan account has nothing locking it
  65. shell: |
  66. usermod -U scan
  67. usermod -e "" scan
  68. chage -E -1 scan
  69. chage -I -1 scan
  70. exit 0
  71. args:
  72. executable: /bin/bash
  73. when: ansible_facts.system == 'Linux'