有没有办法将 Prometheus 配置为使用 Google(服务)帐户来验证抓取目标
Is there a way to configure Prometheus to use a Google (Service) Account to authenticate scrape targets
Update Thanks to @levi-harrison, I wrote a solution gcp-oidc-token-proxy
我想抓取需要 (Google) 身份验证的云 运行 服务,但此解决方案通常适用于受 Google 授权身份保护的任何端点。
等价地,我可以:
curl \
--request GET
--header "Authorization: Bearer $(gcloud auth print-identity-token)" \
https://my-server-blahblah-wl.a.run.app/metrics
Prometheus 仅支持 (?) TLS 或 OAuth2。
oauth2 配置需要客户端 ID 和密码。
使用 Google 服务帐户(配置了适当的 IAM 权限),然后使用 Google 的 OAuth2 for server-server apps,我可以获得 Prometheus 配置 client_id
(虽然我不清楚这是服务帐户的密钥 client_id
还是 client_email
)但我不确定 Prometheus 配置 client_secret
(或 client_secret_file
)使用什么和token_url
.
我已经尝试使用 client_secret_file
的服务帐户密钥。
我尝试使用 oauth2l
生成 JWT 并将其用于 client_secret
:
oauth2l fetch \
--type=jwt \
--scope cloud-platform \
--credentials ${PWD}/${KEY}.json
我试过使用 gcloud auth application-default
因为 ${HOME}/.config/gcloud/application_default_credentials.json
因为这些凭据包含 client_id
和 client_secret
对于application_default_credentials.json
,我使用了https://oauth2.googleapis.com/token
对于 JWT,我使用了 https://sts.googleapis.com/v1beta/token
但是,无论如何,我得到了 400 分。
我尝试将 https://securetoken.googleapis.com/v1/token?key=${API_KEY}
与 JWT 一起使用并使用 INVALID_GRANT_TYPE
获得 400,因为我无法更改请求正文以包含 grant_type=authorization-code
每个 Token Service
为了完整性,prometheus.yml
:
global:
...
scrape_configs:
- job_name: "foo"
scheme: https
oauth2:
# From Service Account key
client_id: ""
# ID token (JWT) from `oauth2l`
client_secret: ""
scopes:
- "https://www.googleapis.com/auth/cloud-platform"
token_url: "https://securetoken.googleapis.com/v1/token?key=${API_KEY}"
static_configs:
- targets:
- "my-server-blahblah-wl.a.run.app"
Prometheus OAuth 2.0认证特别支持Client Credentials grant type, which uses the client_id
and client_secret
as credentials to request a token from the token_url
. The Google's OAuth 2.0 guide seems to describe using the JWT Bearer授权类型,Prometheus不支持
您可能想查看 stackdriver_exporter, and also this thread。
Update Thanks to @levi-harrison, I wrote a solution gcp-oidc-token-proxy
我想抓取需要 (Google) 身份验证的云 运行 服务,但此解决方案通常适用于受 Google 授权身份保护的任何端点。
等价地,我可以:
curl \
--request GET
--header "Authorization: Bearer $(gcloud auth print-identity-token)" \
https://my-server-blahblah-wl.a.run.app/metrics
Prometheus 仅支持 (?) TLS 或 OAuth2。
oauth2 配置需要客户端 ID 和密码。
使用 Google 服务帐户(配置了适当的 IAM 权限),然后使用 Google 的 OAuth2 for server-server apps,我可以获得 Prometheus 配置 client_id
(虽然我不清楚这是服务帐户的密钥 client_id
还是 client_email
)但我不确定 Prometheus 配置 client_secret
(或 client_secret_file
)使用什么和token_url
.
我已经尝试使用 client_secret_file
的服务帐户密钥。
我尝试使用 oauth2l
生成 JWT 并将其用于 client_secret
:
oauth2l fetch \
--type=jwt \
--scope cloud-platform \
--credentials ${PWD}/${KEY}.json
我试过使用 gcloud auth application-default
因为 ${HOME}/.config/gcloud/application_default_credentials.json
因为这些凭据包含 client_id
和 client_secret
对于application_default_credentials.json
,我使用了https://oauth2.googleapis.com/token
对于 JWT,我使用了 https://sts.googleapis.com/v1beta/token
但是,无论如何,我得到了 400 分。
我尝试将 https://securetoken.googleapis.com/v1/token?key=${API_KEY}
与 JWT 一起使用并使用 INVALID_GRANT_TYPE
获得 400,因为我无法更改请求正文以包含 grant_type=authorization-code
每个 Token Service
为了完整性,prometheus.yml
:
global:
...
scrape_configs:
- job_name: "foo"
scheme: https
oauth2:
# From Service Account key
client_id: ""
# ID token (JWT) from `oauth2l`
client_secret: ""
scopes:
- "https://www.googleapis.com/auth/cloud-platform"
token_url: "https://securetoken.googleapis.com/v1/token?key=${API_KEY}"
static_configs:
- targets:
- "my-server-blahblah-wl.a.run.app"
Prometheus OAuth 2.0认证特别支持Client Credentials grant type, which uses the client_id
and client_secret
as credentials to request a token from the token_url
. The Google's OAuth 2.0 guide seems to describe using the JWT Bearer授权类型,Prometheus不支持
您可能想查看 stackdriver_exporter, and also this thread。