Skip to content

Commit 7d56581

Browse files
committed
fix: [#246] bind Prometheus to localhost for secure validation
**Issue**: Prometheus port was completely removed for security, but this broke validation in e2e tests since the service couldn't be accessed from the host. **Solution**: Bind Prometheus port to localhost only (127.0.0.1:9090:9090) instead of removing it entirely or exposing it to all interfaces (0.0.0.0). **Changes**: - Update docker-compose template to bind port 9090 to 127.0.0.1 only - Update test to verify localhost-only binding is present - Prometheus remains accessible from Docker network for Grafana - Validation works via SSH: curl http://localhost:9090 **Security Benefits**: - Before: Port removed (no validation possible from host) - After: Port bound to localhost (validation works, no external exposure) - Grafana access: Unchanged (uses Docker network: http://prometheus:9090) - External access: Still blocked (not accessible from outside VM) **Verification**: - All e2e deployment workflow tests passing (~73s) - Prometheus smoke test successful via localhost - Port not exposed to external network
1 parent 5116f33 commit 7d56581

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 is NOT exposed (internal service only)
388+
// Verify port is bound to localhost only (not exposed to external network)
389389
assert!(
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)"
390+
rendered_content.contains("127.0.0.1:9090:9090"),
391+
"Prometheus port 9090 should be bound to localhost only (not exposed to external 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,9 +65,10 @@ services:
6565
restart: unless-stopped
6666
networks:
6767
- backend_network
68-
# Port 9090 NOT exposed to host - internal service only
68+
ports:
69+
- "127.0.0.1:9090:9090" # Localhost only - not exposed to external network
6970
# Grafana accesses Prometheus via Docker network: http://prometheus:9090
70-
# For debugging, use: docker exec -it prometheus wget -qO- http://localhost:9090/metrics
71+
# Host can access for validation via: curl http://localhost:9090
7172
volumes:
7273
- ./storage/prometheus/etc:/etc/prometheus:Z
7374
logging:

0 commit comments

Comments
 (0)