Name
Last commit
Last update
..
README.md secure fix, init

logo

Ansible을 이용한 보안취약점 조치

/etc/ssh/sshd_config 설정에 PermitRootLogin yes 설정을 no로 조치한다.

Inventory 설정

# cat hosts
[ALL_HOSTS]
172.16.0.100 managed_ip=172.16.0.100 des="2020-12-03"

[ALL_HOSTS_OK]

대상 호스트는 172.16.0.100이며, 추가는 2020-12-03에 수행한다. 참고적으로 ALL_HOSTS_OK 호스트 그룹은 작업이 완료된 호스트의 history를 위한 그룹이다.

Host Variables 설정

# cat host_vars/172.16.0.100
ansible_ssh_host: 172.16.0.100
ansible_ssh_port: SSH_포트번호
ansible_ssh_user: 사용자 아이디
ansible_ssh_pass: "사용자 패스워드"
ansible_become: yes
ansible_become_method: su
ansible_become_user: root
ansible_become_pass: "!root_패스워드"
ansible_python_interpreter: python2.7

Playbook 설정

---
- name: SSHD SecureVal Fix
  hosts: ALL_HOSTS
  vars:
    time: "{{lookup('pipe','date \"+%Y-%m-%d\"')}}"
  tasks:
   - name: Disable root login over SSH Comment absent
     lineinfile:
       dest: /etc/ssh/sshd_config
       regexp: "^#PermitRootLogin"
       line: ""
       state: absent

   - name: Disable root login over SSH
     lineinfile:
       dest: /etc/ssh/sshd_config
       regexp: "^PermitRootLogin"
       line: "PermitRootLogin no"
       state: present
     notify:
       - reload sshd

  handlers:
  - name: reload sshd
    systemd:
      name: sshd
      state: reloaded

보안취약점 조치에 대한 Playbook 분석

  • 원격 호스트의 /etc/ssh/sshd_config 파일에 #PermitRootLogin 지시자가 존재할 경우 제거(absent)한다(향후 주석을 해제할 수 있으므로).
  • PermiitRootLogin 지시자가 없는 경우(주석된 지시자는 미해당) PermitRootLogin no 를 설정파일에 적용한다.

playbook 실행

# ansible-playbook -i hosts ssh_permitrootno.yml