Skip to content

Commit 975fc8b

Browse files
committed
feat(stats): refactor global stats sockets
This allows for multiple sockets to be defined, which is useful if multiple sockets with different access levels are desired. This is altering the haproxy:global:stats pillar structure and hence a BREAKING CHANGE. Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
1 parent 42b603b commit 975fc8b

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

haproxy/templates/haproxy.jinja

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ global
4545
{%- if salt['pillar.get']('haproxy:global:daemon', 'no') == True %}
4646
daemon
4747
{%- endif %}
48-
{%- if salt['pillar.get']('haproxy:global:stats:enable', 'no') == True %}
49-
{%- set socketpath = salt['pillar.get']('haproxy:global:stats:socketpath', '/tmp/ha_stats.sock') %}
50-
{%- set mode = salt['pillar.get']('haproxy:global:stats:mode', '660') %}
51-
{%- set level = salt['pillar.get']('haproxy:global:stats:level', 'operator') %}
52-
stats socket {{ socketpath }} mode {{ mode }} level {{ level }}{% if 'extra' in salt['pillar.get']('haproxy:global:stats', {}) %} {{ salt['pillar.get']('haproxy:global:stats:extra') }}{% endif %}
53-
{%- endif %}
48+
{%- for socket, socket_config in salt['pillar.get']('haproxy:global:stats', {}).items() %}
49+
stats socket {{ socket }} mode {{ socket_config.get('mode', '0600') }} level {{ socket_config.get('level', 'user') }} user {{ socket_config.get('user', 'haproxy') }} group {{ socket_config.get('group', 'haproxy') }}
50+
{%- endfor %}
5451
{%- if 'maxconn' in salt['pillar.get']('haproxy:global', {}) %}
5552
maxconn {{ salt['pillar.get']('haproxy:global:maxconn') }}
5653
{%- endif %}

pillar.example

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@ haproxy:
2424
log-tag: haproxy
2525
# Optional log-send-hostname parameter, sets the hostname field in the syslog header
2626
log-send-hostname: localhost
27+
# stats sockets
2728
stats:
28-
enable: true
29-
socketpath: /var/lib/haproxy/stats
30-
mode: 660
31-
level: admin
32-
# yamllint disable-line rule:line-length
33-
# Optional extra bind parameter, for example to set the owner/group on the socket file
34-
extra: user haproxy group haproxy
29+
/run/haproxy/stats-ro:
30+
# the defaults
31+
level: user
32+
mode: 600
33+
user: haproxy
34+
group: haproxy
35+
/run/haproxy/stats-rw:
36+
# custom example
37+
level: admin
38+
mode: 660
39+
group: sysadmins
3540
# yamllint disable-line rule:line-length
3641
ssl-default-bind-ciphers: "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384"
3742
ssl-default-bind-options: "no-sslv3 no-tlsv10 no-tlsv11"

test/salt/pillar/default.sls

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ haproxy:
2121
# Optional log-send-hostname parameter, sets the hostname field in the syslog header
2222
log-send-hostname: localhost
2323
stats:
24-
enable: true
25-
# Using the `haproxy:global:chroot:path`
26-
socketpath: /var/lib/haproxy/stats
27-
mode: 660
28-
level: admin
29-
# yamllint disable-line rule:line-length
30-
# Optional extra bind parameter, for example to set the owner/group on the socket file
31-
extra: user haproxy group haproxy
24+
/run/haproxy/stats-operator:
25+
level: operator
26+
mode: 660
27+
group: wheel
28+
/run/haproxy/stats-admin:
29+
level: admin
30+
mode: 600
3231
# yamllint disable-line rule:line-length
3332
ssl-default-bind-ciphers: "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384"
3433
ssl-default-bind-options: "no-sslv3 no-tlsv10 no-tlsv11"

0 commit comments

Comments
 (0)