Self-hosting is like surfing — sometimes you run into pirates

Case Study: Anatomy of a Mass Gitea Web Crawl, Synology NAS I/O Saturation Analysis, and Credential Leak Forensic Audit

  • Incident Date: October 25, 2026
  • Target System: Self-hosted Gitea instance (gitea.wired.synology.me) running on a Synology NAS (wiredNAS).
  • Incident Classification: Resource Exhaustion / Web Crawling DoS and Credential Exposure Forensic Audit.
  • Remediation Status: Successfully Resolved (full system resource recovery, database password rotation, and git repository sanitization).

1. Environmental Architecture (Homelab SOE)

The incident impacted the central server node of the homelab infrastructure:

  • Hardware Host: Synology DiskStation DS (hostname: wiredNAS, OS: Synology DSM 7.x, architecture: x86_64, 4-core CPU, 17.4 GB DDR4 RAM).
  • Storage Subsystem: RAID1 storage pool consisting of two 12 TB Western Digital Red Plus HDDs (WD120EFBX) on ports /dev/sata1 and /dev/sata2, managed by Btrfs on volume /volume1 (total capacity: 11 TB, utilization: 86% / 9.0 TB).
  • Container Runtime: Synology Container Manager (Docker Engine 24.x). The host runs over 30 containerized services (including Gitea, PostgreSQL, Authentik, Pi-hole, Home Assistant, n8n, Zabbix, Wiki.js, Karakeep, Referat).
  • Gitea Service Stack:
    • Application Engine: gitea container (listening internally on HTTP port 3000, external SSH port 2222).
    • Database: gitea-db-1 container (PostgreSQL 16 on a dedicated Docker bridge network).
  • Network Edge & Ingress: Built-in Synology DSM NGINX server acting as a Reverse Proxy (terminating SSL/TLS on port 443 for *.wired.synology.me and *.wired.sytes.net).

2. Incident Chronology: What Happened? (Timeline & Telemetry)

Phase I: Preliminary Reconnaissance & Subdomain Scanning (08:57 – 11:15)

Beginning in the early morning hours, the host NGINX error log (/var/log/nginx/error.log) recorded automated internet web scrapers and port scanning bots probing port 443 across homelab subdomains looking for exposed management consoles and configuration files:

2026/10/25 08:44:50 [error] client: 16.216.88.11, server: openui.wired.synology.me, request: "GET / HTTP/2.0"
2026/10/25 08:45:15 [error] client: 5.102.169.102, server: draw.wired.synology.me, request: "GET / HTTP/2.0"
2026/10/25 08:45:17 [error] client: 5.102.169.102, server: zabbix.wired.synology.me, request: "GET / HTTP/1.1"
2026/10/25 08:45:21 [error] client: 5.102.169.102, server: rss.wired.synology.me, request: "GET / HTTP/2.0"
2026/10/25 08:45:22 [error] client: 5.102.169.102, server: firefly.wired.synology.me, request: "GET / HTTP/2.0"

Around 08:57, crawlers targeted gitea.wired.synology.me. Because several user repositories had been temporarily designated as public (is_private = false), search bots began aggressively indexing the codebase tree.

Phase II: Initial Overload Surge (11:17 – 11:22)

At 11:17, concurrent request concurrency surged. Gitea container logs began filling with broken pipe errors (io: read/write on closed pipe) and canceled request contexts (context canceled), caused by client drops and NGINX timeouts:

2026/10/25 11:17:15 routers/web/repo/commit.go:329:Diff() [E] GetDiffShortStat: io: read/write on closed pipe
2026/10/25 11:18:22 routers/web/repo/blame.go:212:processBlameParts() [E] Repo.GitRepo.GetCommit: io: read/write on closed pipe
2026/10/25 11:19:04 routers/web/repo/view.go:141:loadLatestCommitData() [E] GetLatestCommitStatus: context canceled

Error rate distribution during Wave I: 63 errors/min (11:17), 28 errors/min (11:18), 61 errors/min (11:19).

Phase III: Peak Resource Exhaustion & I/O Saturation (12:12 – 12:31)

Between 12:12 and 12:31, distributed crawling reached peak intensity:

  • Network Connections: netstat -ant inspection revealed 1,548 concurrent active TCP connections on port 443 originating from hundreds of unique international IPs (Brazil, Sweden, Morocco, France, Germany, Uruguay, Netherlands, China).
  • CPU and Scheduler State:
    • Load average peaked at 16.82 (on a 4-core host where 4.0 is the baseline threshold).
    • top snapshot:top - 12:30:43 up 13:18, load average: 14.58, 10.87, 8.54 %Cpu(s): 14.3 us, 11.0 sy, 0.0 ni, 0.0 id, 73.6 wa, 0.0 hi, 1.1 siCPU time trapped in disk I/O wait (I/O Wait, %wa) surged to 73.6%!
  • Mechanical Hard Drives (WD Red Plus): Telemetry from iostat -xz 1 2 confirmed severe disk saturation (%util) at 97.20% (sata1) and 89.30% (sata2):Device r/s rkB/s w/s wkB/s aqu-sz %util sata1 125.00 26440.00 188.00 3188.00 34.82 97.20 sata2 75.00 24080.00 188.00 3188.00 12.71 89.30 md2 244.00 63788.00 186.00 3068.00 42.72 97.30
  • PostgreSQL Gitea Database: Slow queries escalated to 5–7 seconds per repository metadata lookup:2026/10/25 12:29:17 models/repo/repo.go:831:GetRepositoryByName() [W] [Slow SQL Query] SELECT ... FROM "repository" WHERE ("owner_id"=$1) AND ("lower_name"=$2) LIMIT 1 - 7.031790271s
  • Gitea Container Memory: Memory consumption climbed to 1.69 GiB, dangerously near the container’s hard limit of 2 GiB.

3. Forensic Investigation: Hypothesis Testing and Root Cause Identification

Hypothesis A: Was the load driven by scheduled background tasks (Cron / CI/CD)?

  • CI/CD Pipeline Validation (Gitea Actions):
    Inspecting the action_task table inside the PostgreSQL database (gitea-db-1): SELECT id, job_id, status, to_timestamp(updated) as updated_at FROM action_task ORDER BY id DESC LIMIT 5;Result: The last CI runner job executed on October 23, 2026. Zero runner tasks ran on October 25.
  • Gitea Internal Cron Inspection (mirror):
    Querying the mirror table showed 30 mirror repositories set to synchronize on an 8-hour cycle (interval: 28800000000000 ns). Two mirrors refreshed at 12:11 and 12:41 (git fetch --prune).
  • Disproving Evidence: Gitea’s mirror synchronization operates at the git transport layer (services/mirror) and never calls the web presentation router.
    During the 12:12–12:31 peak, all recorded failures originated directly inside web controllers:
    • routers/web/repo/blame.go (processBlameParts),
    • routers/web/repo/commit.go (Diff, FileHistory),
    • routers/web/repo/view_file.go (prepareFileView).
    Conclusion: The load was 100% driven by external HTTP GET requests targeting the web UI.

Hypothesis B: Which processes saturated the disk I/O queue?

A custom Python sampling script was executed against /proc/[pid]/io on the Synology host across a 3-second differential window:

TOTAL(MB) READ(MB)   WRITE(MB)  PID      COMMAND
   64.41      64.41       0.00 5737     /usr/local/bin/gitea web 
   19.26      19.26       0.00 4095     /usr/libexec/git-core/git pack-objects --stdout --thin --delta-base-offset --all
   14.39      12.35       2.04 32682    /usr/libexec/git-core/git pack-objects --stdout --thin --delta-base-offset --all
   10.55       8.71       1.84 3199     /usr/libexec/git-core/git pack-objects --stdout --thin --delta-base-offset --all

Inspecting the current working directory of PID 4095 (/proc/4095/cwd):

/proc/4095/cwd -> /data/gitea/tmp/git-repo-content/gitea-bundle2050435557

Evidence: Web bots were not merely scraping HTML pages; they were systematically triggering ZIP / TAR / Git bundle downloads across all accessible repositories, forcing mechanical hard drives to perform thousands of random seek operations on small git packfiles.

Hypothesis C: Which repositories were targeted and indexed by the crawlers?

By filtering Gitea container logs for parser path errors (fatal: no such path... in <commit-sha>), we extracted the exact target directories queried by the bots:

docker logs gitea 2>&1 | grep -o '/data/git/repositories/soda64/[^)]*' | sort | uniq -c

Queries targeting the soda64 user profile:

  1. wired-system-starter.git (22 hits): crawled stack templates: stacks/web-ts, stacks/apple-swift, stacks/android-kotlin, stacks/php, stacks/desktop-tauri.
  2. herdr-init.git (6 hits): crawled the docs folder.
  3. wired-data-system.git (5 hits): crawled examples examples/04-python-cli-offline, examples/03-fastapi-sync-server, examples/02-react-local-first.
  4. referat.git (3 hits): crawled integration bridges: integrations/gitea, integrations/homeassistant, integrations/pve.
  5. zarys.git (3 hits): crawled templates/common.
  6. dnd5.5-character-builder.git (3 hits): crawled the books folder.
  7. wired-design-system.git (1 hit).

The crawlers also aggressively indexed public GitHub mirrors: mirrors/rea (querying scripts/lib/catalog-cli.mjs), mirrors/VoiceStudio, and mirrors/dumbtv.


4. Security Audit: Were Credentials, Passwords, or Access Tokens Exfiltrated?

Automated botnets of this nature function as secret harvesters—scanning commit histories with regular expressions seeking accidentally committed cloud API keys, SSH keys, and database credentials. A forensic audit was performed across all accessed repositories.

4.1. Verification of External Infrastructure Tokens (Home Assistant, Proxmox, Zabbix, OpenAI, SSH)

Every commit in the git object store was analyzed for committed .env files or authentication credentials:

git --git-dir=/data/git/repositories/soda64/referat.git log --all --full-history --summary -- "*.env*"

Evidence: The only matching file across the entire history was .env.example. Reviewing its contents at commit d7608d8 and HEAD:

HOMEASSISTANT_API_KEY='YOUR_HOMEASSISTANT_API_KEY_HERE'
PVE_API_TOKEN_ID='YOUR_PVE_API_TOKEN_ID_HERE'
PVE_API_SECRET='YOUR_PVE_API_SECRET_HERE'
ZABBIX_API_TOKEN='YOUR_ZABBIX_API_TOKEN_HERE'
NETALERT_X_API_KEY='YOUR_NETALERT_X_API_KEY_HERE'
GITEA_API_KEY='YOUR_GITEA_API_KEY_HERE'

Across all integration bridges (referat/integrations/*/*.py):
All credentials are dynamically pulled from the runtime environment using os.environ.get(...). No real API tokens or private keys were ever committed.

4.2. FINDING: Hardcoded Database Password in Referat

During the audit, one plaintext production password was uncovered:

  • In referat.git (docker-compose.yml and .env.example):services: referat-db: environment: POSTGRES_DB: referat POSTGRES_USER: referat POSTGRES_PASSWORD: referat_secure_password_123
  • Validation against Live Production Container:
    Executing docker inspect referat_postgres revealed:"POSTGRES_PASSWORD=referat_secure_password_123"The password in the git repository was identical to the active password on the production database container.

4.3. Attack Vector Analysis and Risk Assessment for the Discovered Password

Could remote internet scrapers use referat_secure_password_123 to breach the database?

  1. Synology Reverse Proxy Configuration (/usr/syno/etc/www/ReverseProxy.json):
    • PostgreSQL port 9433 was never exposed to the internet by the reverse proxy.
    • Only the web interface (9434 -> referat.wired.synology.me) was mapped externally, and it utilizes a separate session-based authentication layer in FastAPI with bcrypt password hashing (web/auth.py).
  2. Boundary Router Exposure:
    Port 9433 was not forwarded on the edge router.
  3. Risk Determination:
    Direct remote exploitation over the internet was impossible. Exploiting this leaked password would have required an attacker to already possess an active foothold inside the internal LAN (192.168.11.x). Nonetheless, storing a live database password in repository source code represented a high-severity flaw requiring immediate rotation.

5. Executed Remediation (Recovery Procedure)

A 5-step remediation workflow was carried out:

Step 1: Immediate Access Revocation (Gitea Private Visibility)

The administrator reverted all affected repositories to is_private = true.
Verification:

curl -I -s http://127.0.0.1:3000/soda64/referat
# Output: HTTP/1.1 404 Not Found

Unauthenticated crawlers were immediately cut off with HTTP 404. Port 443 active connections plummeted from 1,548 to 51, and system load average returned from 16.82 down to 1.01.

Step 2: Strong Cryptographic Password Generation & Local .env Creation

On the Synology NAS, a new 32-character random alphanumeric password was generated using Python’s secrets module and written directly to /volume1/docker/referat/.env with strict 0600 permissions:

sudo ls -l /volume1/docker/referat/.env
# -rw------- 1 root root 53 Oct 25 13:19 /volume1/docker/referat/.env

The .env file is excluded from git via .gitignore.

Step 3: Refactoring docker-compose.yml on the NAS

Hardcoded credentials were replaced with environment variable references:

services:
  referat-db:
    environment:
      POSTGRES_DB: referat
      POSTGRES_USER: referat
      POSTGRES_PASSWORD: ${REFERAT_DB_PASSWORD}

  referat-web:
    environment:
      - REFERAT_DB_HOST=referat-db
      - REFERAT_DB_PORT=5432
      - REFERAT_DB_NAME=referat
      - REFERAT_DB_USER=referat
      - REFERAT_DB_PASSWORD=${REFERAT_DB_PASSWORD}

Step 4: Database Role Password Rotation in PostgreSQL

Because PostgreSQL ignores modified environment variables once a data cluster has been initialized in /data, the credentials were reset directly in the database engine:

ALTER USER referat WITH PASSWORD '<NEW_32_CHAR_SECRET>';

Restarting the container stack (docker compose up -d):

referat_postgres    Up (healthy)   0.0.0.0:9433->5432/tcp
referat_web_console Up             0.0.0.0:9434->8080/tcp

Testing the web API endpoint /docs: HTTP/1.1 200 OK (web console successfully authenticated against the database).

Step 5: Git Repository Sanitization & Commit (referat.git)

In the local project workspace (~/Projekty/referat):

  1. In docker-compose.yml, the static password was replaced with ${REFERAT_DB_PASSWORD}.
  2. In .env.example, the placeholder was changed to YOUR_REFERAT_DB_PASSWORD_HERE.
  3. Changes were committed and pushed to Gitea:commit d6c5f52: fix(security): replace hardcoded database password with env var and update .env.example To https://gitea.wired.synology.me/soda64/referat.git 5f35bf0..d6c5f52 main -> main

6. Key Takeaways and Hardening Recommendations

  1. Strict Zero-Secrets Standard:
    docker-compose.yml files must never contain static passwords in environment directives. Always decouple credentials using local .env files (e.g., ${DB_PASSWORD}) coupled with sanitized .env.example templates.
  2. Restricting Anonymous Gitea Browsing:
    In /volume1/docker/gitea/data/gitea/conf/app.ini, enable mandatory sign-in:[service] REQUIRE_SIGNIN_VIEW = trueThis prevents bots from scraping and cloning code from public repositories without prior GUI authentication.
  3. Synology Reverse Proxy Ingress Hardening:
    In the Synology DSM Reverse Proxy configuration, attach an Access Control List (ACL) to gitea.wired.synology.me, restricting access exclusively to trusted network segments (local LAN 192.168.0.0/16 and authenticated VPN / Tailscale interfaces).

Opublikowano

w

przez

Tagi:

Komentarze

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Wymagane pola są oznaczone *