Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Firewall Configuration #157

Merged
merged 6 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions environments/production/group_vars/heavyforwarder.yml
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 }}"
7 changes: 7 additions & 0 deletions environments/production/group_vars/indexer.yml
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 }}"
5 changes: 5 additions & 0 deletions environments/production/group_vars/search.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
splunk_firewall_ports:
- "{{ splunkweb_port }}"
- "{{ splunkapi_port }}"
- "{{ splunkshcrep_port }}"
13 changes: 13 additions & 0 deletions roles/splunk/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,16 @@ add_pstack_script: false # Set to true to install a pstack generation script for
configure_dmesg: false
install_utilities: false # Set to true to install the list of packages defined in the linux_packages var after installing splunk
use_tuned_thp: false
# Firewall configs
configure_firewall: false # Whether or not to configure the firewall service on your machine, if set to true, opens firewall ports using UFW (default) or Firewalld depending on OS
splunk_firewall_service: splunk # The name of the Splunk firewall service to install for firewalld
# Firewall port presets - reference these in group_vars to assign them to splunk
splunkweb_port: {desc: "Splunk Web", protocol: "tcp", number: 8000}
splunkhec_port: {desc: "Splunk HEC", protocol: "tcp", number: 8088}
splunktcpin_port: {desc: "Splunk TCPIN", protocol: "tcp", number: 9997}
splunkapi_port: {desc: "Splunk API", protocol: "tcp", number: "{{ splunkd_port }}"}
splunkidxcrep_port: {desc: "Splunk Indexer Clustering Replication", protocol: "tcp", number: "{{ splunk_idxc_rep_port }}"}
splunkshcrep_port: {desc: "Splunk Search Head Clustering Replication", protocol: "tcp", number: "{{ splunk_shc_rep_port }}"}
splunk_firewall_ports: # List of ports to allow through local firewall in dict form
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to define this? This will open the ports on UFs, and since the UF is no longer listening on 0.0.0.0:8089 by default, I don't think we need that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankfully it will not - in configure_os.yml I have this so that we don't install the firewall unless it's in the full category:

- name: Configure firewall service
  include_tasks: "configure_firewall.yml"
  when:
    - firewall_service != 'undefined'
    - configure_firewall != false
    - "'full' in group_names"

- "{{ splunkweb_port }}"
- "{{ splunkapi_port }}"
4 changes: 4 additions & 0 deletions roles/splunk/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@
port: "{{ splunkd_port }}"
state: started
delay: 5

- name: reload firewalld
command: firewall-cmd --reload
become: true
62 changes: 62 additions & 0 deletions roles/splunk/tasks/configure_firewall.yml
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"
7 changes: 7 additions & 0 deletions roles/splunk/tasks/configure_os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@
- name: Enable read for dmesg
include_tasks: configure_dmesg.yml
when: configure_dmesg

- name: Configure firewall service
include_tasks: "configure_firewall.yml"
when:
- firewall_service != 'undefined'
- configure_firewall != false
- "'full' in group_names"
9 changes: 9 additions & 0 deletions roles/splunk/templates/firewalld_service.xml.j2
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>
1 change: 1 addition & 0 deletions roles/splunk/vars/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ linux_packages:
- nethogs
- gdb
- dnsutils
firewall_service: ufw
1 change: 1 addition & 0 deletions roles/splunk/vars/RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ linux_packages:
- nethogs
- gdb
- bind-utils
firewall_service: firewalld
1 change: 1 addition & 0 deletions roles/splunk/vars/RedHat8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ linux_packages:
- nethogs
- gdb
- bind-utils
firewall_service: firewalld
1 change: 1 addition & 0 deletions roles/splunk/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ splunk_build: "{{ splunk_package_url | regex_search('\\d+\\.\\d+\\.\\d+(?:\\.\\d
# Create desired splunk version string (to compare with the output from the splunk version command for upgrades)
splunk_version: "{{ splunk_product }} {{ splunk_v }} (build {{ splunk_build }})"
splunk_auth: "{{ splunk_admin_username }}:{{ splunk_admin_password }}"
firewall_service: ufw