Saltstack Official Apache Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3KB

  1. {%- set apache = pillar.get('apache', {}) %}
  2. {%- set mod_security = apache.get('mod_security', {}) %}
  3. {%- if mod_security.get('manage_config', False) %}
  4. include:
  5. - apache.mod_security
  6. {%- for rule_name, rule_details in mod_security.get('rules', {}).items() %}
  7. {%- set rule_set = rule_details.get('rule_set', '') %}
  8. {%- set enabled = rule_details.get('enabled', False ) %}
  9. {%- if enabled %}
  10. /etc/modsecurity/{{ rule_name }}:
  11. file.symlink:
  12. - target: /usr/share/modsecurity-crs/{{ rule_set }}/{{ rule_name }}
  13. - user: {{ apache.rootuser }}
  14. - group: {{ apache.rootgroup }}
  15. - mode: 755
  16. {%- else %}
  17. /etc/modsecurity/{{ rule_name }}:
  18. file.absent:
  19. - name: /etc/modsecurity/{{ rule_name }}
  20. {%- endif %}
  21. {%- endfor %}
  22. {%- for custom_rule, custom_rule_details in mod_security.get('custom_rule_files', {}).items() %}
  23. {%- set file = custom_rule_details.get('file', None) %}
  24. {%- set path = custom_rule_details.get('path', None) %}
  25. {%- set enabled = custom_rule_details.get('enabled', False ) %}
  26. {%- if enabled %}
  27. /etc/modsecurity/{{ file }}:
  28. file.managed:
  29. - source: {{ path }}
  30. - user: {{ apache.rootuser }}
  31. - group: {{ apache.rootgroup }}
  32. - mode: 755
  33. - makedirs: True
  34. {%- else %}
  35. /etc/modsecurity/{{ file }}:
  36. file.absent:
  37. - name: /etc/modsecurity/{{ file }}
  38. {%- endif %}
  39. {%- endfor %}
  40. {%- endif %}