如何为普罗米修斯作业添加不记名令牌

问题描述 投票:0回答:1

我已经开始为我的微服务开发 Prometheus。我最初能够实现它。现在,是时候将执行器端点推送到 spring security 下了。添加安全执行器后,需要来自 Prometheus 的不记名令牌。那么,如何在 Prometheus 作业中配置用户名和密码,以便 Prometheus 从登录中获取不记名令牌并将其添加为所有请求标头中的“授权”。

我使用下面的命令在 docker 容器中运行 Prometheus


 1. $ docker run --name prometheus -p 9090:9090 -v prometheus.yml:/etc/prometheus/prometheus.yml -d prom/prometheus
 2. $ docker run --name grafana -d -p 3000:3000 grafana/grafana

以下是prometheus.yml文件


# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:

  # The job name is added as a label `job=<job_name>` to any time series scraped from this config.
  - job_name: 'prometheus'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
      - targets: ['127.0.0.1:9090']

  - job_name: 'NL-APPLICATION'
    metrics_path: '/actuator/prometheus'
    scrape_interval: 5s
    scheme: http
    static_configs:
      - targets: ['172.17.0.1:8085']

  - job_name: 'NL-ADMIN-API'
    metrics_path: '/actuator/prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['172.17.0.1:8083']

如何指示 Prometheus 执行以下操作

  1. API 调用“/login”使用用户名和密码获取不记名令牌
  2. 将承载令牌添加为“授权”,作为所有执行器 API 调用中的标头
spring-boot docker spring-security prometheus spring-boot-actuator
1个回答
3
投票

您可以指定包含 bearer_token 的文件的路径或将令牌直接添加到配置中

- job_name: 'test'
  metrics_path: "/metrics"
  scheme: "http"
  bearer_token_file: /var/run/secrets/secret    OR   bearer_token: token_here
  static_configs:
    - targets: ['host.com']
© www.soinside.com 2019 - 2024. All rights reserved.