Your Self-Hosted LLM Gateway Is an ATM for Someone Else’s Agent
Executive Summary
The proliferation of self-hosted Large Language Model (LLM) inference servers has introduced a critical, often overlooked attack vector: the "inference ATM." When developers expose local LLM endpoints (e.g., Ollama, vLLM, or Text Generation Inference) to public networks without rigorous authentication, they inadvertently create a resource-leasing service for malicious actors. These actors utilize stolen API keys or open ports to offload computationally expensive token generation, effectively turning homelab hardware into a rented compute farm. This guide details the engineering controls required to secure self-hosted LLM gateways, focusing on network isolation, strict access control, and operational visibility to prevent unauthorized inference billing and hardware degradation.
Implementation Architecture
Securing an LLM gateway requires shifting from a "trust-local-network" model to a "zero-trust" architecture. The core components involve the inference engine, a reverse proxy for authentication, and a network perimeter that prevents direct exposure of the GPU resources.
1. Network Topology and Isolation
The most common failure mode is binding the inference service to 0.0.0.0 (all interfaces) without a firewall. The following Mermaid diagram illustrates the secure topology, ensuring that only authenticated requests from authorized clients reach the inference engine.
graph TD
Client[Authorized Client / CLI] -->|HTTPS + Auth Token| ReverseProxy[Reverse Proxy<br/>Nginx / Caddy]
ReverseProxy -->|Internal Network| Inference[LLM Inference Engine<br/>Ollama / vLLM]
Inference --> GPU[Local GPU / TPU]
Subgraph Public Internet
Attacker[Malicious Actor] -.->|Blocked| Firewall[Host Firewall / UFW]
end
Firewall -->|Port 443 Only| ReverseProxy
Firewall -.->|Block 11434| Inference
style Attacker fill:#f9f,stroke:#333,stroke-width:2px
style Firewall fill:#ff9,stroke:#333,stroke-width:2px
style Inference fill:#9cf,stroke:#333,stroke-width:2px
2. Docker Compose Configuration with Authentication
Using generic placeholders is insufficient for production-grade homelab security. Below is a concrete docker-compose.yml example using Ollama as the inference engine and Caddy as the reverse proxy. This configuration enforces HTTPS, basic authentication, and restricts network exposure.
version: '3.8'
services:
ollama:
image: ollama/ollama:latest
container_name: ollama-server
restart: unless-stopped
# CRITICAL: Bind to localhost only. Never expose 11434 to 0.0.0.0
ports:
- "127.0.0.1:11434:11434"
volumes:
- ollama-data:/root/.ollama
environment:
- OLLAMA_HOST=127.0.0.1
- OLLAMA_KEEP_ALIVE=5m
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
caddy:
image: caddy:2-alpine
container_name: llm-gateway
restart: unless-stopped
ports:
- "443:443"
- "80:80"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy-data:/data
- caddy-config:/config
depends_on:
- ollama
volumes:
ollama-data:
caddy-data:
caddy-config:
The corresponding Caddyfile must enforce authentication and proxy traffic securely:
# Caddyfile Configuration
llm.yourdomain.com {
# Enforce HTTPS
tls admin@yourdomain.com
# Basic Authentication
basicauth {
# Generate hash: echo -n 'your_password' | caddy hash-password
"admin" "$2a$14$..."
}
# Rate Limiting to prevent brute-force and abuse
@rate_limit {
header X-Forwarded-For
remote_ip 10.0.0.x/24
}
handle_path /api/* {
reverse_proxy ollama:11434
}
# Log access for audit trails
log {
output file /var/log/caddy/access.log {
roll_size 100MB
roll_keep 5
}
}
}
3. Operational Pitfalls and Mitigations
The "Public Box" Error:
Many users assume that because they are on a home network, they are safe. However, if the reverse proxy is misconfigured or if the firewall allows inbound traffic on port 11434 (Ollama's default), any script kiddie can run:
curl http://your-public-ip:11434/api/generate -d '{"model":"llama3","prompt":"Hello"}'
This consumes your GPU memory and power, potentially leading to thermal throttling or hardware wear.
Mitigation Strategy:
- Firewall Rules: Use
ufworfirewalldto block all inbound traffic except port 443 (HTTPS) and 22 (SSH). ``bash sudo ufw allow 443/tcp sudo ufw allow 22/tcp sudo ufw enable`` - API Key Rotation: If using tools that support API keys (like vLLM or LiteLLM), rotate keys every 30 days. Store them in a secrets manager (e.g., HashiCorp Vault or Docker Secrets), not in plain text
.envfiles. - Monitoring: Implement Prometheus and Grafana to monitor GPU utilization. A sudden spike in GPU usage during off-hours is a strong indicator of unauthorized inference.
ShVaSa Intuition
The core intuition behind securing self-hosted LLMs is recognizing that compute is a fungible resource. Just as a stolen credit card is used to buy goods, a stolen LLM endpoint is used to buy "intelligence." The attacker does not care about the model; they care about the cost differential between their electricity/GPU cost and your potentially subsidized or sunk-cost hardware.
From an engineering perspective, the threat model is not about data privacy (though that is important) but about resource integrity. The "ATM" analogy holds because the attacker is extracting value (token generation) without authorization. The defense-in-depth strategy must therefore focus on:
- Authentication: Who is allowed to spend?
- Authorization: What can they spend on?
- Auditability: Did they spend?
By treating the LLM gateway as a financial instrument rather than a simple web service, engineers can apply rigorous security practices that prevent the "inference ATM" scenario. This includes strict network segmentation, mandatory authentication, and continuous monitoring of resource consumption patterns. The goal is not just to run the model, but to ensure that the model serves only authorized, verified, and auditable requests.
Grounding & Source Attribution
- Original Topic: Your Self-Hosted LLM Gateway Is an ATM for Someone Else’s Agent
- Primary Author / Dispatcher: Is It Vritra - SDE I via Medium Self-Hosting
- Curated and Synthesized by: ShVaSa Lab (Sharath Japa)
- Preserved Canonical URL: https://shvasa.us/posts/your-self-hosted-llm-gateway-is-an-atm-for-someone-elses-agent