Skip to content

Commit 80c2735

Browse files
committed
Add basic authentication on prometheus endpoint in infra
1 parent 004639a commit 80c2735

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

mithril-infra/assets/docker/docker-compose-monitoring.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ services:
1818
- 'traefik.http.routers.prometheus.rule=Host(`${PROMETHEUS_HOST}`)'
1919
- 'traefik.http.routers.prometheus.tls=true'
2020
- 'traefik.http.routers.prometheus.tls.certresolver=lets-encrypt'
21+
- "traefik.http.routers.prometheus.middlewares=test-auth"
22+
- "traefik.http.middlewares.test-auth.basicauth.users=${AUTH_USER_PASSWORD}"
2123

2224
promtail:
2325
image: grafana/promtail:1.4.1

mithril-infra/main.dns.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ locals {
4242
format("https://%s", "mithril-signer-${key}.${trimsuffix(google_dns_managed_zone.mithril-api-zone.dns_name, ".")}")
4343
]
4444
prometheus_host = trimsuffix(google_dns_record_set.prometheus-endpoint.name, ".")
45-
prometheus_endpoint_url = format("https://%s", "prometheus.${trimsuffix(google_dns_managed_zone.mithril-api-zone.dns_name, ".")}")
45+
prometheus_endpoint_url = format("https://%s%s", local.prometheus_credentials, local.prometheus_host)
4646

4747
}

mithril-infra/mithril.monitoring.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ resource "null_resource" "mithril_monitoring" {
55
]
66

77
triggers = {
8-
image_id = var.mithril_image_id,
9-
vm_instance = google_compute_instance.vm_instance.id
8+
image_id = var.mithril_image_id,
9+
vm_instance = google_compute_instance.vm_instance.id,
10+
prometheus_auth_username = var.prometheus_auth_username,
11+
prometheus_auth_password = var.prometheus_auth_password
1012
}
1113

1214
connection {
@@ -19,6 +21,7 @@ resource "null_resource" "mithril_monitoring" {
1921
provisioner "remote-exec" {
2022
inline = [
2123
"export PROMETHEUS_HOST=${local.prometheus_host}",
24+
"export AUTH_USER_PASSWORD=$(htpasswd -nb ${var.prometheus_auth_username} ${var.prometheus_auth_password})",
2225
"docker-compose -f /home/curry/docker/docker-compose-monitoring.yaml --profile all up -d",
2326
]
2427
}

mithril-infra/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,22 @@ variable "mithril_aggregator_auth_password" {
172172
default = ""
173173
}
174174

175+
variable "prometheus_auth_username" {
176+
type = string
177+
description = "The username for authentication on prometheus"
178+
default = ""
179+
}
180+
181+
variable "prometheus_auth_password" {
182+
type = string
183+
description = "The password for authentication on prometheus"
184+
default = ""
185+
}
186+
175187
locals {
176188
mithril_aggregator_type = var.mithril_aggregator_auth_username == "" ? "noauth" : "auth"
177189
mithril_aggregator_credentials = var.mithril_aggregator_auth_username == "" ? "" : format("%s:%s@", var.mithril_aggregator_auth_username, var.mithril_aggregator_auth_password)
190+
prometheus_credentials = var.prometheus_auth_username == "" ? "" : format("%s:%s@", var.prometheus_auth_username, var.prometheus_auth_password)
178191
}
179192

180193
variable "mithril_genesis_verification_key_url" {

0 commit comments

Comments
 (0)