README.md 2.76 KB
Newer Older
JooHan Hong's avatar
JooHan Hong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
[![logo](https://www.hongsnet.net/images/logo.gif)](https://www.hongsnet.net)

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

> 내부 로그서버로의 전송 미설정 취약점을 조치한다.


## Inventory 설정

```bash
# 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 설정

```bash
# 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 설정

```python
---
- name: OS logs setting Secure Fix
  hosts: ALL_HOSTS
  vars:
    time: "{{lookup('pipe','date \"+%Y%m%d\"')}}"
    log_server: "172.16.0.254"
  tasks:
    - name: /root/test Directory Create
      command: mkdir -p /root/test

    - name: /root/test/rsyslog_config_{{ time }} file copy check
      stat:
        path: /root/test/rsyslog.conf_{{ time }}
      register: rsyslog_config_backup

    - name: /etc/rsyslog.conf_{{ time }} file backup
      command: cp -rf /etc/rsyslog.conf /root/test/rsyslog.conf_{{ time }}
      when: rsyslog_config_backup.stat.exists == False

    - name: Copy the Rsyslog Configs file file in remote node
      copy:
       src: templates/rsyslog.conf.j2
       dest: /etc/rsyslog.conf
       owner: root
       group: root
       mode: 0644
      register: rsyslog_config

    - name: rsyslog Daemon Reloaded Service
      service:
       name: rsyslog
       state: restarted
       enabled: yes
      when: rsyslog_config.changed
```

rsyslog.conf.j2 파일의 변경내역은 다음과 같다.

```bash
auth,authpriv.*                 @{{ log_server }}
*.=info;*.=notice;*.=warn;\
        auth,authpriv.none;\
        cron,daemon.none;\
        mail,news.none           @{{ log_server }}

auth,authpriv.*                 /var/log/auth.log
*.*;auth,authpriv.none          -/var/log/syslog
#cron.*                         /var/log/cron.log
daemon.*                        -/var/log/daemon.log
kern.*                          -/var/log/kern.log
lpr.*                           -/var/log/lpr.log
mail.*                          -/var/log/mail.log
```

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

* [ ] copy 모듈을 사용하여, 원격 시스템에 배너를 설정한다.
* [ ] Jinja2 템플릿을 사용하여, 원격 시스템의 /etc/rsyslog.conf 파일을 배포한다.


## playbook 실행

```bash
# ansible-playbook -i hosts rsyslog_set.yml
```