Skip to content

Commit 263afe7

Browse files
committed
Use encrypt nginx/mariadb/node exporter traffic
This is not possible (yet) for php_fpm but that one also exposes the least interesting metrics for people snooping. If we would want that we would need to do something with nginx for this. This is relevant for the online judge but also makes sense as teams can always query the node endpoint on domservers.
1 parent 802be8d commit 263afe7

File tree

6 files changed

+126
-4
lines changed

6 files changed

+126
-4
lines changed

provision-contest/ansible/Makefile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ LIBVENDORTGZ=roles/domjudge_checkout/files/lib-vendor.tgz
1515
SSHKEY=roles/ssh/files/id_ed25519
1616
SSL_DOMSERVER=roles/ssl/files/domserver
1717
SSL_DOMSERVER_FILES=$(addprefix $(SSL_DOMSERVER),.key .crt)
18+
SSL_NODEEXPORT=roles/prometheus_target_all/files/node_exporter
19+
SSL_NODEEXPORT_FILES=$(addprefix $(SSL_NODEEXPORT),.key .crt)
1820
SSL_LOCALHOST=roles/ssl/files/localhost
1921
SSL_LOCALHOST_FILES=$(addprefix $(SSL_LOCALHOST),.key .crt)
2022
SSL_CDS=roles/ssl/files/cds
@@ -57,9 +59,12 @@ ansible-master:
5759
done
5860

5961
admin: $(SSL_LOCALHOST_FILES)
60-
grafana: $(SSL_GRAFANA_FILES)
61-
domserver: $(SSL_DOMSERVER_FILES)
62-
cds: $(SSL_CDS_FILES)
62+
grafana: $(SSL_GRAFANA_FILES) $(SSL_NODEEXPORT)
63+
domserver: $(SSL_DOMSERVER_FILES) $(SSL_NODEEXPORT)
64+
judgehost: $(SSL_NODEEXPORT)
65+
cds: $(SSL_CDS_FILES) $(SSL_NODEEXPORT)
66+
scoreboard: $(SSL_NODEEXPORT)
67+
mgmt: $(SSL_NODEEXPORT)
6368

6469
$(SSHKEY) $(SSHKEY).pub:
6570
ssh-keygen -t ed25519 -f $(SSHKEY) -P ''
@@ -68,6 +73,9 @@ $(SSL_DOMSERVER_FILES):
6873
openssl req -x509 -nodes -newkey rsa:4096 -subj "/O=DOMjudge/CN=domjudge" \
6974
-addext "subjectAltName = DNS:wf46-domjudge,DNS:wf47-domjudge,DNS:analyst" \
7075
-sha256 -days 365 -keyout $(SSL_DOMSERVER).key -out $(SSL_DOMSERVER).crt
76+
$(SSL_NODEEXPORT_FILES):
77+
openssl req -x509 -nodes -newkey rsa:4096 -subj "/O=DOMjudge/CN=metricexporter" \
78+
-sha256 -days 365 -keyout $(SSL_NODEEXPORT).key -out $(SSL_NODEEXPORT).crt
7179
$(SSL_LOCALHOST_FILES):
7280
openssl req -x509 -nodes -newkey rsa:4096 -subj "/O=DOMjudge/CN=localhost" \
7381
-sha256 -days 365 -keyout $(SSL_LOCALHOST).key -out $(SSL_LOCALHOST).crt
@@ -84,6 +92,7 @@ clean:
8492
distclean: clean
8593
rm -f $(SSHKEY) $(SSHKEY).pub
8694
rm -f $(SSL_DOMSERVER_FILES)
95+
rm -f $(SSL_NODEEXPORT)
8796
rm -f $(SSL_LOCALHOST_FILES)
8897
rm -f $(SSL_CDS_FILES)
8998
rm -f $(SSL_GRAFANA_FILES)

provision-contest/ansible/roles/grafana/templates/prometheus.yml.j2

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,72 @@ scrape_configs:
1616
- {{ hostvars[host].ansible_host }}:9104
1717
{% endfor %}
1818
- job_name: node_domserver
19+
basic_auth:
20+
username: "prometheus"
21+
password: "{{ PROMETHEUS_PASS }}"
22+
tls_config:
23+
insecure_skip_verify: true
24+
scheme: https
1925
static_configs:
2026
- targets:
2127
{% for host in groups["domserver"] %}
2228
- {{ hostvars[host].ansible_host }}:9100
2329
{% endfor %}
2430
- job_name: node_judgehost
31+
basic_auth:
32+
username: "prometheus"
33+
password: "{{ PROMETHEUS_PASS }}"
34+
tls_config:
35+
insecure_skip_verify: true
36+
scheme: https
2537
static_configs:
2638
- targets:
2739
{% for host in groups["judgehost"] %}
2840
- {{ hostvars[host].ansible_host }}:9100
2941
{% endfor %}
3042
- job_name: node_grafana
43+
basic_auth:
44+
username: "prometheus"
45+
password: "{{ PROMETHEUS_PASS }}"
46+
tls_config:
47+
insecure_skip_verify: true
48+
scheme: https
3149
static_configs:
3250
- targets:
3351
{% for host in groups["grafana"] %}
3452
- {{ hostvars[host].ansible_host }}:9100
3553
{% endfor %}
3654
- job_name: node_mgmt
55+
basic_auth:
56+
username: "prometheus"
57+
password: "{{ PROMETHEUS_PASS }}"
58+
tls_config:
59+
insecure_skip_verify: true
60+
scheme: https
3761
static_configs:
3862
- targets:
3963
{% for host in groups["mgmt"] %}
4064
- {{ hostvars[host].ansible_host }}:9100
4165
{% endfor %}
4266
- job_name: node_scoreboard
67+
basic_auth:
68+
username: "prometheus"
69+
password: "{{ PROMETHEUS_PASS }}"
70+
tls_config:
71+
insecure_skip_verify: true
72+
scheme: https
4373
static_configs:
4474
- targets:
4575
{% for host in groups["scoreboard"] %}
4676
- {{ hostvars[host].ansible_host }}:9100
4777
{% endfor %}
4878
- job_name: node_cds
79+
basic_auth:
80+
username: "prometheus"
81+
password: "{{ PROMETHEUS_PASS }}"
82+
tls_config:
83+
insecure_skip_verify: true
84+
scheme: https
4985
static_configs:
5086
- targets:
5187
{% for host in groups["cds"] %}
@@ -65,18 +101,36 @@ scrape_configs:
65101
- {{ hostvars[host].ansible_host }}
66102
{% endfor %}
67103
- job_name: 'web_nginx_cds'
104+
basic_auth:
105+
username: "prometheus"
106+
password: "{{ PROMETHEUS_PASS }}"
107+
tls_config:
108+
insecure_skip_verify: true
109+
scheme: https
68110
static_configs:
69111
- targets:
70112
{% for host in groups["cds"] %}
71113
- {{ hostvars[host].ansible_host }}:9113
72114
{% endfor %}
73115
- job_name: 'web_nginx_scoreboard'
116+
basic_auth:
117+
username: "prometheus"
118+
password: "{{ PROMETHEUS_PASS }}"
119+
tls_config:
120+
insecure_skip_verify: true
121+
scheme: https
74122
static_configs:
75123
- targets:
76124
{% for host in groups["scoreboard"] %}
77125
- {{ hostvars[host].ansible_host }}:9113
78126
{% endfor %}
79127
- job_name: 'web_nginx_domserver'
128+
basic_auth:
129+
username: "prometheus"
130+
password: "{{ PROMETHEUS_PASS }}"
131+
tls_config:
132+
insecure_skip_verify: true
133+
scheme: https
80134
static_configs:
81135
- targets:
82136
{% for host in groups["domserver"] %}

provision-contest/ansible/roles/prometheus_target_all/handlers/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@
55
enabled: true
66
state: restarted
77
daemon_reload: true
8+
9+
- name: Restart node-exporter
10+
service:
11+
name: prometheus-node-exporter
12+
enabled: true
13+
state: restarted

provision-contest/ansible/roles/prometheus_target_all/tasks/main.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,43 @@
66
state: present
77
pkg:
88
- prometheus-node-exporter
9+
10+
- name: Collect prometheus settings
11+
file:
12+
path: /etc/prometheus
13+
owner: root
14+
group: root
15+
mode: 0755
16+
state: directory
17+
18+
- name: Install SSL server certificates
19+
copy:
20+
src: "node_exporter.{{ item }}"
21+
dest: "/etc/prometheus/node_exporter.{{ item }}"
22+
owner: root
23+
group: root
24+
mode: 0644
25+
loop:
26+
- crt
27+
- key
28+
29+
- name: Get HTPassword
30+
delegate_to: localhost
31+
shell: "echo {{ PROMETHEUS_PASS }} | htpasswd -inBC 10 \"\" | tr -d ':\n'"
32+
register: htpassd_shell
33+
34+
- name: Set certificate to encrypt node_exporter traffic
35+
template:
36+
owner: prometheus
37+
group: prometheus
38+
mode: 0644
39+
src: web.yml.j2
40+
dest: /etc/prometheus/prometheus-authentication.yml
41+
42+
- name: Scrape with TLS encryption
43+
lineinfile:
44+
dest: /etc/default/prometheus-node-exporter
45+
state: present
46+
regexp: '^ARGS=""'
47+
line: 'ARGS="--web.config /etc/prometheus/prometheus-authentication.yml"'
48+
notify: Restart node-exporter
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Role dependencies
2+
---
3+
dependencies:
4+
- role: prometheus_target_all
5+
tags: prometheus_target_all

provision-contest/ansible/roles/prometheus_target_web/tasks/main.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
- prometheus-mysqld-exporter
1717
notify: Restart mysqld-exporter
1818

19+
- name: Scrape mysql exporter with TLS encryption
20+
lineinfile:
21+
dest: /etc/default/prometheus-mysqld-exporter
22+
state: present
23+
regexp: '^ARGS=""'
24+
line: 'ARGS="--web.config /etc/prometheus/prometheus-authentication.yml"'
25+
notify: Restart mysqld-exporter
26+
1927
# Gather PHP-FPM statistics
2028
# The exporter from this is currently not in deb sources
2129
# so we need to download this from GitHub see the README in files
@@ -68,7 +76,7 @@
6876
dest: /etc/default/prometheus-nginx-exporter
6977
state: present
7078
regexp: '^ARGS=""'
71-
line: 'ARGS="-nginx.scrape-uri=http://localhost:8787/basic_status"'
79+
line: 'ARGS="--nginx.scrape-uri=http://localhost:8787/basic_status --web.config /etc/prometheus/prometheus-authentication.yml"'
7280
notify: Restart nginx-exporter
7381

7482
- name: Create storage dir for exporter settings

0 commit comments

Comments
 (0)