mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-07 09:42:46 +01:00
223 lines
5.6 KiB
Plaintext
223 lines
5.6 KiB
Plaintext
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
|
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
|
# https://securityonion.net/license; you may not use this file except in compliance with the
|
|
# Elastic License 2.0.
|
|
|
|
{% from 'allowed_states.map.jinja' import allowed_states %}
|
|
{% if sls in allowed_states and grains.role not in ['so-manager', 'so-managersearch'] %}
|
|
|
|
{% from 'vars/globals.map.jinja' import GLOBALS %}
|
|
{% from "suricata/map.jinja" import SURICATAOPTIONS with context %}
|
|
|
|
{% set interface = salt['pillar.get']('sensor:interface') %}
|
|
{% set BPF_NIDS = salt['pillar.get']('bpf:suricata', None) %}
|
|
{% set BPF_STATUS = 0 %}
|
|
|
|
{# import_yaml 'suricata/files/defaults2.yaml' as suricata #}
|
|
{% from 'suricata/suricata_config.map.jinja' import suricata_defaults as suricata_config with context %}
|
|
{% from "suricata/map.jinja" import START with context %}
|
|
|
|
# Suricata
|
|
|
|
# Add Suricata Group
|
|
suricatagroup:
|
|
group.present:
|
|
- name: suricata
|
|
- gid: 940
|
|
|
|
# Add Suricata user
|
|
suricata:
|
|
user.present:
|
|
- uid: 940
|
|
- gid: 940
|
|
- home: /nsm/suricata
|
|
- createhome: False
|
|
|
|
socoregroupwithsuricata:
|
|
group.present:
|
|
- name: socore
|
|
- gid: 939
|
|
- addusers:
|
|
- suricata
|
|
|
|
suridir:
|
|
file.directory:
|
|
- name: /opt/so/conf/suricata
|
|
- user: 940
|
|
- group: 940
|
|
|
|
suriruledir:
|
|
file.directory:
|
|
- name: /opt/so/conf/suricata/rules
|
|
- user: 940
|
|
- group: 940
|
|
- makedirs: True
|
|
|
|
surilogdir:
|
|
file.directory:
|
|
- name: /opt/so/log/suricata
|
|
- user: 940
|
|
- group: 939
|
|
|
|
suridatadir:
|
|
file.directory:
|
|
- name: /nsm/suricata/extracted
|
|
- user: 940
|
|
- group: 939
|
|
- mode: 770
|
|
- makedirs: True
|
|
|
|
surirulesync:
|
|
file.recurse:
|
|
- name: /opt/so/conf/suricata/rules/
|
|
- source: salt://suricata/rules/
|
|
- user: 940
|
|
- group: 940
|
|
- show_changes: False
|
|
|
|
surilogscript:
|
|
file.managed:
|
|
- name: /usr/local/bin/surilogcompress
|
|
- source: salt://suricata/cron/surilogcompress
|
|
- mode: 755
|
|
|
|
/usr/local/bin/surilogcompress:
|
|
cron.present:
|
|
- user: suricata
|
|
- minute: '17'
|
|
- hour: '*'
|
|
- daymonth: '*'
|
|
- month: '*'
|
|
- dayweek: '*'
|
|
|
|
suriconfig:
|
|
file.managed:
|
|
- name: /opt/so/conf/suricata/suricata.yaml
|
|
- source: salt://suricata/files/suricata.yaml.jinja
|
|
- context:
|
|
suricata_config: {{ suricata_config.suricata.config }}
|
|
- user: 940
|
|
- group: 940
|
|
- template: jinja
|
|
|
|
surithresholding:
|
|
file.managed:
|
|
- name: /opt/so/conf/suricata/threshold.conf
|
|
- source: salt://suricata/files/threshold.conf.jinja
|
|
- user: 940
|
|
- group: 940
|
|
- template: jinja
|
|
|
|
# BPF compilation and configuration
|
|
{% if BPF_NIDS %}
|
|
{% set BPF_CALC = salt['cmd.script']('/usr/sbin/so-bpf-compile', interface + ' ' + BPF_NIDS|join(" "),cwd='/root') %}
|
|
{% if BPF_CALC['stderr'] == "" %}
|
|
{% set BPF_STATUS = 1 %}
|
|
{% else %}
|
|
suribpfcompilationfailure:
|
|
test.configurable_test_state:
|
|
- changes: False
|
|
- result: False
|
|
- comment: "BPF Syntax Error - Discarding Specified BPF"
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
suribpf:
|
|
file.managed:
|
|
- name: /opt/so/conf/suricata/bpf
|
|
- user: 940
|
|
- group: 940
|
|
{% if BPF_STATUS %}
|
|
- contents_pillar: nids:bpf
|
|
{% else %}
|
|
- contents:
|
|
- ""
|
|
{% endif %}
|
|
|
|
so-suricata:
|
|
docker_container.{{ SURICATAOPTIONS.status }}:
|
|
{% if SURICATAOPTIONS.status == 'running' %}
|
|
- image: {{ GLOBALS.registry_host }}:5000/{{ GLOBALS.image_repo }}/so-suricata:{{ GLOBALS.so_version }}
|
|
- start: {{ SURICATAOPTIONS.start }}
|
|
- privileged: True
|
|
- environment:
|
|
- INTERFACE={{ interface }}
|
|
- binds:
|
|
- /opt/so/conf/suricata/suricata.yaml:/etc/suricata/suricata.yaml:ro
|
|
- /opt/so/conf/suricata/threshold.conf:/etc/suricata/threshold.conf:ro
|
|
- /opt/so/conf/suricata/rules:/etc/suricata/rules:ro
|
|
- /opt/so/log/suricata/:/var/log/suricata/:rw
|
|
- /nsm/suricata/:/nsm/:rw
|
|
- /nsm/suricata/extracted:/var/log/suricata//filestore:rw
|
|
- /opt/so/conf/suricata/bpf:/etc/suricata/bpf:ro
|
|
- network_mode: host
|
|
- watch:
|
|
- file: suriconfig
|
|
- file: surithresholding
|
|
- file: /opt/so/conf/suricata/rules/
|
|
- file: /opt/so/conf/suricata/bpf
|
|
- require:
|
|
- file: suriconfig
|
|
- file: surithresholding
|
|
- file: suribpf
|
|
|
|
{% else %} {# if Suricata isn't enabled, then stop and remove the container #}
|
|
- force: True
|
|
{% endif %}
|
|
|
|
append_so-suricata_so-status.conf:
|
|
file.append:
|
|
- name: /opt/so/conf/so-status/so-status.conf
|
|
- text: so-suricata
|
|
- unless: grep -q so-suricata /opt/so/conf/so-status/so-status.conf
|
|
|
|
{% if not SURICATAOPTIONS.start %}
|
|
so-suricata_so-status.disabled:
|
|
file.comment:
|
|
- name: /opt/so/conf/so-status/so-status.conf
|
|
- regex: ^so-suricata$
|
|
{% else %}
|
|
delete_so-suricata_so-status.disabled:
|
|
file.uncomment:
|
|
- name: /opt/so/conf/so-status/so-status.conf
|
|
- regex: ^so-suricata$
|
|
{% endif %}
|
|
|
|
surirotate:
|
|
cron.absent:
|
|
- name: /usr/local/bin/surirotate
|
|
- user: root
|
|
- minute: '11'
|
|
- hour: '*'
|
|
- daymonth: '*'
|
|
- month: '*'
|
|
- dayweek: '*'
|
|
|
|
so-suricata-eve-clean:
|
|
file.managed:
|
|
- name: /usr/sbin/so-suricata-eve-clean
|
|
- user: root
|
|
- group: root
|
|
- mode: 755
|
|
- template: jinja
|
|
- source: salt://suricata/cron/so-suricata-eve-clean
|
|
|
|
# Add eve clean cron
|
|
clean_suricata_eve_files:
|
|
cron.present:
|
|
- name: /usr/sbin/so-suricata-eve-clean > /dev/null 2>&1
|
|
- user: root
|
|
- minute: '*/5'
|
|
- hour: '*'
|
|
- daymonth: '*'
|
|
- month: '*'
|
|
- dayweek: '*'
|
|
|
|
{% else %}
|
|
|
|
{{sls}}_state_not_allowed:
|
|
test.fail_without_changes:
|
|
- name: {{sls}}_state_not_allowed
|
|
|
|
{% endif %}
|