Prometheus 数据安全之 Basic 认证

咱们都知道 Promethetheus 是不带认证和数据加密的,但不少时候咱们又想在公网中直接使用它的管理界面,若是不作任何处理,它将存在严重的数据泄漏安全问题。nginx

下面我将介绍如何经过 nginx 的 basic 认证来解决这一问题。apache

原始 Prometheus 代理配置

server {
    listen 80;
    server_name example.coom;

    location / {
        proxy_pass http://localhost:9090/;
    }
}

说明:使用 nignx 的 proxy_pass 代理咱们 Prometheus 服务。安全

使用 htpasswd 生成认证密钥对ide

htpasswd 属于 apache2-utils 包,下面我将演示在 Ubuntu 上的安装和配置过程。post

Step1: 安装 apache2-utils加密

$ sudo apt-get install apache2-utils

Step2: 生成认证密钥代理

$ htpasswd -c /etc/nginx/.htpasswd monitor

New password:
Re-type new password:
Adding password for user monitor

说明:monitor 能够修改成任意用户名。code

Step3: 使用 cat 查看生成内容:server

$ cat /etc/nginx/.htpasswd

monitor:$apr1$EEV......

修改 nginx 配置

server {
    listen 80;
    server_name example.coom;

    location / {
        auth_basic "Prometheus";
        auth_basic_user_file "/etc/nginx/.htpasswd";

        proxy_pass http://localhost:9090/;
    }
}

保存配置,重启 nignx 服务后,你访问域名 example.com 将出现 basic 认证的界面:
Prometheus 数据安全之 Basic 认证blog

输入正确的帐号密码,你将进入 Prometheus 管理界面。

写在最后

咱们能够使用 nginx 的 basic auth 的方式来解决 Prometheus 认证的问题,此方法一样适用 Alertmanger 或者 NodeExporter。

从如今起,不要再让你的监控数据在公网中裸奔,赶快去修改配置吧。

做者:宋佳洋
本文连接:http://www.songjiayang.com/posts/prometheus-shu-ju-an-quan-zhi-basic-ren-zhengk8s课程、Golang 课程火热招生资料找WeChat:17812796384

相关文章
相关标签/搜索