Prometheus datasource : client_error: client error: 403

Prometheus datasource : client_error: client error: 403

您好,我正在尝试将内置的 OpenShift(v4.8) prometheus 数据源添加到本地 grafana 服务器。我已经使用用户名和密码提供了基本身份验证,截至目前,我还启用了 skip tls verify。我仍然收到此错误

普罗米修斯URL = https://prometheus-k8s-openshift-monitoring.apps.xxxx.xxxx.xxxx.com

这是 grafana 日志


logger=tsdb.prometheus t=2022-04-12T17:35:23.47+0530 lvl=eror msg="Instant query failed" query=1+1 err="client_error: client error: 403"
logger=context t=2022-04-12T17:35:23.47+0530 lvl=info msg="Request Completed" method=POST path=/api/ds/query status=400 remote_addr=10.100.95.27 time_ms=36 size=65 referer=https://grafana.xxxx.xxxx.com/datasources/edit/6TjZwT87k

您无法使用基本身份验证对 OpenShift prometheus 实例进行身份验证。您需要使用不记名令牌进行身份验证,例如一个来自 oc whoami -t:

curl -H "Authorization: Bearer $(oc whoami -t)" -k https://prometheus-k8s-openshift-monitoring.apps.xxxx.xxxx.xxxx.com/

或来自具有适当权限的ServiceAccount

secret=$(oc -n openshift-monitoring get sa prometheus-k8s -o jsonpath='{.secrets[1].name}')
token=$(oc -n openshift-monitoring get secret $secret -o jsonpath='{.data.token}' | base64 -d)
curl -H "Authorization: Bearer $token" -k https://prometheus-k8s-openshift-monitoring.apps.xxxx.xxxx.xxxx.com/