Exemple de service ReverseProxy qui permet de faire un filtrage IP.
Pour modifier la restriction, il suffit
- d’éditer le service et de modifier le template de fichier :
/usr/local/etc/haproxy/whitelist.lst - Vous pourriez aussi renseigner les IP dans une variable par exemple.
Il suffirait de creer IPWHILIST = « yy.yy.yyy.yyy/32 xx.xxx.xxx.xxx/32 »
Exemple de fichier yaml que vous pouvez « importer » depuis l’onglet Services, qui fait un lien vers le service myprivateservice sur le port 80
services:
- type: classic
id: reverseproxy
name: Reverse Proxy
dockerConfiguration:
image: haproxy
imageVersion: latest
countMin: 1
countMax: 1
ports:
- listeningPort: 80
protocol: tcp
healthCheckType: HTTP
healthCheckMethod: GET
healthCheckPath: /
loadBalancerRules:
- publicPort: 443
links:
- toServiceId: "myprivateserviceid"
toServicePort: 80
localExposedPort: 8080
variableHost: APP_HOST
variablePort: APP_PORT
variableAddress: APP_ADDRESS
environmentVariables:
- key: IPWHILIST
value: 'xx.xx.xxx.xxx xx.xx.xxxxxx'
files:
- content: |
xx.xx.xxx.xxx/32
xx.xx.xxxxxx/32
path: /usr/local/etc/haproxy/whitelist.lst
interpolate: true
perms: "444"
- content: |
global
log stdout format raw daemon
maxconn 2048
defaults
log global
mode http
option httplog
timeout connect 5s
timeout client 10s
timeout server 10s
frontend http-in
bind *:80
# Prendre l'IP réelle depuis X-Forwarded-For
http-request set-src hdr_ip(X-Forwarded-For,-1)
# Fichier de whitelist d'IP/ranges
acl allowed_ip src -f /usr/local/etc/haproxy/whitelist.lst
# Depuis un var d'env
acl allowed_ip_var src %IPWHILIST%
# Bloquer les IP non autorisées
http-request deny if !allowed_ip !allowed_ip_var
# Default backend
default_backend webapp
backend webapp
server web1 %APP_ADDRESS%
path: /usr/local/etc/haproxy/haproxy.cfg
interpolate: true
perms: "444"