diff --git a/bootstrap/edge/main.tf b/bootstrap/edge/main.tf index 96019a8..6332d5f 100644 --- a/bootstrap/edge/main.tf +++ b/bootstrap/edge/main.tf @@ -10,6 +10,7 @@ terraform { locals { compose_file = templatefile("${path.module}/templates/docker-compose.yml.tftpl", {}) + crowdsec_acquis = templatefile("${path.module}/templates/crowdsec-acquis.yaml.tftpl", {}) heimdall_server_name = "heimdall.${var.server_name}" heimdall_backend_host = var.heimdall_backend_host != "" ? var.heimdall_backend_host : var.gitea_backend_host server_names = distinct(concat([var.server_name, local.heimdall_server_name], var.additional_server_names)) @@ -51,6 +52,7 @@ locals { }) : "" config_hash = sha256(join("\n---\n", [ local.compose_file, + local.crowdsec_acquis, local.default_conf, local.default_vcl, local.haproxy_cfg, @@ -105,6 +107,11 @@ resource "null_resource" "edge_services" { destination = "/tmp/homelab-edge/config_files/default.conf" } + provisioner "file" { + content = local.crowdsec_acquis + destination = "/tmp/homelab-edge/config_files/crowdsec-acquis.yaml" + } + provisioner "file" { content = local.default_vcl destination = "/tmp/homelab-edge/config_files/default.vcl" @@ -196,6 +203,7 @@ sudo mkdir -p \ "$install_dir/certbot/www" \ "$install_dir/letsencrypt" sudo cp /tmp/homelab-edge/docker-compose.yml "$install_dir/docker-compose.yml" +sudo cp /tmp/homelab-edge/config_files/crowdsec-acquis.yaml "$install_dir/config_files/crowdsec-acquis.yaml" sudo cp /tmp/homelab-edge/config_files/default.conf "$install_dir/config_files/default.conf" sudo cp /tmp/homelab-edge/config_files/default.vcl "$install_dir/config_files/default.vcl" sudo cp /tmp/homelab-edge/config_files/haproxy.cfg "$install_dir/config_files/haproxy.cfg" diff --git a/bootstrap/edge/templates/crowdsec-acquis.yaml.tftpl b/bootstrap/edge/templates/crowdsec-acquis.yaml.tftpl new file mode 100644 index 0000000..5850a4d --- /dev/null +++ b/bootstrap/edge/templates/crowdsec-acquis.yaml.tftpl @@ -0,0 +1,7 @@ +source: file +filenames: + - /var/log/nginx/access.log + - /var/log/nginx/error.log +labels: + type: nginx +force_inotify: true diff --git a/bootstrap/edge/templates/default.conf.tftpl b/bootstrap/edge/templates/default.conf.tftpl index 686b08c..da5e8de 100644 --- a/bootstrap/edge/templates/default.conf.tftpl +++ b/bootstrap/edge/templates/default.conf.tftpl @@ -3,6 +3,9 @@ map $request_uri $blocked_uris { ~*(/\.env|/\.git|/\.aws|/wp-admin) 1; } +access_log /var/log/nginx/access.log; +error_log /var/log/nginx/error.log warn; + limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s; proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=static_assets:10m max_size=100m inactive=24h; diff --git a/bootstrap/edge/templates/docker-compose.yml.tftpl b/bootstrap/edge/templates/docker-compose.yml.tftpl index a1a236a..3ed096d 100644 --- a/bootstrap/edge/templates/docker-compose.yml.tftpl +++ b/bootstrap/edge/templates/docker-compose.yml.tftpl @@ -14,6 +14,22 @@ services: - ./certbot/www:/var/www/certbot:ro - nginx_cache:/var/cache/nginx - nginx_dynamic_cache:/var/cache/nginx_dynamic + - nginx_logs:/var/log/nginx + + crowdsec: + image: crowdsecurity/crowdsec:latest + restart: unless-stopped + depends_on: + - nginx-dev + ports: + - "127.0.0.1:8080:8080" + environment: + COLLECTIONS: "crowdsecurity/nginx crowdsecurity/http-cve" + volumes: + - ./config_files/crowdsec-acquis.yaml:/etc/crowdsec/acquis.yaml:ro + - nginx_logs:/var/log/nginx:ro + - crowdsec_config:/etc/crowdsec + - crowdsec_data:/var/lib/crowdsec/data haproxy-dev: image: haproxy:alpine @@ -56,5 +72,8 @@ services: volumes: nginx_cache: nginx_dynamic_cache: + nginx_logs: + crowdsec_config: + crowdsec_data: squid_cache: squid_logs: