Skip to content

Commit 8323def

Browse files
committed
fix: [#246] remove Prometheus port exposure for security
**Security Issue**: Prometheus port 9090 was exposed to external network due to Docker bypassing UFW firewall rules when using 0.0.0.0:9090:9090 binding. **Root Cause**: Docker manipulates iptables directly, taking precedence over UFW rules. Even with UFW default policy 'deny incoming', Docker port bindings bypass this protection. **Solution**: Remove port mapping entirely for Prometheus service. Grafana can still access Prometheus via Docker internal network (http://prometheus:9090). **Changes**: - Remove 'ports: - "9090:9090"' from Prometheus service in docker-compose.yml.tera - Add comment explaining Prometheus is internal-only - Update test to verify port is NOT exposed (security expectation) - Grafana continues to work via Docker network communication **Security Impact**: - Before: Prometheus UI accessible at http://<vm-ip>:9090 (exposed) - After: Prometheus UI NOT accessible externally (internal-only) - Grafana access: Unchanged (uses Docker network) **Verification**: - All 1555 unit tests passing - UFW firewall correctly denies incoming by default - Only SSH, Tracker, and Grafana ports should be accessible This issue existed since Prometheus slice implementation but was not detected until Grafana integration testing revealed the exposure.
1 parent 696fc0d commit 8323def

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/infrastructure/templating/docker_compose/template/renderer/docker_compose.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ mod tests {
385385
"Should set container name"
386386
);
387387

388-
// Verify port mapping
388+
// Verify port is NOT exposed (internal service only)
389389
assert!(
390-
rendered_content.contains("9090:9090"),
391-
"Should expose Prometheus port 9090"
390+
!rendered_content.contains("ports:") || !rendered_content.contains("9090:9090"),
391+
"Prometheus port 9090 should NOT be exposed to host (internal service only, accessed via Docker network)"
392392
);
393393

394394
// Verify volume mount

templates/docker-compose/docker-compose.yml.tera

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ services:
6565
restart: unless-stopped
6666
networks:
6767
- backend_network
68-
ports:
69-
- "9090:9090"
68+
# Port 9090 NOT exposed to host - internal service only
69+
# Grafana accesses Prometheus via Docker network: http://prometheus:9090
70+
# For debugging, use: docker exec -it prometheus wget -qO- http://localhost:9090/metrics
7071
volumes:
7172
- ./storage/prometheus/etc:/etc/prometheus:Z
7273
logging:

0 commit comments

Comments
 (0)