Saltstack Official UFW 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.

57 lines
2.0KB

  1. # -*- coding: utf-8 -*-
  2. # vim: ft=sls
  3. {#- Get the `tplroot` from `tpldir` #}
  4. {%- set tplroot = tpldir.split('/')[0] %}
  5. {%- set sls_package_install = tplroot ~ '.package.install' %}
  6. {%- set sls_enable_service = tplroot ~ '.service.enable' %}
  7. {%- set sls_reload_service = tplroot ~ '.service.reload' %}
  8. {%- from tplroot ~ "/map.jinja" import ufw with context %}
  9. include:
  10. - {{ sls_package_install }}
  11. - {{ sls_enable_service }}
  12. - {{ sls_reload_service }}
  13. # Services
  14. {%- for service_name, service_details in ufw.get('services', {}).items() %}
  15. {%- set from_addr_raw = service_details.get('from_addr', [None]) %}
  16. {%- set from_addrs = [from_addr_raw] if from_addr_raw is string else from_addr_raw %}
  17. {%- for from_addr in from_addrs %}
  18. {%- set protocol = service_details.get('protocol', None) %}
  19. {%- set deny = service_details.get('deny', None) %}
  20. {%- set limit = service_details.get('limit', None) %}
  21. {%- set method = 'deny' if deny else ('limit' if limit else 'allow') %}
  22. {%- set from_port = service_details.get('from_port', None) %}
  23. {%- set to_addr = service_details.get('to_addr', None) %}
  24. {%- set to_port = service_details.get('to_port', service_name) %}
  25. {%- set comment = service_details.get('comment', None) %}
  26. ufw-svc-{{ method }}-{{ service_name }}-{{ from_addr }}:
  27. ufw.{{ method }}:
  28. {%- if protocol is not none %}
  29. - protocol: {{ protocol }}
  30. {%- endif %}
  31. {%- if from_addr is not none %}
  32. - from_addr: {{ from_addr }}
  33. {%- endif %}
  34. {%- if from_port is not none %}
  35. - from_port: "{{ from_port }}"
  36. {%- endif %}
  37. {%- if to_addr is not none %}
  38. - to_addr: {{ to_addr }}
  39. {%- endif %}
  40. # Debian Jessie doesn't implement the **comment** directive
  41. # CentOS-6 throws an UTF-8 error
  42. {%- if comment is not none and salt['grains.get']('osfinger') != 'Debian-8' and salt['grains.get']('osfinger') != 'CentOS-6' %}
  43. - comment: '"{{ comment }}"'
  44. {%- endif %}
  45. - to_port: "{{ to_port }}"
  46. - listen_in:
  47. - cmd: reload-ufw
  48. {%- endfor %}
  49. {%- endfor %}