1
0
Fork 0
docker-easy-haproxy/examples/docker/docker-compose-ip-whitelist.yml
Joao Gilberto Magalhaes 5767e55dea Refactor Docker Compose examples and plugins, add pytest tests
- Adjusted Compose files to build images locally instead of pulling.
- Simplified examples by removing `/etc/hosts` entry instructions.
- Enhanced `cloudflare.py` plugin with a configurable log format.
- Improved `generate-keys.sh` for portability using `$SCRIPT_DIR`.
- Added end-to-end tests for Compose examples using pytest.
2026-02-11 19:19:08 -05:00

79 lines
2.4 KiB
YAML

# ==============================================================================
# EXAMPLE: IP Whitelist Plugin
# ==============================================================================
#
# WHAT THIS DEMONSTRATES:
# - Restricting access to specific IP addresses or CIDR ranges
# - Single IP, CIDR notation, and multiple IP support
# - Custom HTTP status code for blocked requests
# - Admin panel or sensitive application protection
#
# # IMPORTANT: Update the easyhaproxy.http.plugin.ip_whitelist.allowed_ips with your actual IPs!
# # Default allows localhost and private networks for testing
# ```
#
# HOW TO START:
# ```bash
# docker compose -f docker-compose-ip-whitelist.yml up -d
# ```
#
# HOW TO VERIFY IT'S WORKING:
# ```bash
# # Test from localhost (127.0.0.1 is whitelisted)
# curl -k -H "Host: admin.local" http://127.0.0.1/
# # Expected: 200 OK - Access granted
#
# # Test from non-whitelisted IP
# # You'll need to test from another machine or temporarily remove your IP
# # from the allowed_ips list to see the 403 Forbidden response
#
# # View HAProxy stats to see blocked requests
# # URL: http://localhost:1936
# # Username: admin
# # Password: password
# ```
#
# CLEAN UP:
# ```bash
# docker compose -f docker-compose-ip-whitelist.yml down
# ```
#
# ==============================================================================
services:
haproxy:
build:
context: ../../
dockerfile: build/Dockerfile
image: byjg/easy-haproxy:local
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
EASYHAPROXY_DISCOVER: docker
HAPROXY_CUSTOMERRORS: "true"
HAPROXY_USERNAME: admin
HAPROXY_PASSWORD: password
HAPROXY_STATS_PORT: 1936
ports:
- "80:80/tcp"
- "1936:1936/tcp"
# Admin panel with IP whitelist
admin:
image: byjg/static-httpserver
environment:
TITLE: "Admin Panel - IP Restricted"
labels:
easyhaproxy.http.host: admin.local
easyhaproxy.http.port: 80
easyhaproxy.http.localport: 8080
# Enable IP whitelist plugin
easyhaproxy.http.plugins: ip_whitelist
# Allow localhost and private networks
# UPDATE THIS with your actual IPs/networks!
easyhaproxy.http.plugin.ip_whitelist.allowed_ips: 127.0.0.1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12
# Status code to return for blocked IPs
easyhaproxy.http.plugin.ip_whitelist.status_code: 403