【问题标题】:Access Control for the Prometheus PushgatewayPrometheus Pushgateway 的访问控制
【发布时间】:2020-01-28 22:16:17
【问题描述】:

我们有一个 Prometheus Pushgateway 正在运行并监听从我们的 AWS Lambda 函数推送的指标。但是,公众可以访问 Pushgateway 的 URL,这可能会带来一些安全问题。我们想知道是否有任何方法可以为 Pushgateway 添加一层保护,使其无法公开访问?

我发现这个 Github 线程可以回答这个问题: https://github.com/prometheus/pushgateway/issues/281

建议在pushgateway前面设置一个反向代理。但是,我仍然对这实际上如何工作感到困惑?我们目前正在使用 Kubernetes 来部署 Prometheus。

【问题讨论】:

    标签: security networking prometheus prometheus-pushgateway


    【解决方案1】:

    您可以使用 TLS 机密作为入口规则,在入口控制器中包含身份验证。 这是一个示例,展示了如何为您的入口生成基本身份验证:

    https://kubernetes.github.io/ingress-nginx/examples/auth/basic/

    另外,不要忘记在您的客户端中包含 Python 处理程序函数以设置此处指出的 auth 标头:

    https://github.com/prometheus/client_python#handlers-for-authentication

    【讨论】:

    • 感谢您的解决方案,我按照文档进行操作,效果很好!
    【解决方案2】:

    这里的建议是使用 AWS 内部负载均衡器创建 Pushgateway Internal 的 URL,创建一个 AWS Private Hosted Zone 将您的 VPC 附加到该区域,然后下一步将在同一个中部署 lambda专有网络。

    这应该可以解决安全问题。

    【讨论】:

    • 感谢您的回答,这是一个很好的解决方案,但我个人更熟悉入口控制器配置。但是,我仍然感谢您的努力。点赞!
    【解决方案3】:

    你是对的,你需要反向代理。我也遇到了同样的问题,所以你的 prometheus/pushgateway 前面需要 nginx。

    首先,使用this article 安装 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" - 所以它只会暴露给 localhost。

    通过 nginx pushgateway 可以在 3001 端口访问,9091 端口将不公开。需要基本身份验证才能访问或推送指标。

    关于如何使用 Postman 进行测试,您可以找到 here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多