Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. # Loadbalancer filter includes
  2. :HAPROXY - [0:0]
  3. -A INPUT -j HAPROXY
  4.  
  5. {# Loop through the haproxy_frontends looking for backends, then use the
  6. backend members' allow_hosts to create a list of ACL allows for this
  7. frontend #}
  8. {% for frontend in haproxy_frontend |
  9. selectattr('default_backend', 'defined') %}
  10. {# Use the 'allow_group_var' attribute to search for connection source IPs
  11. to allow access for if defined on the allow_groups hosts #}
  12. {% set _allowed_host_var = frontend.allow_groups_var |
  13. default('loadbalancer_connection_source') %}
  14. {# Build an allowed list of IPs for all hosts which are members of one of the
  15. allow_groups for this frontend, and have the _allowed_host_var defined #}
  16. {% set _allowed = frontend.allow_groups |
  17. map('extract', groups) |
  18. sum(start=[]) |
  19. map('extract', hostvars, _allowed_host_var) |
  20. select('defined') |
  21. unique | list %}
  22. {# Now dump the allow rules for this frontend #}
  23. {% for allow in _allowed %}
  24. {# Accommodate allow rules for multiple bind addresses #}
  25. {% for bind in frontend.bind %}
  26. {% set listen_port = bind.listen.split(':')[-1] %}
  27. {# IPv6 compatible listen_host #}
  28. {% set listen_host = bind.listen.split(':')[:-1] | join(':') %}
  29. -A HAPROXY -s {{ allow }} -d {{ listen_host }} -p tcp -m tcp --dport {{ listen_port }} -j ACCEPT -m comment --comment "Frontend {{ frontend.name }} allowed"
  30. {% endfor %}
  31. {% endfor %}
  32. {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement