Ansible을 이용한 보안취약점 조치
특별한 사유가 없는 World Write Able(Other User의 Write 권한)이 존재하는 파일이나 디렉토리의 권한을 조치한다.
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: OS PACKAGE_QUERY Action
hosts: ALL_HOSTS
vars:
time_d: "{{lookup('pipe','date \"+%Y%m%d\"')}}"
time_m: "{{lookup('pipe','date \"+%Y%m%d_%H%M\"')}}"
tasks:
- name: command set Execute...
shell: "{{ item }}"
with_items:
- chmod 644 /etc/hosts
- chmod 644 /etc/passwd
- name: file stat check
stat:
path: "{{ item }}"
with_items:
- /etc/hosts
- /etc/passwd
register: file_stat
- debug: var=file_stat
- name: file stat command check
shell: "{{ item }}"
with_items:
- ls -al /etc/hosts
- ls -al /etc/passwd
register: file_stat_command
- debug: var=file_stat_command
- name: Local Directory Create
local_action: command mkdir -p PERMISSION_SET/{{ managed_ip }}/{{ time_d }}
- name: Command Result Local Stored
local_action: copy content={{ file_stat_command.results }} dest=PERMISSION_SET/{{ managed_ip }}/{{ time_d }}/command_result_{{ time_m }}.txt
보안취약점 조치
에 대한 Playbook 분석
- 취약점을 조치할 명령(권한 조치)을 설정하며, with_item 모듈에 따라 다중으로 지정할 수 있다.
-
수행 후 증적을 남기기 위해 로컬에 다음과 같이 txt 파일을 기록한다.
- time_d : 현재 일자기준
- time_m : 수행 기준(분 단위)
playbook 실행
# ansible-playbook -i hosts world_write_able_fix.yml