Merge pull request #265 from quietsy/swag-dbip

This commit is contained in:
Roxedus
2021-12-04 16:50:17 +00:00
committed by GitHub
9 changed files with 98 additions and 69 deletions
+3 -3
View File
@@ -3,9 +3,9 @@ name: Build Image
on: [push, pull_request, workflow_dispatch]
env:
ENDPOINT: "linuxserver/mods" #don't modify
BASEIMAGE: "replace_baseimage" #replace
MODNAME: "replace_modname" #replace
ENDPOINT: "linuxserver/mods"
BASEIMAGE: "swag"
MODNAME: "dbip"
jobs:
build:
+1 -1
View File
@@ -1,6 +1,6 @@
FROM scratch
LABEL maintainer="username"
LABEL maintainer="quietsy"
# copy local files
COPY root/ /
-23
View File
@@ -1,23 +0,0 @@
## Buildstage ##
FROM ghcr.io/linuxserver/baseimage-alpine:3.12 as buildstage
RUN \
echo "**** install packages ****" && \
apk add --no-cache \
curl && \
echo "**** grab rclone ****" && \
mkdir -p /root-layer && \
curl -o \
/root-layer/rclone.deb -L \
"https://downloads.rclone.org/v1.47.0/rclone-v1.47.0-linux-amd64.deb"
# copy local files
COPY root/ /root-layer/
## Single layer deployed image ##
FROM scratch
LABEL maintainer="username"
# Add files from buildstage
COPY --from=buildstage /root-layer/ /
+40 -12
View File
@@ -1,17 +1,45 @@
# Rsync - Docker mod for openssh-server
# DBIP Docker mod for Nginx based images
This mod adds rsync to openssh-server, to be installed/updated during container start.
This mod downloads the `dbip-country-lite.mmdb` database under `/config/geoip2db`, the database is updated weekly.
In openssh-server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:openssh-server-rsync`
**This mod should not be enabled together with the swag-maxmind mod.**
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`
Follow these steps to enable the dbip mod:
# Mod creation instructions
1. In the container's docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:swag-dbip`
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:swag-dbip|linuxserver/mods:swag-mod2`
2. Add the following line to `/config/nginx/nginx.conf` under the `http` section:
```nginx
include /config/nginx/dbip.conf;
```
3. Edit `/config/nginx/dbip.conf` and add countries to the blocklist / whitelist according to the comments, for example:
```nginx
map $geoip2_data_country_iso_code $geo-whitelist {
default no;
UK yes;
}
* Fork the repo, create a new branch based on the branch `template`.
* Edit the `Dockerfile` for the mod. `Dockerfile.complex` is only an example and included for reference; it should be deleted when done.
* Inspect the `root` folder contents. Edit, add and remove as necessary.
* Edit this readme with pertinent info, delete these instructions.
* Finally edit the `.github/workflows/BuildImage.yml`. Customize the build branch, and the vars for `BASEIMAGE` and `MODNAME`.
* 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.
* Submit PR against the branch created by the team.
map $geoip2_data_country_iso_code $geo-blacklist {
default yes;
US no;
}
```
4. Use the definitions in the following way:
```nginx
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name some-app.*;
include /config/nginx/ssl.conf;
client_max_body_size 0;
if ($lan-ip = yes) { set $geo-whitelist yes; }
if ($geo-whitelist = no) { return 404; }
location / {
```
5. Recreate the container to apply the changes.
+28
View File
@@ -0,0 +1,28 @@
geoip2 /config/geoip2db/dbip-country-lite.mmdb {
auto_reload 1w;
$geoip2_data_continent_code continent code;
$geoip2_data_country_iso_code country iso_code;
}
# Country Codes: https://en.wikipedia.org/wiki/ISO_3166-2
map $geoip2_data_country_iso_code $geo-whitelist {
default yes;
# Example for whitelisting a country, comment out 'default yes;' above and uncomment 'default no;' and the whitelisted country below
# default no;
# UK yes;
}
map $geoip2_data_country_iso_code $geo-blacklist {
default yes;
# Example for blacklisting a country, uncomment the blacklisted country below
# UK no;
}
geo $lan-ip {
default no;
10.0.0.0/8 yes;
172.16.0.0/12 yes;
192.168.0.0/16 yes;
127.0.0.1 yes;
}
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/with-contenv bash
echo "Applying the dbip mod..."
chmod +x /etc/periodic/weekly/dbip
# check GeoIP2 database
if [ ! -f /config/geoip2db/dbip-country-lite.mmdb ]; then
echo "Downloading GeoIP2 City database."
/etc/periodic/weekly/dbip
fi
if [ ! -f /config/nginx/dbip.conf ]; then
cp /defaults/dbip.conf /config/nginx/dbip.conf
fi
echo "Applied the dbip mod"
-27
View File
@@ -1,27 +0,0 @@
#!/usr/bin/with-contenv bash
# Determine if setup is needed
if [ ! -f /usr/local/lib/python***/dist-packages/sshuttle ] && \
[ -f /usr/bin/apt ]; then
## Ubuntu
apt-get update
apt-get install --no-install-recommends -y \
iptables \
openssh-client \
python3 \
python3-pip
pip3 install sshuttle
fi
if [ ! -f /usr/lib/python***/site-packages/sshuttle ] && \
[ -f /sbin/apk ]; then
# Alpine
apk add --no-cache \
iptables \
openssh \
py3-pip \
python3
pip3 install sshuttle
fi
chown -R root:root /root
chmod -R 600 /root/.ssh
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
DATE=$(date '+%Y-%m')
FILE="https://download.db-ip.com/free/dbip-country-lite-${DATE}.mmdb.gz"
wget -O /tmp/dbip-country-lite.mmdb.gz $FILE
gzip -df /tmp/dbip-country-lite.mmdb.gz
mv -f /tmp/dbip-country-lite.mmdb /config/geoip2db/dbip-country-lite.mmdb
exit 0
-3
View File
@@ -1,3 +0,0 @@
#!/usr/bin/with-contenv bash
sshuttle --dns --remote root@${HOST}:${PORT} 0/0 -x 172.17.0.0/16