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.

119 lines
3.6KB

  1. {% from "apache/map.jinja" import apache with context %}
  2. {% import_yaml "apache/hardening-values.yaml" as hardening_values %}
  3. {% import_yaml "apache/defaults/" ~ salt['grains.get']('os_family') ~ "/defaults-apache-" ~ apache.version ~ ".yaml" as global_defaults %}
  4. include:
  5. - apache
  6. - apache.mod_ssl
  7. - apache.hardening
  8. {# merge defaults with pillar content #}
  9. {% set pillar_server_config = salt['pillar.get']('apache:server_apache_config', {}) %}
  10. {% set server_config = salt['apache_directives.merge_container_with_additional_data'](
  11. global_defaults.server_apache_config,
  12. pillar_server_config) %}
  13. {# enforce directives values #}
  14. {% for directive, directive_data in hardening_values.enforced_directives.items() %}
  15. {% set server_config = salt['apache_directives.enforce_directive_value'](directive,
  16. directive_data,
  17. container_name='server',
  18. container_data=server_config) %}
  19. {% endfor %}
  20. {# merge server config with hardened sections #}
  21. {% set server_config = salt['apache_directives.enforce_security_directives_into_containers'](
  22. server_config,
  23. hardening_values.enforced_containers ) %}
  24. {# remove containers #}
  25. {% for container_name_to_remove, items_names in hardening_values.containers_to_remove.items() %}
  26. {% for item_name in items_names %}
  27. {% set server_config = salt['apache_directives.remove_container'](
  28. server_config,
  29. container_name_to_remove,
  30. item_name) %}
  31. {% endfor %}
  32. {% endfor %}
  33. {# add supplemental security directives in server configuration #}
  34. {% for d_directive in hardening_values.server_supplemental_directives %}
  35. {% for directive, value in d_directive.items() %}
  36. {% set server_config = salt['apache_directives.append_to_container_directives'](
  37. directive,
  38. value,
  39. server_config) %}
  40. {% endfor %}
  41. {% endfor %}
  42. {% if grains['os_family']=="RedHat" %}
  43. {{ apache.logdir }}:
  44. file.directory:
  45. - makedirs: True
  46. - require:
  47. - pkg: apache
  48. - user: root
  49. - group: {{ apache.group }}
  50. - dir_mode: 750
  51. - watch_in:
  52. - module: apache-restart
  53. - require_in:
  54. - module: apache-restart
  55. - module: apache-reload
  56. - service: apache
  57. {{ apache.configfile }}:
  58. file.managed:
  59. - template: jinja
  60. - source:
  61. - salt://apache/files/{{ salt['grains.get']('os_family') }}/apache-{{ apache.version }}.config.jinja
  62. - user: root
  63. - group: root
  64. - mode: 644
  65. - require:
  66. - pkg: apache
  67. - watch_in:
  68. - module: apache-restart
  69. - require_in:
  70. - module: apache-restart
  71. - module: apache-reload
  72. - service: apache
  73. - context:
  74. apache: {{ apache | json}}
  75. server_config: {{ server_config | json }}
  76. {{ apache.vhostdir }}:
  77. file.directory:
  78. - makedirs: True
  79. - require:
  80. - pkg: apache
  81. - user: root
  82. - group: root
  83. - dir_mode: 755
  84. - file_mode: 644
  85. - recurse:
  86. - user
  87. - group
  88. - mode
  89. - watch_in:
  90. - module: apache-restart
  91. - require_in:
  92. - module: apache-restart
  93. - module: apache-reload
  94. - service: apache
  95. {{ apache.confdir }}/welcome.conf:
  96. file.managed:
  97. - source:
  98. - salt://apache/files/{{ salt['grains.get']('os_family') }}/welcome.conf
  99. - user: root
  100. - group: root
  101. - mode: 644
  102. - require:
  103. - pkg: apache
  104. - watch_in:
  105. - service: apache
  106. {% endif %}