Skip to content

Commit 8edd703

Browse files
authored
Merge pull request #254 from quietsy/swag-maxmind
2 parents d1dc6e5 + eb65a89 commit 8edd703

File tree

8 files changed

+109
-69
lines changed

8 files changed

+109
-69
lines changed

.github/workflows/BuildImage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Build Image
33
on: [push, pull_request, workflow_dispatch]
44

55
env:
6-
ENDPOINT: "linuxserver/mods" #don't modify
7-
BASEIMAGE: "replace_baseimage" #replace
8-
MODNAME: "replace_modname" #replace
6+
ENDPOINT: "linuxserver/mods"
7+
BASEIMAGE: "swag"
8+
MODNAME: "maxmind"
99

1010
jobs:
1111
build:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM scratch
22

3-
LABEL maintainer="username"
3+
LABEL maintainer="quietsy"
44

55
# copy local files
66
COPY root/ /

Dockerfile.complex

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

README.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,49 @@
1-
# Rsync - Docker mod for openssh-server
1+
# Maxmind Docker mod for Nginx based images
22

3-
This mod adds rsync to openssh-server, to be installed/updated during container start.
3+
This mod adds the maxmind database to nginx using the license key defined in the environment variable.
44

5-
In openssh-server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:openssh-server-rsync`
5+
This mod downloads the `GeoLite2-City.mmdb` database under `/config/geoip2db`, the database is updated weekly.
66

7-
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:openssh-server-rsync|linuxserver/mods:openssh-server-mod2`
7+
**This mod should not be enabled together with the swag-dbip mod.**
88

9-
# Mod creation instructions
9+
Follow these steps to enable the maxmind mod:
1010

11-
* Fork the repo, create a new branch based on the branch `template`.
12-
* Edit the `Dockerfile` for the mod. `Dockerfile.complex` is only an example and included for reference; it should be deleted when done.
13-
* Inspect the `root` folder contents. Edit, add and remove as necessary.
14-
* Edit this readme with pertinent info, delete these instructions.
15-
* Finally edit the `.github/workflows/BuildImage.yml`. Customize the build branch, and the vars for `BASEIMAGE` and `MODNAME`.
16-
* Ask the team to create a new branch named `<baseimagename>-<modname>`. Baseimage should be the name of the image the mod will be applied to. The new branch will be based on the `template` branch.
17-
* Submit PR against the branch created by the team.
11+
1. Acquire a maxmind license here: https://www.maxmind.com/en/geolite2/signup
12+
2. In the container's docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:swag-maxmind`
13+
14+
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:swag-maxmind|linuxserver/mods:swag-mod2`
15+
3. In the container's docker arguments, set an environment variable `MAXMINDDB_LICENSE_KEY=<license-key>` with your license key.
16+
4. Add the following line to `/config/nginx/nginx.conf` under the `http` section:
17+
18+
```nginx
19+
include /config/nginx/maxmind.conf;
20+
```
21+
5. Edit `/config/nginx/maxmind.conf` and add countries to the blocklist / whitelist according to the comments, for example:
22+
23+
```nginx
24+
map $geoip2_data_country_iso_code $geo-whitelist {
25+
default no;
26+
UK yes;
27+
}
28+
29+
map $geoip2_data_country_iso_code $geo-blacklist {
30+
default yes;
31+
US no;
32+
}
33+
```
34+
6. Use the definitions in the following way:
35+
```nginx
36+
server {
37+
listen 443 ssl;
38+
listen [::]:443 ssl;
39+
40+
server_name some-app.*;
41+
include /config/nginx/ssl.conf;
42+
client_max_body_size 0;
43+
44+
if ($lan-ip = yes) { set $geo-whitelist yes; }
45+
if ($geo-whitelist = no) { return 404; }
46+
47+
location / {
48+
```
49+
7. Recreate the container to apply the changes.

root/defaults/maxmind.conf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
geoip2 /config/geoip2db/GeoLite2-City.mmdb {
2+
auto_reload 1w;
3+
$geoip2_data_city_name city names en;
4+
$geoip2_data_postal_code postal code;
5+
$geoip2_data_latitude location latitude;
6+
$geoip2_data_longitude location longitude;
7+
$geoip2_data_state_name subdivisions 0 names en;
8+
$geoip2_data_state_code subdivisions 0 iso_code;
9+
$geoip2_data_continent_code continent code;
10+
$geoip2_data_country_iso_code country iso_code;
11+
}
12+
13+
# Country Codes: https://en.wikipedia.org/wiki/ISO_3166-2
14+
15+
map $geoip2_data_country_iso_code $geo-whitelist {
16+
default yes;
17+
# Example for whitelisting a country, comment out 'default yes;' above and uncomment 'default no;' and the whitelisted country below
18+
# default no;
19+
# UK yes;
20+
}
21+
22+
map $geoip2_data_country_iso_code $geo-blacklist {
23+
default yes;
24+
# Example for blacklisting a country, uncomment the blacklisted country below
25+
# UK no;
26+
}
27+
28+
geo $lan-ip {
29+
default no;
30+
10.0.0.0/8 yes;
31+
172.16.0.0/12 yes;
32+
192.168.0.0/16 yes;
33+
127.0.0.1 yes;
34+
}

root/etc/cont-init.d/98-maxmind

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
echo "Applying the maxmind mod..."
4+
5+
# create GeoIP2 folder symlink
6+
[[ -d /var/lib/libmaxminddb ]] && [[ ! -L /var/lib/libmaxminddb ]] && \
7+
rm -rf /var/lib/libmaxminddb
8+
[[ ! -d /var/lib/libmaxminddb ]] && \
9+
ln -s /config/geoip2db /var/lib/libmaxminddb
10+
# check GeoIP2 database
11+
if [ -n "$MAXMINDDB_LICENSE_KEY" ]; then
12+
sed -i "s|.*MAXMINDDB_LICENSE_KEY.*|MAXMINDDB_LICENSE_KEY=\"${MAXMINDDB_LICENSE_KEY}\"|g" /etc/libmaxminddb.cron.conf
13+
if [ ! -f /var/lib/libmaxminddb/GeoLite2-City.mmdb ]; then
14+
echo "Downloading GeoIP2 City database."
15+
/etc/periodic/weekly/libmaxminddb
16+
fi
17+
elif [ -f /var/lib/libmaxminddb/GeoLite2-City.mmdb ]; then
18+
echo -e "Currently using the user provided GeoLite2-City.mmdb.\nIf you want to enable weekly auto-updates of the database, retrieve a free license key from MaxMind,\nand add a new env variable \"MAXMINDDB_LICENSE_KEY\", set to your license key."
19+
else
20+
echo -e "Starting 2019/12/30, GeoIP2 databases require personal license key to download. Please retrieve a free license key from MaxMind,\nand add a new env variable \"MAXMINDDB_LICENSE_KEY\", set to your license key."
21+
fi
22+
23+
if [ ! -f /config/nginx/maxmind.conf ]; then
24+
cp /defaults/maxmind.conf /config/nginx/maxmind.conf
25+
fi
26+
27+
echo "Applied the maxmind mod"

root/etc/cont-init.d/98-vpn-config

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

root/etc/services.d/sshvpn/run

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

0 commit comments

Comments
 (0)