Skip to content

Commit

Permalink
Haproxy: Allow staging backends to be accessed from source ips
Browse files Browse the repository at this point in the history
  • Loading branch information
quartje committed Oct 30, 2023
1 parent 14330d4 commit 06a0493
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions roles/haproxy/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ haproxy_internalips:
- 0.0.0.0/0
- ::0/0
haproxy_hsts_value: "max-age=34214400"
# If you have a staging server you want to be accessed from certain ips, and them to this list
haproxy_stagingips:
- ''
1 change: 1 addition & 0 deletions roles/haproxy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
- allowedips.acl
- blockedips.acl
- internalips.acl
- stagingips.acl
notify:
- "reload haproxy"

Expand Down
10 changes: 6 additions & 4 deletions roles/haproxy/templates/haproxy_frontend.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ frontend internet_ip
frontend local_ip
bind 127.0.0.1:81 accept-proxy
acl valid_vhost hdr(host) -f /etc/haproxy/acls/validvhostsunrestricted.acl
acl staging req.cook(staging) -m str true
acl staging src -f /etc/haproxy/acls/stagingips.acl
acl stagingvhost hdr(host) -i -M -f /etc/haproxy/maps/backendsstaging.map
acl stagingcookie req.cook(staging) -m str true
use_backend %[req.hdr(host),lower,map(/etc/haproxy/maps/backendsstaging.map)] if stagingvhost stagingcookie
use_backend %[req.hdr(host),lower,map(/etc/haproxy/maps/backendsstaging.map)] if stagingvhost staging
use_backend %[req.hdr(host),lower,map(/etc/haproxy/maps/backends.map)]
option httplog
capture request header User-agent len 256
Expand Down Expand Up @@ -151,9 +152,10 @@ frontend internet_restricted_ip
frontend localhost_restricted
bind 127.0.0.1:82 accept-proxy
acl valid_vhost hdr(host) -f /etc/haproxy/acls/validvhostsrestricted.acl
acl staging req.cook(staging) -m str true
acl staging src -f /etc/haproxy/acls/stagingips.acl
acl stagingvhost hdr(host) -i -M -f /etc/haproxy/maps/backendsstaging.map
acl stagingcookie req.cook(staging) -m str true
use_backend %[req.hdr(host),lower,map(/etc/haproxy/maps/backendsstaging.map)] if stagingvhost stagingcookie
use_backend %[req.hdr(host),lower,map(/etc/haproxy/maps/backendsstaging.map)] if stagingvhost staging
use_backend %[req.hdr(host),lower,map(/etc/haproxy/maps/backends.map)]
option httplog
capture request header User-agent len 256
Expand Down
3 changes: 3 additions & 0 deletions roles/haproxy/templates/stagingips.acl.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for ip in haproxy_stagingips %}
{{ ip }}
{% endfor %}

0 comments on commit 06a0493

Please sign in to comment.