Skip to content

Commit 95840d9

Browse files
committed
Add containerized geoipupdate to Docker setup
- Add geoipupdate service to docker-compose.yml using ghcr.io/maxmind/geoipupdate - Credentials supplied via .env file (MAXMIND_ACCOUNT_ID, MAXMIND_LICENSE_KEY) - GeoIP databases stored in named volume 'geoip-data', mounted read-only by monitor - Removed GeoIP mount from web service (not needed) - GEOIPUPDATE_FREQUENCY=168 (weekly, matching MaxMind's Tuesday release schedule) - Add .env.example for credential setup - Update INSTALL.md: MaxMind credentials as prerequisite, Docker section uses containerized geoipupdate, systemd sections retain host geoipupdate + cron
1 parent f99d37c commit 95840d9

3 files changed

Lines changed: 109 additions & 54 deletions

File tree

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# MaxMind GeoIP credentials
2+
# Get a free account at https://www.maxmind.com/en/geolite2/signup
3+
# Then generate a license key in your account dashboard.
4+
MAXMIND_ACCOUNT_ID=your_account_id
5+
MAXMIND_LICENSE_KEY=your_license_key

INSTALL.md

Lines changed: 90 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,13 @@ ssh -p 2222 user@your-server
3232

3333
You must open up your firewall (if present) to expose ports 22, 80 or 443, and potentially your real SSH port. This is specific to your network configuration, so the exact steps are not presented here.
3434

35-
### GeoIP Databases
35+
### MaxMind Account (GeoIP)
3636

3737
Knock-Knock uses MaxMind GeoLite2 databases for IP geolocation. You need a free MaxMind account.
3838

39-
1. Install geoipupdate:
40-
41-
**Debian/Ubuntu:**
42-
```bash
43-
apt install -y geoipupdate
44-
```
45-
46-
**RHEL/CentOS/Fedora:**
47-
```bash
48-
dnf install -y geoipupdate
49-
```
50-
51-
2. Create a free account at https://www.maxmind.com/en/geolite2/signup
52-
3. Generate a license key in your account dashboard. Either download the config file and save it as `/etc/GeoIP.conf`, or edit the existing `/etc/GeoIP.conf` (created by the install) and add your `AccountID` and `LicenseKey`.
53-
54-
Then download the databases:
55-
```bash
56-
geoipupdate
57-
58-
# Ensure databases are at /usr/share/GeoIP (some distros use /var/lib/GeoIP)
59-
[ ! -e /usr/share/GeoIP ] && ln -s /var/lib/GeoIP /usr/share/GeoIP
60-
61-
# Verify
62-
ls /usr/share/GeoIP/GeoLite2-*.mmdb
63-
```
64-
65-
Set up weekly auto-updates:
66-
```bash
67-
crontab -e
68-
# Add line:
69-
0 3 * * 3 /usr/bin/geoipupdate
70-
```
39+
1. Register at https://www.maxmind.com/en/geolite2/signup
40+
2. In your account dashboard, generate a license key
41+
3. Note your **Account ID** and **License Key** — you'll need them below
7142

7243
### SSH Host Key (Systemd Only)
7344

@@ -91,40 +62,43 @@ Complete the [Prerequisites](#prerequisites) above first (skip the SSH Host Key
9162
curl -fsSL https://get.docker.com | sh
9263
```
9364

94-
### Using the Pre-built Image (Recommended)
95-
96-
A multi-arch image (amd64 + arm64) is published to GitHub Container Registry. You only need the `docker-compose.yml` file:
65+
### Clone the Repository
9766

9867
```bash
9968
cd /root
10069
git clone https://github.com/djkurlander/knock-knock.git
10170
cd knock-knock
102-
103-
# Pull and start (uses pre-built image from ghcr.io)
104-
docker compose up -d
10571
```
10672

107-
### Building Locally
108-
109-
If you prefer to build from source:
73+
### Configure MaxMind Credentials
11074

11175
```bash
112-
cd /root
113-
git clone https://github.com/djkurlander/knock-knock.git
114-
cd knock-knock
76+
cp .env.example .env
77+
nano .env # Fill in your Account ID and License Key
78+
```
79+
80+
### Start
11581

116-
# Build and start from Dockerfile
117-
docker compose up -d --build
82+
```bash
83+
# Pull and start (uses pre-built image from ghcr.io)
84+
docker compose up -d
11885
```
11986

87+
The `geoipupdate` container downloads the GeoIP databases on first start and refreshes them weekly. The monitor waits until the databases are ready before processing knocks — you'll see `⏳ Waiting for GeoIP databases...` in the logs until the download completes.
88+
12089
### Verify
12190

12291
```bash
123-
docker compose logs honeypot-monitor # Should show "Monitor Active"
124-
docker compose logs web # Should show uvicorn startup
92+
docker compose logs -f honeypot-monitor
93+
# Should show:
94+
# ⏳ Waiting for GeoIP databases... (briefly, during first-time download)
95+
# ✅ GeoIP databases loaded
96+
# 🚀 Maximalist Monitor Active...
97+
98+
docker compose logs web # Should show uvicorn startup
12599
```
126100

127-
That's it. Three containers (Redis, honeypot+monitor, web) start automatically and restart on failure.
101+
That's it. Four containers (Redis, geoipupdate, honeypot+monitor, web) start automatically and restart on failure.
128102

129103
**Useful commands:**
130104
```bash
@@ -142,6 +116,35 @@ See [Optional Configuration](#optional-configuration) for various site-specific
142116

143117
Complete the [Prerequisites](#prerequisites) above first.
144118

119+
### GeoIP Databases
120+
121+
```bash
122+
apt install -y geoipupdate
123+
```
124+
125+
Configure your MaxMind credentials in `/etc/GeoIP.conf`:
126+
```
127+
AccountID your_account_id
128+
LicenseKey your_license_key
129+
DatabaseDirectory /usr/share/GeoIP
130+
```
131+
132+
Download the databases and set up weekly auto-updates (MaxMind updates databases every Tuesday):
133+
```bash
134+
geoipupdate
135+
136+
# Ensure databases are at /usr/share/GeoIP (some distros use /var/lib/GeoIP)
137+
[ ! -e /usr/share/GeoIP ] && ln -s /var/lib/GeoIP /usr/share/GeoIP
138+
139+
# Verify
140+
ls /usr/share/GeoIP/GeoLite2-*.mmdb
141+
142+
# Weekly auto-update
143+
crontab -e
144+
# Add line:
145+
0 3 * * 3 /usr/bin/geoipupdate
146+
```
147+
145148
### System Dependencies
146149

147150
```bash
@@ -199,6 +202,32 @@ See [Optional Configuration](#optional-configuration) for various site-specific
199202

200203
Complete the [Prerequisites](#prerequisites) above first.
201204

205+
### GeoIP Databases
206+
207+
```bash
208+
dnf install -y geoipupdate
209+
```
210+
211+
Configure your MaxMind credentials in `/etc/GeoIP.conf`:
212+
```
213+
AccountID your_account_id
214+
LicenseKey your_license_key
215+
DatabaseDirectory /usr/share/GeoIP
216+
```
217+
218+
Download the databases and set up weekly auto-updates (MaxMind updates databases every Tuesday):
219+
```bash
220+
geoipupdate
221+
222+
# Verify
223+
ls /usr/share/GeoIP/GeoLite2-*.mmdb
224+
225+
# Weekly auto-update
226+
crontab -e
227+
# Add line:
228+
0 3 * * 3 /usr/bin/geoipupdate
229+
```
230+
202231
### System Dependencies
203232

204233
```bash
@@ -311,7 +340,16 @@ ss -tlnp | grep :22
311340
# Make sure real SSH is moved to another port first
312341
```
313342

314-
### GeoIP lookups failing
343+
### GeoIP lookups returning Unknown (Docker)
344+
```bash
345+
docker compose logs honeypot-monitor | grep -i geoip
346+
# Should show "✅ GeoIP databases loaded"
347+
# If stuck on "⏳ Waiting...", check geoipupdate logs:
348+
docker compose logs geoipupdate
349+
# Verify credentials in .env are correct
350+
```
351+
352+
### GeoIP lookups failing (Systemd)
315353
```bash
316354
ls -la /usr/share/GeoIP/GeoLite2-*.mmdb
317355
# If missing, ensure /etc/GeoIP.conf includes: DatabaseDirectory /usr/share/GeoIP
@@ -343,7 +381,7 @@ sqlite3 /root/knock-knock/data/knock_knock.db "SELECT * FROM knocks ORDER BY id
343381
# Reset all data (clear database and Redis)
344382
./restart.sh --reset-all
345383

346-
# Update GeoIP databases
384+
# Update GeoIP databases (systemd only — Docker handles this automatically)
347385
geoipupdate
348386

349387
# Rotate SSL certs (if using Let's Encrypt)

docker-compose.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ services:
55
- redis-data:/data
66
restart: unless-stopped
77

8+
geoipupdate:
9+
image: ghcr.io/maxmind/geoipupdate
10+
environment:
11+
- GEOIPUPDATE_ACCOUNT_ID=${MAXMIND_ACCOUNT_ID}
12+
- GEOIPUPDATE_LICENSE_KEY=${MAXMIND_LICENSE_KEY}
13+
- 'GEOIPUPDATE_EDITION_IDS=GeoLite2-ASN GeoLite2-City'
14+
- GEOIPUPDATE_FREQUENCY=168
15+
volumes:
16+
- geoip-data:/usr/share/GeoIP
17+
restart: unless-stopped
18+
819
honeypot-monitor:
920
image: ghcr.io/djkurlander/knock-knock:latest
1021
build: . # Used when running: docker compose up --build
@@ -15,9 +26,10 @@ services:
1526
- "22:22"
1627
volumes:
1728
- ./data:/app/data
18-
- /usr/share/GeoIP:/usr/share/GeoIP:ro
29+
- geoip-data:/usr/share/GeoIP:ro
1930
depends_on:
2031
- redis
32+
- geoipupdate
2133
restart: unless-stopped
2234

2335
web:
@@ -41,10 +53,10 @@ services:
4153
- "${WEB_LISTEN:-0.0.0.0}:80:80"
4254
volumes:
4355
- ./data:/app/data
44-
- /usr/share/GeoIP:/usr/share/GeoIP:ro
4556
depends_on:
4657
- redis
4758
restart: unless-stopped
4859

4960
volumes:
5061
redis-data:
62+
geoip-data:

0 commit comments

Comments
 (0)