CrowdSec (detection only) and staged custom-Caddy plumbing

- crowdsec stack on lava reading Caddy's access log (logs/ subpath only),
  collections caddy, http-cve, base-http-scenarios, appsec-virtual-patching;
  AppSec listener on :7422; allowlist for lava, Tailscale, the server
- caddy_custom switch (image + plugin directives), staged by
  caddy_crowdsec_enforce / caddy_appsec / caddy_ratelimit; all off, so the
  rendered config is unchanged in effect
- (protect) on every site, (ratelimit_login) on login paths, both empty
  until enabled; caddy recreated when compose.yml or .env changes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-27 12:22:15 -07:00
1 parent 8aad8132b6
commit 48a4e48b84
13 files changed
+261 -1

No files matched your search

@@ -14,12 +14,24 @@
group: docker
notify: restart caddy
- name: template caddy .env (CrowdSec bouncer key)
ansible.builtin.template:
src: caddy-env.j2
dest: /opt/stacks/caddy/.env
owner: root
mode: '0640'
group: docker
diff: false
when: caddy_custom
register: caddy_env
- name: template caddy compose file
ansible.builtin.template:
src: caddy-compose.yml.j2
dest: /opt/stacks/caddy/compose.yml
owner: root
mode: '0644'
register: caddy_compose
- name: deploy caddy stack
community.docker.docker_compose_v2:
@@ -28,6 +40,16 @@
files:
- compose.yml
# recreate: never (above) keeps the running container, so a new image or env
# (caddy_custom on/off, a pinned tag) only applies through this task.
- name: recreate caddy when its compose file or .env changed
community.docker.docker_compose_v2:
project_src: /opt/stacks/caddy
recreate: always
files:
- compose.yml
when: caddy_compose.changed or (caddy_env.changed | default(false))
# Lets public traffic through to Caddy. Re-adds the rule if Caddy's IP changed.
- name: allow public traffic to caddy
ansible.builtin.command: /usr/local/bin/ufw-docker.sh allow caddy-caddy-1 {{ item }}
@@ -0,0 +1,68 @@
# CrowdSec next to Caddy. Unban: docker exec crowdsec cscli decisions delete --ip <ip>
- name: make crowdsec directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
loop:
- /opt/stacks/crowdsec
- /opt/stacks/crowdsec/acquis.d
- name: Template out the crowdsec compose file
ansible.builtin.template:
src: crowdsec-compose.yml.j2
dest: /opt/stacks/crowdsec/compose.yml
owner: root
mode: '0644'
- name: Template out the crowdsec .env file
ansible.builtin.template:
src: crowdsec-env.j2
dest: /opt/stacks/crowdsec/.env
owner: root
mode: '0640'
group: docker
diff: false # contains the bouncer key
- name: Template out the crowdsec acquisition files
ansible.builtin.template:
src: "crowdsec-acquis-{{ item }}.yaml.j2"
dest: "/opt/stacks/crowdsec/acquis.d/{{ item }}.yaml"
owner: root
mode: '0644'
loop: [caddy, appsec]
notify: restart crowdsec
- name: deploy crowdsec stack
community.docker.docker_compose_v2:
project_src: /opt/stacks/crowdsec
files:
- compose.yml
- name: wait for the crowdsec local API
ansible.builtin.command: docker exec crowdsec cscli lapi status
register: crowdsec_lapi
retries: 20
delay: 3
until: crowdsec_lapi.rc == 0
changed_when: false
when: not ansible_check_mode
# Our own networks are never banned (centralized allowlist, CrowdSec >= 1.6.8)
- name: read the crowdsec allowlist
ansible.builtin.command: docker exec crowdsec cscli allowlists inspect trusted -o json
register: crowdsec_allowlist_current
failed_when: false
changed_when: false
when: not ansible_check_mode
- name: create the crowdsec allowlist
ansible.builtin.command: docker exec crowdsec cscli allowlists create trusted -d "own networks (ansible)"
when: not ansible_check_mode and crowdsec_allowlist_current.rc != 0
- name: add missing entries to the crowdsec allowlist
ansible.builtin.command: >-
docker exec crowdsec cscli allowlists add trusted {{ item }} -d ansible
loop: "{{ crowdsec_allowlist }}"
when: >-
not ansible_check_mode and
(crowdsec_allowlist_current.rc != 0 or item not in crowdsec_allowlist_current.stdout)
@@ -9,6 +9,10 @@
import_tasks: pocketid.yml
tags: pocketid
- name: Install crowdsec
import_tasks: crowdsec.yml
tags: crowdsec
- name: Install tinyauth
import_tasks: tinyauth.yml
tags: tinyauth