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

logo

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

사용자 패스워드에 대한 정책 취약점을 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: User Password Policy Fix (PAM)
  hosts: TEST
  vars:
    time: "{{lookup('pipe','date \"+%Y%m%d\"')}}"
  environment:
    LANG: ko_KR.UTF-8
  tasks:
    - name: /root/test Directory Create
      command: mkdir -p /root/test

    - name: /root/test/common-password_{{ time }} file copy check
      stat:
        path: /root/test/common-password_{{ time }}
      register: common_password_config_backup

    - name: /etc/pam.d/common-password_{{ time }} file backup
      command: cp -rf /etc/pam.d/common-password /root/test/common-password_{{ time }}
      when: common_password_config_backup.stat.exists == False

    - name: Copy the /etc/pam.d/common-password file in remote node
      copy:
       src: templates/common-password
       dest: /etc/pam.d/common-password
       owner: root
       group: root
       mode: 0644
      register: common_password_config

    - name: Restrict Access to the su Command
      lineinfile:
        dest: /etc/pam.d/su
        regexp: '# auth       required   pam_wheel.so'
        line: 'auth            required        pam_wheel.so use_uid'
        state: present

templates/common-password 파일내용은 다음과 같다.

password        [success=1 default=ignore]      pam_unix.so obscure sha512
password        requisite                       pam_deny.so
password        required                        pam_permit.so
password        requisite               pam_cracklib.so retry=3 minlen=8 lcredit=1 ucredit=1 dcredit=1 ocredit=1

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

  • Fix 하기전에 /etc/pam.d/common-password 파일을 일자(YYYY-MM-DD) 기준으로 백업(stat, command 모듈)한다.
  • 검증된 파일을 원격시스템에 COPY(copy 모듈) 한다.
  • wheel 그룹만 root로 전환할 수 있게 설정(pam_wheel)을 진행한다.

playbook 실행

# ansible-playbook -i hosts pam_common.yml