-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple Firewall Configuration (#157)
* Firewall changes: - Firewalld Services instead of ephemeral commands - New port format to specify protocol for modularity - Defaults to UFW and if RHEL uses firewalld - Added default firewall ports per group var - Checks to see if firewall package is installed and service is running and enabled * Handlers for firewalls and merge into single yml * Firewall change requests - port proto combos predefined and referenced - super user privileges for handlers and package interactions * Firewall changes after tests - SSH Allow in UFW - Make Firewalld aware of service - Removing unnecessary reload handle of UFW - Adding RHEL 8 firewall_service * replace with firewalld in name for task running only for firewalld * Adding comments and desc to port dictionary Co-authored-by: David Twersky <jewunix@gmail.com>
- Loading branch information
Showing
12 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
splunk_firewall_ports: | ||
- "{{ splunkweb_port }}" | ||
- "{{ splunkapi_port }}" | ||
- "{{ splunktcpin_port }}" | ||
- "{{ splunkhec_port }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
splunk_firewall_ports: | ||
- "{{ splunkweb_port }}" | ||
- "{{ splunkapi_port }}" | ||
- "{{ splunktcpin_port }}" | ||
- "{{ splunkhec_port }}" | ||
- "{{ splunkidxcrep_port }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
splunk_firewall_ports: | ||
- "{{ splunkweb_port }}" | ||
- "{{ splunkapi_port }}" | ||
- "{{ splunkshcrep_port }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
- name: Ensure {{ firewall_service }} package is installed | ||
ansible.builtin.package: | ||
name: "{{ firewall_service }}" | ||
state: present | ||
become: true | ||
|
||
- name: Configure firewalld for Splunk | ||
block: | ||
- name: Ensure firewalld is Started and Enabled | ||
ansible.builtin.systemd: | ||
name: "{{ firewall_service }}" | ||
state: started | ||
enabled: true | ||
become: true | ||
|
||
- name: Add splunk firewalld service | ||
ansible.builtin.template: | ||
src: firewalld_service.xml.j2 | ||
dest: /etc/firewalld/services/{{ splunk_firewall_service }}.xml | ||
backup: true | ||
mode: 0644 | ||
owner: root | ||
group: root | ||
become: true | ||
register: firewalld | ||
|
||
- name: reload firewalld | ||
command: firewall-cmd --reload | ||
become: true | ||
when: firewalld.changed | ||
|
||
- name: Activate splunk firewalld service | ||
ansible.posix.firewalld: | ||
service: "{{ splunk_firewall_service }}" | ||
permanent: true | ||
state: enabled | ||
immediate: true | ||
notify: reload firewalld | ||
become: true | ||
when: firewall_service == "firewalld" | ||
|
||
- name: Configure UFW for Splunk | ||
block: | ||
- name: Ensure SSH is enabled | ||
community.general.ufw: | ||
port: 22 | ||
proto: tcp | ||
rule: allow | ||
state: enabled | ||
become: true | ||
|
||
- name: Add splunk port to UFW | ||
community.general.ufw: | ||
port: "{{ item.number }}" | ||
proto: "{{ item.protocol }}" | ||
rule: allow | ||
state: reloaded | ||
comment: "{{ item.desc | default('') }}" | ||
become: true | ||
loop: "{{ splunk_firewall_ports }}" | ||
when: firewall_service == "ufw" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<service> | ||
<short>splunk</short> | ||
<description>Ports to be configured for splunk</description> | ||
{% for port in splunk_firewall_ports %} | ||
<!-- {{ port.desc | default('') }} --> | ||
<port protocol="{{ port.protocol }}" port="{{ port.number }}"/> | ||
{% endfor %} | ||
</service> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ linux_packages: | |
- nethogs | ||
- gdb | ||
- dnsutils | ||
firewall_service: ufw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ linux_packages: | |
- nethogs | ||
- gdb | ||
- bind-utils | ||
firewall_service: firewalld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ linux_packages: | |
- nethogs | ||
- gdb | ||
- bind-utils | ||
firewall_service: firewalld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters