Ansible을 이용한 보안취약점 조치
cron 설정 중 cron.deny 파일 및 설정이 존재하지않을 경우 취약하므로, 이를 Fix 한다.
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: cron Secure Fix
hosts: ALL_HOSTS
tasks:
- name: Copy the CRON cron.allow file in remote node
copy:
src: templates/cron.allow.j2
dest: /etc/cron.allow
owner: root
group: root
mode: 0640
- name: Copy the CRON cron.deny file in remote node
copy:
src: templates/cron.deny.j2
dest: /etc/cron.deny
owner: root
group: root
mode: 0640
위의 cron.allow, cron.deny 파일의 내역은 다음과 같다.
# cat templates/cron.allow.j2
root
# cat templates/cron.deny.j2
cron.deny 파일에 아무런 사용자가 없어도 반드시 등록해야 한다. 즉, 위의 설정은 root 유저를 제외한 모든 사용자의 cron을 제한하겠다는 설정이다.
보안취약점 조치
에 대한 Playbook 분석
- copy 모듈을 사용하여, 기존에 검증된 파일을 원격서버에 복사한다.
playbook 실행
# ansible-playbook -i hosts cron_deny.yml