[英]Access Control for the Prometheus Pushgateway
我們有一個 Prometheus Pushgateway 正在運行並監聽來自我們的 AWS Lambda function 的指標推送。但是,公眾可以訪問到 Pushgateway 的 URL,這可能會帶來一些安全問題。 我們想知道是否有任何方法可以為 Pushgateway 添加一層保護,使其不可公開訪問?
我發現這個 Github 線程可以回答這個問題: https://github.com/prometheus/pushgateway/issues/281
它建議在 pushgateway 前面設置一個反向代理。 但是,我仍然對這實際上如何工作感到困惑? 我們目前正在使用 Kube.netes 來部署 Prometheus。
這里的建議是使用 AWS 內部負載均衡器將 Pushgateway 的 URL 設置為內部,創建一個 AWS 私有托管區域,將您的 VPC 附加到該區域,然后下一步是在同一 VPC 中部署 lambda。
這應該可以解決安全問題。
您可以通過使用 TLS 機密作為入口規則在入口控制器中包含身份驗證。 這是一個示例,展示了如何為您的入口生成基本身份驗證:
https://kubernetes.github.io/ingress-nginx/examples/auth/basic/
另外,不要忘記在您的客戶端中包含 Python 處理程序函數以設置 auth 標頭,如下所示:
https://github.com/prometheus/client_python#handlers-for-authentication
沒錯,這里需要反向代理。 我也遇到了同樣的問題,所以你的 prometheus/pushgateway 前面需要 nginx。
首先,使用本文安裝 nginx(如果您已經配置了 prometheus,則可以從步驟 8 — 保護 Prometheus 開始):
我的 nginx 配置:
events { }
http {
upstream prometheus {
server 127.0.0.1:9090;
keepalive 64;
}
upstream pushgateway {
server 127.0.0.1:9091;
keepalive 64;
}
server {
root /var/www/example;
listen 0.0.0.0:80;
server_name __;
location / {
auth_basic "Prometheus server authentication2";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://prometheus;
}
}
server {
root /var/www/example;
listen 0.0.0.0:3001;
server_name __;
location / {
auth_basic "Pushgateway server authentication";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://pushgateway;
}
}
}
我的 pushgateway.service 文件:
[Unit]
Description=Pushgateway
Wants=network-online.target
After=network-online.target
[Service]
User=pushgateway
Group=pushgateway
Type=simple
ExecStart=/usr/local/bin/pushgateway --web.listen-address="127.0.0.1:9091" --web.telemetry-path="/metrics" --persistence.file="/tmp/metric.store" --persistence.interval=5m --log.level="info" --log.format="logger:stdout?json=true"
[Install]
WantedBy=multi-user.target
重要的是設置:--web.listen-address="127.0.0.1:9091",而不是 ":9091" - 所以它只會暴露給本地主機。
通過 nginx 推送網關可以訪問端口 3001,端口 9091 將不公開。 需要基本身份驗證才能訪問或推送指標。
關於如何使用 Postman 進行測試,您可以在此處找到
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.