- Security Automation with Ansible 2
- Madhu Akula Akash Mahajan
- 201字
- 2021-07-02 22:00:00
Hardening a host firewall service
The following code snippet is for installing and configuring the uncomplicated firewall (UFW) with its required services and rules. Ansible even has a module for UFW, so the following snippet starts with installing this and enabling logging. It follows this by adding default policies, like default denying all incoming and allowing outgoing.
Then it will add SSH, HTTP, and HTTPS services to allow incoming. These options are completely configurable, as required. Then it will enable and add to startup programs that apply the changes:
- name: installing ufw package apt:
name: "ufw"
update_cache: yes
state: present - name: enable ufw logging ufw:
logging: on - name: default ufw setting ufw:
direction: "{{ item.direction }}"
policy: "{{ item.policy }}"
with_items: - { direction: 'incoming', policy: 'deny' } - { direction: 'outgoing', policy: 'allow' } - name: allow required ports to access server ufw:
rule: "{{ item.policy }}"
port: "{{ item.port }}"
proto: "{{ item.protocol }}" with_items: - { port: "22", protocol: "tcp", policy: "allow" } - { port: "80", protocol: "tcp", policy: "allow" } - { port: "443", protocol: "tcp", policy: "allow" } - name: enable ufw ufw:
state: enabled - name: restart ufw and add to start up programs service:
name: ufw
state: restarted
enabled: yes
推薦閱讀
- Mastering Mesos
- ArchiCAD 19:The Definitive Guide
- 32位嵌入式系統與SoC設計導論
- Mastercam 2017數控加工自動編程經典實例(第4版)
- Cloud Analytics with Microsoft Azure
- CSS全程指南
- 大數據挑戰與NoSQL數據庫技術
- INSTANT Autodesk Revit 2013 Customization with .NET How-to
- Salesforce Advanced Administrator Certification Guide
- 液壓機智能故障診斷方法集成技術
- IBM? SmartCloud? Essentials
- 一步步寫嵌入式操作系統
- 三菱FX/Q系列PLC工程實例詳解
- 工業機器人力覺視覺控制高級應用
- Web編程基礎