Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
206cd3949f | ||
|
|
d9744f3f85 | ||
|
|
2b293e9835 |
+15
-29
@@ -53,7 +53,6 @@
|
|||||||
- /etc/crowdsec/bouncers
|
- /etc/crowdsec/bouncers
|
||||||
- /etc/crowdsec/parsers/s02-enrich
|
- /etc/crowdsec/parsers/s02-enrich
|
||||||
- /etc/systemd/system/crowdsec.service.d
|
- /etc/systemd/system/crowdsec.service.d
|
||||||
- /etc/systemd/system/crowdsec-hubupdate.service.d
|
|
||||||
- /etc/systemd/system/crowdsec-firewall-bouncer.service.d
|
- /etc/systemd/system/crowdsec-firewall-bouncer.service.d
|
||||||
- /etc/systemd/system/nftables.service.d
|
- /etc/systemd/system/nftables.service.d
|
||||||
|
|
||||||
@@ -172,35 +171,22 @@
|
|||||||
when: crowdsec_missing | length > 0
|
when: crowdsec_missing | length > 0
|
||||||
notify: Restart crowdsec
|
notify: Restart crowdsec
|
||||||
|
|
||||||
# The script upgrades every hub item with --force (a scenario removed with --force taints its collection, and a plain upgrade skips
|
# Read again: the collections installed above bring their scenarios along.
|
||||||
# tainted collections) and removes the disabled scenarios again. It runs here once and daily as crowdsec-hubupdate.service.
|
- name: List the installed hub scenarios
|
||||||
- name: Install the hub update script
|
ansible.builtin.command: cscli hub list -o json
|
||||||
ansible.builtin.template:
|
register: crowdsec_scenarios_json
|
||||||
src: crowdsec-hubupdate.sh.j2
|
changed_when: false
|
||||||
dest: /usr/local/sbin/crowdsec-hubupdate
|
failed_when: crowdsec_scenarios_json.rc != 0 and not ansible_check_mode
|
||||||
mode: "0755"
|
check_mode: false
|
||||||
|
|
||||||
- name: Run the hub update script instead of the package one
|
# --force also removes items that belong to an installed collection. A plain "cscli hub upgrade" keeps them removed;
|
||||||
ansible.builtin.copy:
|
# "cscli hub upgrade --force" would bring them back.
|
||||||
dest: /etc/systemd/system/crowdsec-hubupdate.service.d/override.conf
|
- name: Remove the hub scenarios replaced by local ones
|
||||||
mode: "0644"
|
ansible.builtin.command: "cscli scenarios remove {{ item.value }} --force"
|
||||||
content: |
|
loop: "{{ crowdsec.disabled_scenarios | dict2items | rejectattr('value', 'none') }}"
|
||||||
[Service]
|
loop_control:
|
||||||
ExecStart=
|
label: "{{ item.value }}"
|
||||||
ExecStart=/usr/local/sbin/crowdsec-hubupdate
|
when: item.value in ((crowdsec_scenarios_json.stdout | default('{}', true) | from_json).scenarios | default([], true) | map(attribute='name'))
|
||||||
register: crowdsec_hubupdate_dropin
|
|
||||||
|
|
||||||
- name: Reload systemd for the hub update unit
|
|
||||||
ansible.builtin.systemd:
|
|
||||||
daemon_reload: true
|
|
||||||
when: crowdsec_hubupdate_dropin is changed
|
|
||||||
|
|
||||||
- name: Upgrade the hub items and remove the disabled scenarios
|
|
||||||
ansible.builtin.command: /usr/local/sbin/crowdsec-hubupdate
|
|
||||||
environment:
|
|
||||||
NO_RELOAD: "1"
|
|
||||||
register: crowdsec_hubupdate
|
|
||||||
changed_when: "'changed' in crowdsec_hubupdate.stdout"
|
|
||||||
notify: Restart crowdsec
|
notify: Restart crowdsec
|
||||||
|
|
||||||
- name: Install the local parsers and scenarios
|
- name: Install the local parsers and scenarios
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Managed by Ansible. crowdsec-hubupdate.service runs this script instead of /usr/libexec/crowdsec/hubupdate.sh.
|
|
||||||
#
|
|
||||||
# "cscli scenarios remove --force" taints the collection that holds the scenario, and a plain "cscli hub upgrade" skips tainted
|
|
||||||
# collections for good. The upgrade therefore runs with --force, which also brings the removed scenarios back, and the removal is
|
|
||||||
# applied again. crowdsec is reloaded only when the installed hub files or the data files differ afterwards; with NO_RELOAD=1
|
|
||||||
# the script prints "changed" instead, for the role, which restarts crowdsec once at the end of its run.
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
test -x /usr/bin/cscli || exit 0
|
|
||||||
|
|
||||||
fingerprint() {
|
|
||||||
{
|
|
||||||
find -L /etc/crowdsec -path /etc/crowdsec/hub -prune -o -type f -exec sha256sum {} +
|
|
||||||
find /var/lib/crowdsec/data -maxdepth 1 -type f ! -name 'crowdsec.db*' ! -name trace -exec sha256sum {} +
|
|
||||||
} 2>/dev/null | sort -k2 | sha256sum
|
|
||||||
}
|
|
||||||
|
|
||||||
before="$(fingerprint)"
|
|
||||||
|
|
||||||
/usr/bin/cscli --error hub update >/dev/null
|
|
||||||
/usr/bin/cscli --error hub upgrade --force >/dev/null
|
|
||||||
|
|
||||||
{% for scenario in crowdsec.disabled_scenarios.values() | reject('none') | unique | sort %}
|
|
||||||
if /usr/bin/cscli scenarios list -o raw | cut -d, -f1 | grep -qxF '{{ scenario }}'; then
|
|
||||||
/usr/bin/cscli --error scenarios remove '{{ scenario }}' --force >/dev/null
|
|
||||||
fi
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
if [ "$before" != "$(fingerprint)" ]; then
|
|
||||||
if [ -n "${NO_RELOAD:-}" ]; then
|
|
||||||
echo changed
|
|
||||||
else
|
|
||||||
systemctl reload crowdsec.service
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
Reference in New Issue
Block a user