- 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 Hadoop 3
- 輕松學C語言
- WOW!Illustrator CS6完全自學寶典
- 80x86/Pentium微型計算機原理及應用
- 計算機網絡技術實訓
- Flink原理與實踐
- PowerMill 2020五軸數控加工編程應用實例
- Cloudera Hadoop大數據平臺實戰指南
- 計算機硬件技術基礎(第2版)
- Kubernetes on AWS
- 工程地質地學信息遙感自動提取技術
- Microsoft Power BI Complete Reference
- Cloud Native Development Patterns and Best Practices
- 數據庫技術:Access 2003 計算機網絡技術
- 實戰GAN:TensorFlow與Keras生成對抗網絡構建