Skip to content
This repository was archived by the owner on Aug 8, 2022. It is now read-only.

Commit 57ba067

Browse files
authored
Merge pull request #10 from linuxserver-labs/dev-conf
2 parents 0015b7e + a6c5208 commit 57ba067

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+706
-209
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Check for base image updates
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: "52 0 * * 0"
6+
7+
jobs:
8+
call-workflow:
9+
uses: linuxserver-labs/docker-actions/.github/workflows/check-baseimage-update.yml@v5
10+
with:
11+
repo_owner: ${{ github.repository_owner }}
12+
baseimage: "alpine"
13+
basebranch: "master"
14+
app_name: "fail2Ban"
15+
secrets:
16+
repo_release_token: ${{ secrets.repo_release_token }}

.github/workflows/call-build-image.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ name: Build Image On Release
33
on:
44
release:
55
types: [published]
6+
pull_request:
67

78
jobs:
89
call-workflow:
9-
uses: linuxserver-labs/docker-actions/.github/workflows/build-image.yml@v2
10+
uses: linuxserver-labs/docker-actions/.github/workflows/build-image.yml@v5
1011
with:
1112
repo_owner: ${{ github.repository_owner }}
12-
app_name: "fail2ban"
13+
app_name: fail2ban
14+
release_type: alpine
15+
release_name: fail2Ban
16+
secrets:
17+
scarf_token: ${{ secrets.SCARF_TOKEN }}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files.associations": {
3+
"**/fail2ban/**/**.conf": "ini",
4+
"**/fail2ban/**/**.local": "ini"
5+
}
6+
}

Dockerfile

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,12 @@ LABEL maintainer="nomandera"
1010
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2
1111

1212
RUN \
13-
echo "**** install runtime packages ****" && \
14-
apk add --no-cache --upgrade \
13+
echo "**** install runtime packages ****" && \
14+
apk add --no-cache --upgrade \
1515
curl \
1616
fail2ban \
17-
fail2ban-doc && \
18-
echo "**** remove unnecessary fail2ban filters ****" && \
19-
rm \
20-
/etc/fail2ban/jail.d/alpine-ssh.conf && \
21-
echo "**** copy fail2ban default action and filter to /default ****" && \
22-
mkdir -p /defaults/fail2ban && \
23-
mv /etc/fail2ban/action.d /defaults/fail2ban/ && \
24-
mv /etc/fail2ban/filter.d /defaults/fail2ban/
25-
17+
fail2ban-doc
18+
2619

2720
# add local files
2821
COPY root/ /

LICENSE

100755100644
File mode changed.

readme-vars.yml

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
---
2-
32
# project information
43
project_name: fail2ban
54
project_url: "https://github.com/fail2ban/fail2ban"
65
project_logo: "https://raw.githubusercontent.com/linuxserver/docker-templates/master/linuxserver.io/img/fail2ban-banner.png"
76
project_blurb: "[{{ project_name|capitalize }}]({{ project_url }}) Fail2Ban can do many things but at its core it scans log files and bans IP addresses with too many failed login attempts by adding firewall rules to reject new connections from those IP addresses, for a configurable amount of time."
87

9-
108
project_lsio_github_repo_url: "https://github.com/linuxserver/docker-{{ project_name }}"
119
project_blurb_optional_extras_enabled: false
1210

1311
# supported architectures
1412
available_architectures:
15-
- { arch: "{{ arch_x86_64 }}", tag: "amd64-latest"}
16-
- { arch: "{{ arch_arm64 }}", tag: "arm64v8-latest"}
17-
- { arch: "{{ arch_armhf }}", tag: "arm32v7-latest"}
13+
- { arch: "{{ arch_x86_64 }}", tag: "amd64-latest" }
14+
- { arch: "{{ arch_arm64 }}", tag: "arm64v8-latest" }
15+
- { arch: "{{ arch_armhf }}", tag: "arm32v7-latest" }
1816

1917
# development version
2018
development_versions: true
@@ -28,12 +26,28 @@ param_container_name: "{{ project_name }}"
2826
param_usage_include_net: false
2927
param_usage_include_env: true
3028
param_env_vars:
31-
- { env_var: "TZ", env_value: "Europe/London", desc: "Specify a timezone to use EG Europe/London." }
29+
- {
30+
env_var: "TZ",
31+
env_value: "Europe/London",
32+
desc: "Specify a timezone to use EG Europe/London.",
33+
}
3234
param_usage_include_vols: true
3335
param_volumes:
34-
- { vol_path: "/config", vol_host_path: "<path to data>", desc: "Where Fail2ban should store its config file." }
35-
- { vol_path: "/remotelog/applicationX/applicationX.log", vol_host_path: "<path to applicationX.log>", desc: "Path to a specific named log file." }
36-
- { vol_path: "/remotelog/applicationY/", vol_host_path: "<path to applicationY log directory>", desc: "Path to an application log directory with multiple logs." }
36+
- {
37+
vol_path: "/config",
38+
vol_host_path: "<path to data>",
39+
desc: "Where Fail2ban should store its config file.",
40+
}
41+
- {
42+
vol_path: "/remotelog/applicationX/applicationX.log",
43+
vol_host_path: "<path to applicationX.log>",
44+
desc: "Path to a specific named log file.",
45+
}
46+
- {
47+
vol_path: "/remotelog/applicationY/",
48+
vol_host_path: "<path to applicationY log directory>",
49+
desc: "Path to an application log directory with multiple logs.",
50+
}
3751
param_usage_include_ports: false
3852
param_ports:
3953
param_device_map: false
@@ -51,80 +65,78 @@ optional_block_1: false
5165
# application setup block
5266
app_setup_block_enabled: true
5367
app_setup_block: |
54-
This docker specific implementation of fail2ban can read an arbitrary number of log files from other containers, monitor them for abuse as a single large entity
55-
and apply IP bans that will protect ALL docker containers on the host but not the host itself.
56-
68+
This docker specific implementation of fail2ban can read an arbitrary number of log files from other containers, monitor them for abuse as a single large entity and apply IP bans that will protect ALL docker containers on the host but not the host itself.
69+
5770
To do this it takes advantage of the DOCKER-USER iptables chain that exists in all modern docker installs.
58-
71+
5972
Note: Internal Docker iptables rules are added to the DOCKER chain which is separate to the DOCKER-USER chain and should never be manipulated directly by the user.
60-
73+
6174
Since DOCKER-USER rules are applied before any rules Docker itself creates fail2ban blocks automatically apply to all local native and custom docker bridge networks without risking breaking docker itself.
62-
63-
IMPORTANT: Both the DOCKER and DOCKER-USER chains are evaluated BEFORE the FORWARD chain. This is often overlooked by users who expected existing firewall restrictions to
64-
apply to docker services which they do not resulting in the false assumption that services are protected and private when they are not.
65-
75+
76+
> IMPORTANT: Both the DOCKER and DOCKER-USER chains are evaluated BEFORE the FORWARD chain. This is often overlooked by users who expected existing firewall restrictions to apply to docker services which they do not resulting in the false assumption that services are protected and private when they are not.
77+
6678
If none of this make sense to you don't worry you do not need to understand firewalling to make use of this container.
67-
79+
6880
Fail2ban configuration can seem daunting at first but most of the complexity can be ignored for most users.
69-
81+
7082
In simple terms Fail2ban has three steps with associated configuration files:
71-
72-
filters. Think of these as a list of patterns used to match abuse in your log files.
73-
jails. These are used to tell Fail2ban which log files match which filters and other basics such as how how many failed logins are allowed etc
74-
actions. As the name suggests these define what actions Fail2ban takes when a jail is triggered. Typical users will never alter these.
75-
83+
84+
`filters` - Think of these as a list of patterns used to match abuse in your log files.
85+
`jails` - These are used to tell Fail2ban which log files match which filters and other basics such as how how many failed logins are allowed etc
86+
`actions` - As the name suggests these define what actions Fail2ban takes when a jail is triggered. Typical users will never alter these.
87+
7688
Fail2ban continues this one step further with a system that can merge multiple configuration files into one. This is a fairly unusual methodology which can seem confusing at first but is a critical and powerful skill to learn.
77-
89+
7890
This is best explained using an example:
79-
91+
8092
If we ignore actions since almost all users will be happy with the "block IP action" we can concentrate on filters and jails.
81-
93+
8294
Each jail is defined in a .conf file located in /config/fail2ban/jail.d/ so for example nginx-http-auth.conf with contents like:
83-
95+
96+
```ini
8497
[nginx-http-auth]
8598
8699
enabled = false
87100
filter = nginx-http-auth
88101
port = http,https
89102
logpath = /remotelog/nginx/error.log
90-
103+
```
104+
91105
This file is relatively simple to understand but it is important you do not edit it directly. If you wish to alter this file you have two options:
92-
106+
93107
1. Create a file called nginx-http-auth.local with just the changes you wish to make and the [] header. So for example if you wanted to enable this jail we
94108
could create a file called nginx-http-auth.local beside the existing nginx-http-auth.conf with contents of
95-
109+
110+
```ini
96111
[nginx-http-auth]
97112
98113
enabled = true
99-
114+
```
115+
100116
At load tile Fail2ban will read every .conf and .local and merge them internally resulting in this example of turning nginx-http-auth on.
101-
117+
102118
2. Fail2ban also has a jail.conf file that contains global settings but it can also accept jail specific changes.
103119
As previously you should not edit a conf file so in this case we would create jail.local and enter the same two lines we changed in the previous nginx-http-auth.local example/
104-
120+
105121
Which method is preferable? The choice is yours and both have merits but jail.local is probably easier at first. Should you wish to change later the effort to do so it relatively minimal.
106-
107-
At this point you may be asking yourself why all this complication? Once you get used to the setup it soon becomes second nature and it allows lsio and the fail2ban project to push new
108-
config files and changes such as security fixes without the risk of altering existing user changes.
109-
122+
123+
At this point you may be asking yourself why all this complication? Once you get used to the setup it soon becomes second nature and it allows lsio and the fail2ban project to push new config files and changes such as security fixes without the risk of altering existing user changes.
124+
110125
So how do you actually turn on a jail? It is actually relatively simple.
111-
126+
112127
Step 1: In docker volume mount the log file or folder of log files from the container to be protected into this one.
113128
Step 2: Find the filter that matches the application log type. Most are included by default and more are being added all the time.
114129
Step 3: Activate the jail using either the global jail.local or jail-specific.local as described above. Normally you only need to change two variables `enabled = true` and the `logpath = /match/your/volume/mount/from/step/1.log`
115-
130+
116131
For neatness we would recommend logs are mount read only using the convention of `/remotelog/containername/nativefilename.log`. So for example our Airsonic container would be:
117-
118-
-v <path to containers>/airsonic/airsonic.log:/remotelog/airsonic/airsonic.log:ro
119132
120-
Once these three simple steps are taken restart fail2ban and protection should be in place. You can repeat this process to protect any number of containers and given how noisy the internet is in no time you will see
121-
bad actors being banned.
122-
133+
`-v <path to containers>/airsonic/airsonic.log:/remotelog/airsonic/airsonic.log:ro`
134+
135+
Once these three simple steps are taken restart fail2ban and protection should be in place. You can repeat this process to protect any number of containers and given how noisy the internet is in no time you will see bad actors being banned.
136+
123137
Note: As a safety measure we ship this container with a default ignore list of all IANA private addresses to ensure you do not ban yourself or your LAN users by default. You can alter this using jail.local if you wish.
124-
125138
126139
# changelog
127140

128141
changelogs:
129142
- { date: "xx.xx.20:", desc: "Initial Release." }
130-
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[Definition]
2+
3+
# Option: actionstart
4+
# Notes.: command executed on demand at the first ban (or at the start of Fail2Ban if actionstart_on_demand is set to false).
5+
# Values: CMD
6+
#
7+
actionstart = curl -X POST -d '{"tag": "f2b", "type": "info", "body": "The guard in <name> is waking up."}' \
8+
-H "Content-Type: application/json" \
9+
<url>
10+
11+
# Option: actionstop
12+
# Notes.: command executed at the stop of jail (or at the end of Fail2Ban)
13+
# Values: CMD
14+
#
15+
actionstop =
16+
17+
# Option: actioncheck
18+
# Notes.: command executed once before each actionban command
19+
# Values: CMD
20+
#
21+
actioncheck =
22+
23+
# Option: actionban
24+
# Notes.: command executed when banning an IP. Take care that the
25+
# command is executed with Fail2Ban user rights.
26+
# Tags: <ip> IP address
27+
# <failures> number of failures
28+
# <time> unix timestamp of the ban time
29+
# Values: CMD
30+
#
31+
32+
actionban = curl -X POST -d '{"tag": "f2b", "type": "warning", "body": "#I smell blood in <name>.\n<ip> has been banned."}' \
33+
-H "Content-Type: application/json" \
34+
<url>
35+
36+
# Option: actionunban
37+
# Notes.: command executed when unbanning an IP. Take care that the
38+
# command is executed with Fail2Ban user rights.
39+
# Tags: <ip> IP address
40+
# <failures> number of failures
41+
# <time> unix timestamp of the ban time
42+
# Values: CMD
43+
#
44+
45+
actionunban = curl -X POST -d '{"tag": "f2b", "type": "success", "body": "#Someone have seen the light in <name>.\n<ip> has been unbanned."}' \
46+
-H "Content-Type: application/json" \
47+
<url>
48+
49+
[Init]
50+
51+
url = http://apprise:8000/notify/default
File renamed without changes.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Fail2Ban main configuration file
2+
#
3+
# Comments: use '#' for comment lines and ';' (following a space) for inline comments
4+
#
5+
# Changes: in most of the cases you should not modify this
6+
# file, but provide customizations in fail2ban.local file, e.g.:
7+
#
8+
# [DEFAULT]
9+
# loglevel = DEBUG
10+
#
11+
12+
[DEFAULT]
13+
14+
# Option: loglevel
15+
# Notes.: Set the log level output.
16+
# CRITICAL
17+
# ERROR
18+
# WARNING
19+
# NOTICE
20+
# INFO
21+
# DEBUG
22+
# Values: [ LEVEL ] Default: INFO
23+
#
24+
loglevel = INFO
25+
26+
# Option: logtarget
27+
# Notes.: Set the log target. This could be a file, SYSLOG, STDERR or STDOUT.
28+
# Only one log target can be specified.
29+
# If you change logtarget from the default value and you are
30+
# using logrotate -- also adjust or disable rotation in the
31+
# corresponding configuration file
32+
# (e.g. /etc/logrotate.d/fail2ban on Debian systems)
33+
# Values: [ STDOUT | STDERR | SYSLOG | SYSOUT | FILE ] Default: STDERR
34+
#
35+
logtarget = /config/log/fail2ban/fail2ban.log
36+
37+
# Option: syslogsocket
38+
# Notes: Set the syslog socket file. Only used when logtarget is SYSLOG
39+
# auto uses platform.system() to determine predefined paths
40+
# Values: [ auto | FILE ] Default: auto
41+
syslogsocket = auto
42+
43+
# Option: socket
44+
# Notes.: Set the socket file. This is used to communicate with the daemon. Do
45+
# not remove this file when Fail2ban runs. It will not be possible to
46+
# communicate with the server afterwards.
47+
# Values: [ FILE ] Default: /var/run/fail2ban/fail2ban.sock
48+
#
49+
socket = /var/run/fail2ban/fail2ban.sock
50+
51+
# Option: pidfile
52+
# Notes.: Set the PID file. This is used to store the process ID of the
53+
# fail2ban server.
54+
# Values: [ FILE ] Default: /var/run/fail2ban/fail2ban.pid
55+
#
56+
pidfile = /var/run/fail2ban/fail2ban.pid
57+
58+
# Options: dbfile
59+
# Notes.: Set the file for the fail2ban persistent data to be stored.
60+
# A value of ":memory:" means database is only stored in memory
61+
# and data is lost when fail2ban is stopped.
62+
# A value of "None" disables the database.
63+
# Values: [ None :memory: FILE ] Default: /var/lib/fail2ban/fail2ban.sqlite3
64+
dbfile = /config/fail2ban/fail2ban.sqlite3
65+
66+
# Options: dbpurgeage
67+
# Notes.: Sets age at which bans should be purged from the database
68+
# Values: [ SECONDS ] Default: 86400 (24hours)
69+
dbpurgeage = 1d
70+
71+
# Options: dbmaxmatches
72+
# Notes.: Number of matches stored in database per ticket (resolvable via
73+
# tags <ipmatches>/<ipjailmatches> in actions)
74+
# Values: [ INT ] Default: 10
75+
dbmaxmatches = 10
76+
77+
[Definition]
78+
79+
80+
[Thread]
81+
82+
# Options: stacksize
83+
# Notes.: Specifies the stack size (in KiB) to be used for subsequently created threads,
84+
# and must be 0 or a positive integer value of at least 32.
85+
# Values: [ SIZE ] Default: 0 (use platform or configured default)
86+
#stacksize = 0

root/defaults/fail2ban/fail2ban.local

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)