Skip to content

Commit c8a6b59

Browse files
committed
ignore duplicate apps
1 parent f594478 commit c8a6b59

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

filter_plugins/util.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@ class FilterModule(object):
66
def filters(self):
77
return {
88
'safe_key': self.safe_key,
9+
'unique_apps': self.unique_apps,
910
}
1011

1112
@staticmethod
1213
def safe_key(key: str) -> str:
1314
return regex_replace('[^0-9a-zA-Z_]+', '', key.replace(' ', '_'))
15+
16+
@staticmethod
17+
def unique_apps(all_apps: list) -> list:
18+
apps = []
19+
20+
for app in all_apps:
21+
try:
22+
if app['name'] not in apps:
23+
apps.append(app)
24+
25+
except KeyError:
26+
pass
27+
28+
return apps

tasks/debian/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
waf_app_rules_default_dir: "{{ WAF_HC.path.cnf }}/{{ WAF_HC.path.dir.cnf_rules }}/_tmpl/{{ waf_app.ruleset_version }}"
4747
loop_control:
4848
loop_var: waf_app_user
49-
loop: "{{ WAF_CONFIG.apps }}"
49+
loop: "{{ WAF_CONFIG.apps | unique_apps }}"
5050
no_log: true
5151
tags: [config, rules, apps]
5252
args:
@@ -63,3 +63,5 @@
6363
- name: HAProxy WAF | Logging
6464
ansible.builtin.import_tasks: debian/logging.yml
6565
tags: [logs]
66+
67+
# todo: cleanup non-existent/orphaned apps

templates/etc/coraza/spoa.yml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ log_level: '{{ WAF_CONFIG.log.level }}'
99
log_format: '{{ WAF_CONFIG.log.format }}'
1010

1111
applications:
12-
{% for user_app in WAF_CONFIG.apps %}
12+
{% for user_app in WAF_CONFIG.apps | unique_apps %}
1313
{% set app = defaults_app | combine(user_app, recursive=true) %}
1414
{% set name = app.name | safe_key %}
1515
{% set path_rules = (WAF_HC.path.cnf + '/' + WAF_HC.path.dir.cnf_rules + '/' + name + '/' + app.ruleset_version) %}

templates/etc/rsyslog.d/coraza-spoa.conf.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module(load="imfile" PollingInterval="{{ WAF_CONFIG.log.poll_interval_sec }}")
22

3-
{% for user_app in WAF_CONFIG.apps %}
3+
{% for user_app in WAF_CONFIG.apps | unique_apps %}
44
{% set app = defaults_app | combine(user_app, recursive=true) %}
55
{% set name = app.name | safe_key %}
66
input(

0 commit comments

Comments
 (0)