From 059f497ec0fd5e650747800c4b398483717af17d Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Fri, 13 Feb 2026 09:37:40 -0500 Subject: [PATCH] feat: Initial commit. --- .gitignore | 1 + Dockerfile | 16 ++++++++++++ LICENSE | 9 +++++++ README.md | 11 +++++++++ caddy/Caddyfile | 32 ++++++++++++++++++++++++ compose.yaml | 59 ++++++++++++++++++++++++++++++++++++++++++++ crowdsec/acquis.yaml | 5 ++++ example.env | 4 +++ 8 files changed, 137 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 caddy/Caddyfile create mode 100644 compose.yaml create mode 100644 crowdsec/acquis.yaml create mode 100644 example.env diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c24e983 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +ARG CADDY_VERSION=2 + +FROM docker.io/caddy:${CADDY_VERSION}-builder-alpine AS builder + +RUN xcaddy build \ + --with github.com/caddy-dns/cloudflare \ + --with github.com/mholt/caddy-l4 \ + --with github.com/caddyserver/transform-encoder \ + --with github.com/hslatman/caddy-crowdsec-bouncer/http@main \ + --with github.com/hslatman/caddy-crowdsec-bouncer/layer4@main + +FROM caddy:${CADDY_VERSION} AS caddy + +WORKDIR / + +COPY --from=builder /usr/bin/caddy /usr/bin/caddy diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6954f72 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2025 homelab + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f7508c --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# caddy + +This is the primary entrypoint / reverse proxy used for services that run under the `ductcalc.pro` +domain. + +## Usage + +1. clone this repository to the host +1. copy the `example.env` to `.env` +1. update the environment variables +1. start the stack diff --git a/caddy/Caddyfile b/caddy/Caddyfile new file mode 100644 index 0000000..be61719 --- /dev/null +++ b/caddy/Caddyfile @@ -0,0 +1,32 @@ +{ + email {env.ACME_EMAIL} + servers { + client_ip_headers X-Forwarded-For + trusted_proxies static private_ranges + trusted_proxies_strict + } + order crowdsec before respond + crowdsec { + api_url http://crowdsec:8080 + api_key {$CROWDSEC_API_KEY} + ticker_interval 15s + } + log { + level INFO + output file /var/log/caddy/access.log + roll_size 30MiB + roll_keep 5 + } + tls { + dns cloudflare {env.CF_AUTH_TOKEN} + resolvers 1.1.1.1 + } +} + +ductcalc.pro { + tls + log + crowdsec + reverse_proxy http://ductcalc:8080 +} + diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..f8d5d51 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,59 @@ +services: + caddy: + build: + context: . + target: caddy + container_name: caddy + restart: unless-stopped + env_file: + - .env + environment: + - CLOUDFLARE_EMAIL=${CF_EMAIL} + - CLOUDFLARE_API_TOKEN=${CF_AUTH_TOKEN} + - ACME_AGREE=true + - CROWDSEC_API_KEY=${CROWDSEC_API_KEY} + ports: + - 80:80 + - 443:443 + - "443:443/udp" + cap_add: + - NET_ADMIN + volumes: + - ./caddy:/etc/caddy + - caddy_data:/data + - caddy_config:/config + - caddy_logs:/var/log/caddy + networks: + - proxy + security_opt: + - no-new-privileges:true + + crowdsec: + image: docker.io/crowdsecurity/crowdsec:latest + container_name: crowdsec + restart: unless-stopped + environment: + - GID=1000 + - COLLECTIONS=crowdsecurity/linux crowdsecurity/caddy crowdsecurity/http-cve crowdsecurity/whitelist-good-actors + - BOUNCER_KEY_CADDY=${CROWDSEC_API_KEY} + volumes: + - crowdsec_db:/var/lib/crowdsec/data/ + - ./crowdsec/acquis.yaml:/etc/crowdsec/acquis.yaml + - caddy_logs:/var/log/caddy:ro + networks: + - proxy + security_opt: + - no-new-privileges:true + depends_on: + - caddy + +volumes: + caddy_data: {} + caddy_config: {} + caddy_logs: {} + crowdsec_db: {} + +networks: + proxy: + external: true + diff --git a/crowdsec/acquis.yaml b/crowdsec/acquis.yaml new file mode 100644 index 0000000..46acbcc --- /dev/null +++ b/crowdsec/acquis.yaml @@ -0,0 +1,5 @@ +filenames: + - /var/log/caddy/*.log +labels: + type: caddy + diff --git a/example.env b/example.env new file mode 100644 index 0000000..7adbd9d --- /dev/null +++ b/example.env @@ -0,0 +1,4 @@ +ACME_EMAIL="acme@example.com" +CF_AUTH_TOKEN="secret-token" +CF_EMAIL="cloudflare@example.com" +CROWDSEC_API_KEY="CHANGEME"