ကျွန်တော်တို့ ansible ကိုသုံးပြီး automate လုပ်လို့ရတဲ့ use cases တွေကများပါတယ်. ကျွန်တော် sharing လုပ်ချင်တာက ansible ကိုသုံးပြီး linux server တွေကို OS System Hardening လုပ်တဲ့အပိုင်းကို sharing လုပ်ချင်ပါတယ်.
Hardening ဆိုတာက အကြမ်းအားဖြင့် System တွေရဲ့ configuration and Settings တွေကို secure ဖြစ်အောင်လုပ်တာကိုပြောတာပါ. Hardening အပိုင်းကကျယ်ပြန့်ပါတယ်.
OS System Hardening အပိုင်းမှာအကြမ်းအားဖြင့် Operating System ( Linux or Windows ) ရဲ့ updates, patches, and service packs တွေကိုပုံမှန် update, patch လုပ်တာတွေပါပါတယ်. Operating System တွေရဲ့ configuration and settings ကို security compliance ( PCI DSS, CIS, etc .. ) နဲ့ကိုက်ညီအောင် သက်မှတ်တာတွေလဲပါပါတယ်.
ကျွန်တော်က AWS ပေါ်မှာ deploy လုပ်ထားတဲ့ linux ec2 instances တွေကို ansible ကိုသုံးပြီး os system hardening လုပ်မှာပါ.
ကျွန်တော်တို့ ec2 instances တွေကို hardening မလုပ်ခင်မှာ လိုအပ်တာတွေကိုအရင် install လုပ်ထားဖို့လိုပါတယ်.
Prerequisites
- python3
- boto3 and botocore ( aws python library )
- ansible binary
- aws-cli ( aws commandline )
- aws cloud9 IDE or other IDE
ကျွန်တော်တို့ လိုအပ်တာတွေကို install လုပ်တဲ့အပိုင်းနဲ့ပါတ်သက်ပြီး ကျွန်တော်အရင်က sharing လုပ်ထားတာရှိပါတယ်.
ကျွန်တော်တို့လိုအပ်တဲ့ dependency တွေကို install လုပ်ပြီးရင်တော့ OS System Hardening အတွက်လိုအပ်တဲ့ ansible collection ကို install လုပ်ပါမယ်.
ကျွန်တော်တို့ ansible collections ကို ansible galaxy or github ကနေ install လုပ်လို့ရပါတယ်.
ကျွန်တော်က OS Sytstem Hardening အတွက် DevSec Hardening Framework ကိုသုံးထားပါတယ်.
ကျွန်တော်တို့ အလုပ်ရဲ့ လိုအပ်ချက်ပေါ်မူတည်ပြီး ansible roles or playbook ကိုကိုယ်တိုင်ရေးပြီးသုံးးလဲရပါတယ်.
ansible roles and collections နဲ့ပါတ်သက်ပြီး ကျွန်တော် အရင်က sharing လုပ်ထားတာရှိပါတယ်.
ကျွန်တော်တို့ DevSec Hardening Framework ကို ansible galaxy ကနေအရင် install လုပ်ပါမယ်.
DevSec Hardening Framework ကို အခြား ssh, Nginx, Apache and MySQL Hardening တို့အတွက်လဲသုံးလို့ရပါတယ်.

ကျွန်တော်တို့ os-hardening အပိုင်းကို install လုပ်ကြည့်ရအောင်.

ကျွန်တော်တို့ ansible roles and collections ကို install လုပ်မဲ့ directory ကို ansible.cfg မှာသက်မှတ်ပေးဖို့လိုပါတယ်.
ကျွန်တော်တို့ project directory မှာ role and collections ဆိုတဲ့ directory နစ်ခုကို create လုပ်ပါမယ်.
mkdir -p roles collections

ansible.cfg မှာ ansible roles and colletions ကို install လုပ်မဲ့ directory ကို သက်မှတ်ပါမယ်.
vim ansible.cfg
[defaults]
inventory=./inventory
deprecation_warnings=False
private_key_file=aws_ec2.pem
remote_user=ubuntu
roles_path=./roles
collections_paths=./collections
[inventory]
enable_plugins = aws_ec2
[privilege_escalation]
become=True
become_method=sudo
become_user=root
ကျွန်တော်တို့ os-hardening role ကို install လုပ်ကြည့်ရအောင်.
ansible-galaxy install dev-sec.os-hardening

ကျွန်တော်က DevSec Hardening Framework ထဲက os-hardening role တစ်ခုထဲကို install လုပ်ထားတာပါ.
တစ်ကယ်လို့ DevSec Hardening Framework တစ်ခုလုံးကို install လုပ်ချင်ရင်တော့ ansible collections ကိုသုံးရမှာပါ.
ansible-galaxy collection install devsec.hardening

ကျွန်တော်တို့ projects directory ကို check လုပ်ကြည့်ပါမယ်.
tree -L 2

ကျွန်တော်က IDE ကို AWS Cloud9 ကိုသုံးထားပါတယ်. ကိုယ်ကြိုက်ရာ IDE ကိုသုံးလို့ရပါတယ်.
ကျွန်တော်က EC2 instances တွေရဲ့ os-hardening အတွက် AWS EC2 မှာ ubuntu:20.04 instances သုံးလုံးကို deploy လုပ်ထားပါတယ်. အခြား linux distro တွေကိုသုံးလဲရပါတယ်.
EC2 Instances တွေရဲ့ IP and FQDN အတွက် ansible dynamic inventory ကိုသုံးထားပါတယ်.
ansible dynamic inventory နဲ့ပါတ်သက်ပြီး ကျွန်တော်အရင်က sharing လုပ်ထားတာရှိပါတယ်.
ansible dynamic inventory ကိုမသုံးဘဲ static inventory ကိုသုံးလဲရပါတယ်. ansible static inventory နဲ့ပါတ်သက်ပြီး ကျွန်တော်အရင်က sharing လုပ်ထားတာရှိပါတယ်.
ကျွန်တော်တို့ DevSec Hardening Framework ကိုသုံးပြီး os-hardening လုပ်ကြည့်ရအောင်.
ကျွန်တော်တို့ အရင်ဆုံး EC2 instances တွေကို ansible နဲ့ passwordless authentication access လုပ်လို့ရတာကို check လုပ်ပါမယ်.
ကျွန်တော်တို့ ansible dynamic inventory ကိုသုံးပါမယ်.
ansible-inventory --graph

ansible ad-hoc command ကိုသုံးပြီး EC2 instances တွေမှာ ping and sudoers access ရမရကို check လုပ်ပါမယ်.
ansible aws_ec2 -m ping -b

EC2 instances တွေကို ping and sudoers access ရရင် ကျွန်တော်တို့ os-hardening ကိုစမ်းကြည့်ရအောင်.
ping က ICMP ping မဟုတ်ပါဘူး, ကျွန်တော်တို့ automate လုပ်မဲ့ resources တွေမှာ python interpreter ရှိမရှိကို check လုပ်တာပါ.
ansible-doc ping

ကျွန်တော်တို့ DevSec Hardening Framework ထဲက os-hardening role ကိုသုံးပြီး hardening လုပ်မှာပါ.
os-hardening role က configure လုပ်မှာတွေကို အောက်ပါ link မှာကြည့်ပါ.

ကျွန်တော်တို့ os-hardening role ကို ansible playbook မှာမသုံးခင်မှာ role မှာသက်မှတ်ထားတာတွေကို လေ့လာကြည့်ရအောင်.
os-hardening role ထဲက main.yaml က role မှာသက်မှတ်ထားတဲ့ tasks တွေကို run မှာပါ.

main.yml က hardening.yml file ကို import လုပ်ထားပါတယ်. ansible မှာ playbook, tasks and roles တွေကို import လုပ်ပြီးသုံးတာနဲ့ပါတ်သက်ပြီးကျွန်တော်အရင်က sharing လုပ်ထားတာရှိပါတယ်.
hardening.yml ကိုလေ့လာကြည့်ရအောင်.

hardening.yml file မှာ os-hardening လုပ်တဲ့ playbooks တွေကိုအဓိက သက်မှတ်ထားပါတယ်.
os-hardening roles မှာသုံးတဲ variables တွေကို vars directory မှာသက်မှတ်ထားပါတယ်.

ကျွန်တော်တို့က roles variables တွေကို အလုပ်ရဲ့လိုအပ်ချက်ပေါ်မူတည်ပြီး ပြောင်းလို့ရပါတယ်.
ကျွန်တော်တို့ os-hardening role ကို EC2 instances တွေမှာသုံးကြည့်ရအောင်.
AWS EC2 instances တွေရဲ့ dynamic inventory ကို region or tag အပေါ်မူတည်ပြီးလဲသုံးလို့ရပါတယ်.
vim os-hardening.yaml
- name: os-hardening with DevSec Hardening Framework
hosts: aws_ec2 # aws ec2 dynamic inventory
collections:
- devsec.hardening
roles:
- os_hardening
vars:
sysctl_overwrite:
# Enable IPv4 traffic forwarding.
net.ipv4.ip_forward: 1
vars keyword ကိုသုံးပြီးကိုယ်ပြောင်းချင်တဲ့ variables value တွေကိုသက်မှတ်လို့ရပါတယ်.
ကျွန်တော်တို့ os-hardening role ရဲ့ vars directory မှာသက်မှတ်ထားတာတဲ့ variables တွေကို အလုပ်ရဲ့လိုအပ်ချက်အရပြောင်းလို့ရပါတယ်.
ansible မှာ variables တွေကိုအသုံးပြုပုံကို ကျွန်တော်အရင်က sharing လုပ်ထားတာရှိပါတယ်.
ansible playbook ကို run ကြည့်ရအောင်.
ansible-playbook --syntax-check os-hardening.yaml
ansible-playbook os-hardening.yaml


ကျွန်တော်တို့ AWS EC2 Instances တွေကို os-hardening လုပ်တဲ့အပိုင်းကအဆင်ပြေပါပြီး.
DevSec Hardening Framework က အခြား hardening အပိုင်းမှာလဲသုံးရတာအဆင်ပြေပါတယ်.
ကျွန်တော်တို့ ansible ကိုဆက်လေ့လာလိုလျှင်.
https://www.ansiblefordevops.com/
https://www.jeffgeerling.com/blog/2020/ansible-101-jeff-geerling-youtube-streaming-series