Prometheus 登录用户认证

发布时间:2024-01-19 13:36:11

前言

prometheus默认是没有用户密码登录认证的,对于部分环境可能会存在受攻击风险,以下实现安全用户密码登录。

Prometheus于2.24版本(包括2.24)之后提供Basic Auth功能进行加密访问,在浏览器登录UI的时候需要输入用户密码,访问Prometheus api的时候也需要加上用户密码。

对密码进行哈希处理

yum install -y python pip
pip install bcrypt

cat <<'EOF'>>/prometheus/config/prometheus_passwd.py 
import getpass
import bcrypt

password = getpass.getpass("password: ")
hashed_password = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt())
print(hashed_password.decode())
EOF

执行脚本,生成加密密码?

python /prometheus/config/prometheus_passwd.py

docker-compose 更改

  • prometheus用户密码admin/CIASM@123
  • 需要自定义的密码python /prometheus/config/prometheus_passwd.py生成加密的即可
  • 其它yml用处及更多参考
cat <<'EOF'>>/prometheus/config/basic_auth.yaml
basic_auth_users:
  admin: $2b$12$S.cAXMn0aP/LoTPgUhhcoee3fifsHUHN9GCuRJbdKQ5lOByUAOGRq
EOF

cat <<'EOF'>>/prometheus/config/docker-compose.yml
version: '3'
services:
  prometheus:
    image: prom/prometheus:latest
    hostname: prometheus
    restart: always
    ports:
      - "9090:9090"
    volumes:
      - ./data:/data
      - ./config/prometheus.yml:/etc/prometheus/prometheus.yml
      - ./config/node_down.yml:/etc/prometheus/node_down.yml
      - ./config/vmware_exporter.yml:/etc/prometheus/vmware_exporter.yml
      - ./config/basic_auth.yaml:/etc/prometheus/basic_auth.yaml
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--web.enable-admin-api'
      - '--web.enable-lifecycle'
      - '--web.config.file=/etc/prometheus/basic_auth.yaml'
EOF

重新启动生效?

docker-compose up -d

?登录显示需要用户名密码

grafana 连接认证的prometheus

文章来源:https://blog.csdn.net/hanzheng260561728/article/details/135690445
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。