-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM caddy:2.7-builder AS builder | ||
|
||
COPY ./fail2ban.go /src/caddy-fail2ban/ | ||
COPY ./go.sum /src/caddy-fail2ban/ | ||
COPY ./go.mod /src/caddy-fail2ban/ | ||
RUN xcaddy build \ | ||
--with github.com/Javex/caddy-fail2ban=/src/caddy-fail2ban | ||
|
||
FROM caddy:2.7 | ||
|
||
COPY --from=builder /usr/bin/caddy /usr/bin/caddy | ||
|
||
RUN apk update && apk add fail2ban curl bash | ||
RUN rm /etc/fail2ban/jail.d/alpine-ssh.conf | ||
COPY ./fail2ban/caddy-banfile.conf /etc/fail2ban/action.d/caddy-banfile.conf | ||
COPY ./test/caddy-test.local /etc/fail2ban/jail.d/caddy-test.local | ||
COPY ./test/caddy-fail2ban-test.sh /usr/local/bin/ | ||
RUN chmod u+x /usr/local/bin/caddy-fail2ban-test.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
log { | ||
level DEBUG | ||
} | ||
} | ||
|
||
127.0.0.1:80 { | ||
@banned { | ||
fail2ban /srv/banned-ips | ||
} | ||
handle @banned { | ||
abort | ||
} | ||
respond "ok" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
fail2ban-server | ||
sleep 1 | ||
|
||
output=$(curl http://127.0.0.1) | ||
if [ "$output" != "ok" ]; then | ||
echo "Expected 'ok' output, got '${output}'" | ||
exit 1 | ||
fi | ||
|
||
fail2ban-client set caddy_test banip 127.0.0.1 | ||
|
||
set +e | ||
curl http://127.0.0.1 | ||
curl_exit_code=$? | ||
set -e | ||
if [ $curl_exit_code -eq 0 ]; then | ||
echo "Expected curl to exit with non-zero exit code, but it was successful"; | ||
exit 1 | ||
fi | ||
|
||
echo "Success!" | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[caddy_test] | ||
backend = auto | ||
enabled = true | ||
port = 80,443 | ||
protocol = tcp | ||
filter = bitwarden | ||
maxretry = 3 | ||
bantime = 86400 | ||
findtime = 43200 | ||
action = caddy-banfile[banfile_path="/srv/banned-ips"] |