Skip to content

Commit

Permalink
Implement rate limiting
Browse files Browse the repository at this point in the history
Refs #70
  • Loading branch information
bviktor committed Mar 3, 2023
1 parent 00c3c11 commit 6f3216d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
4 changes: 4 additions & 0 deletions roles/install/files/kf2-ddos.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:msg, regex, ".*_DROP: .* DPT=7777 .*" /var/log/kf2-ddos.log
& stop
:msg, regex, ".*_REJECT: .* DPT=7777 .*" /var/log/kf2-ddos.log
& stop
9 changes: 9 additions & 0 deletions roles/install/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
systemd:
daemon_reload: true
when: servicecheck.systemd

- name: Reload firewalld configuration
command:
cmd: firewall-cmd --reload

- name: Reload rsyslog configuration
systemd:
name: rsyslog.service
state: restarted
32 changes: 27 additions & 5 deletions roles/install/tasks/firewalld.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
---
- include_role:
name: bviktor.servicecheck
vars:
unit: firewalld.service
- name: Install rsyslog
package:
name: rsyslog
state: latest

- name: Enable rsyslog
systemd:
name: rsyslog.service
state: started
enabled: true

- name: Configure KF2 DDoS logging
copy:
src: kf2-ddos.conf
dest: /etc/rsyslog.d/kf2-ddos.conf
owner: root
group: root
mode: '0644'
notify: Reload rsyslog configuration

- name: Log packets denied by firewalld
lineinfile:
path: /etc/firewalld/firewalld.conf
regexp: '^LogDenied='
line: LogDenied=all
notify: Reload firewalld configuration

- include_role:
name: bviktor.firewalld
vars:
service: 'kf2'
port: "{{ item }}"
rate_limit: '10/m'
loop:
- '7777/udp'
- '20560/udp'
- '27015/udp'
- '8080/tcp'
when: servicecheck.started
8 changes: 8 additions & 0 deletions roles/install/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
- include_tasks: kf2.yml
- include_tasks: systemd.yml
- include_tasks: sudo.yml

- include_role:
name: bviktor.servicecheck
vars:
unit: firewalld.service

- include_tasks: firewalld.yml
when: servicecheck.started

- include_tasks: config.yml
- include_tasks: autokick.yml
- include_tasks: killinuxfloor.yml
Expand Down

0 comments on commit 6f3216d

Please sign in to comment.