Ansible을 이용한 보안취약점 조치
시스템 접근 시 경고사항에 대한 미설정 취약점을 조치한다.
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: MOTD(Banner) Not Set Secure Fix
hosts: ALL_HOSTS
tasks:
- name: Copy the banner issue file in remote node
copy:
src: templates/issue.j2
dest: /etc/issue
owner: root
group: root
mode: 0644
- name: Copy the banner motd file in remote node
copy:
src: templates/issue.j2
dest: /etc/motd
owner: root
group: root
mode: 0644
- name: Copy the banner issue.net file in remote node
copy:
src: templates/issue.j2
dest: /etc/issue.net
owner: root
group: root
mode: 0644
- name: /etc/ssh/sshd_config Banner Configure
lineinfile: dest=/etc/ssh/sshd_config regexp="^#?Banner" line="Banner /etc/issue.net" state=present
issue.j2 파일의 내역은 다음과 같다.
# cat templates/issue.j2
####################################################################
# #
# All access and usage is monitored and recorded #
# and can be provided evidence as court or related organization. #
# #
####################################################################
보안취약점 조치
에 대한 Playbook 분석
- copy 모듈을 사용하여, 원격 시스템에 배너를 설정한다.
- /etc/ssh/sshd_config 파일에 Banner 설정이 없다면, 이를 /etc/issue.net으로 적용한다.
playbook 실행
# ansible-playbook -i hosts motd_issue.yml