How ericpino/goguard works
Purpose and execution model
goGuard is a Go daemon for detecting malicious HTTP access-log requests and blocking source IPs after repeated threat matches. The sole application entry point is main.go; it runs as a native Linux binary or a containerized process. Runtime configuration is environment-driven via .env.example.
Startup and configuration boundary
At startup, the daemon loads log-tail location, blocking mode, hit/window thresholds, whitelist ranges, and credentials for Cloudflare and Telegram. These settings define the operational boundary between local host enforcement and optional external integrations.
• main.go
• .env.example
Real-time log ingestion
The primary input is a web-server access log, such as Nginx’s access log. The daemon continuously tails this file, parses incoming lines sufficiently to identify the request source IP and requested URL/payload, then passes each event into threat evaluation.
• main.go
Threat detection and qualification
Requests are evaluated against regex-style signatures for SQLi, XSS, traversal/reconnaissance, RCE, SSTI/JNDI, and common admin probes. A match is not necessarily a ban: suspicious activity is attributed to its source IP and counted within a sliding time window, reducing single-request false positives.
• main.go
IP state, whitelist, and ban decision
The daemon maintains in-memory operational state for processed lines, detected threats, per-IP hit histories, and blocked IPs used by --status. Whitelisted literal IPs and CIDR ranges—including optionally Cloudflare address space—bypass ban handling. Once a non-whitelisted IP reaches MAX_HITS during TIME_WINDOW_SECONDS, it crosses the enforcement boundary.
• main.go
• .env.example
Enforcement and notifications
Blocking can target local iptables, Cloudflare’s Firewall Access Rules API, or both, according to BLOCK_MODE. Local enforcement requires Linux and root/sudo-level access to alter firewall rules. Cloudflare enforcement requires zone-scoped API credentials and protects at the edge. Ban events can also be sent through the Telegram Bot API.
• main.go
• .env.example
Deployment/runtime infrastructure
The repository supports direct compilation using the Go module definition and container deployment through Docker Compose. Container deployment must preserve access to the tailed log and, for local firewall mode, sufficient host networking/capabilities to execute iptables.
• go.mod
• Dockerfile
• docker-compose.yml
Main entry points: main.go Threshold decision · docker-compose.yml Docker Compose runtime · Dockerfile Container image · .env.example Environment config
Components 14
Runtime Inputs
- Environment config · Thresholds, whitelist, blocking mode, and integration credentials.
.env.example - Web access log
goGuard Daemon
- Daemon entry point
main.go - Log tailer and parser · Extracts source IP and request payload from new log lines.
main.go - Threat signatures · Matches SQLi, XSS, traversal, RCE, SSTI/JNDI, and admin probes.
main.go - IP hit state · Tracks hit histories, detected threats, processed lines, and blocked IPs.
main.go - Whitelist filter · Literal IPs, CIDRs, and optional Cloudflare ranges bypass bans.
main.go - Threshold decision · Bans non-whitelisted IPs reaching MAX_HITS within TIME_WINDOW_SECONDS.
main.go
Enforcement
- Local iptables · Requires Linux privileges for local blocking.
- Cloudflare Firewall API · Creates zone-scoped Firewall Access Rules.
- Telegram Bot API
Deployment
- Go module
go.mod - Container image
Dockerfile - Docker Compose runtime · Mounts the tailed log and supplies host privileges when local blocking is enabled.
docker-compose.yml
Connections 16
- Environment config → Daemon entry point: loads settings
- Web access log → Log tailer and parser: new lines
- Daemon entry point → Log tailer and parser: starts
- Log tailer and parser → Threat signatures: request event
- Threat signatures → IP hit state: matched threat
- IP hit state → Whitelist filter: source IP
- Whitelist filter → Threshold decision: non-whitelisted IP
- Threshold decision → IP hit state: records blocked IP
- Threshold decision → Local iptables: local or both mode
- Threshold decision → Cloudflare Firewall API: Cloudflare or both mode
- Threshold decision → Telegram Bot API: ban alert
- Go module → Daemon entry point: builds
- Container image → Daemon entry point: packages
- Docker Compose runtime → Container image: runs image
- Docker Compose runtime → Web access log: mounts log
- Docker Compose runtime → Local iptables: host capabilities