通常情况下,MetricStore的读写操作需要配置访问密钥(AK)或安全令牌(STS)进行鉴权。本文主要介绍免除这些鉴权配置的方法,让用户无需鉴权即可通过Prometheus接口对MetricStore进行数据上报或者查询。
实现背景
MetricStore的Prometheus接口支持通过Project Policy实现免密读写配置。该配置作用于 Project 级别,操作时需注意可能影响其他 Store 的访问行为。建议先使用GetProjectPolicy接口获取现有策略,并在其基础上进行修改。
文档中提及的接口如下:
权限策略通用结构
{
"Version": "1",
"Statement": [
{
"Effect": "<Effect>",
"Action": "<Action>",
"Resource": "<Resource>",
"Condition": {
"<Condition_operator>": {
"<Condition_key>": [
"<Condition_value>"
]
}
}
}
]
}
- Effect:权限策略效果。取值:Allow(允许)、Deny(拒绝)。
- Action:授予允许或拒绝权限的具体操作。具体信息,请参见操作(Action)。
- Resource:受操作影响的具体对象,您可以使用资源ARN来描述指定资源。具体信息,请参见资源(Resource)。
- Condition:指授权生效的条件。可选字段。具体信息,请参见条件(Condition)。
- Condition_operator:条件运算符,不同类型的条件对应不同的条件运算符。具体信息,请参见权限策略基本元素。
- Condition_key:条件关键字。
- Condition_value:条件关键字对应的值。
MetricStore接口权限策略
安全性建议
资源(Resource)优先精确到
MetricStore
级别,避免使用Project
通配符*
。始终通过条件(Condition)策略限制免密访问的来源(如 VPC 或 IP 段),减少暴露范围。
灵活配置
可同时组合多个条件(Condition)(如同时限制 VPC 和 IP)。
可添加多个资源(Resource)或条件(Condition)来覆盖更多场景。
操作(Action)
权限类型 | 对应Action |
Prometheus 协议写入权限 | log:RemoteWritePrometheus |
Prometheus 协议查询权限 | log:QueryPrometheusMetrics |
资源(Resource)
资源类型 | ARN格式 | 说明 |
指定 Project |
| 通配符 |
指定 MetricStore |
| 建议优先使用该级别以提高安全性。 |
条件(Condition)
条件类型 | Key 值 | 示例值 | 描述 |
指定 VPC |
|
| 限制仅允许特定 VPC 的流量免密访问。 |
指定 IP 段 |
|
| 限制仅允许特定 IP 地址或 IP 段的流量免密访问。 |
配置参考
参考1:指定 VPC 的完整策略
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": ["log:RemoteWritePrometheus", "log:QueryPrometheusMetrics"],
"Resource": ["acs:log:*:*:project/{projectName}/logstore/{metricstore}"],
"Condition": {
"StringEquals": {
"acs:SourceVpc": ["vpc-xxx1", "vpc-xxx2"]
}
}
}
]
}
参考2:指定IP的完整策略
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": ["log:RemoteWritePrometheus", "log:QueryPrometheusMetrics"],
"Resource": ["acs:log:*:*:project/{projectName}/logstore/{metricstore}"],
"Condition": {
"StringEquals": {
"acs:IpAddress": ["xx.xx.xx.xx", "xx.xx.xx.0/24"]
}
}
}
]
}
配置示例
示例1:对指定 MetricStore 以及指定 VPC 开启免密写入功能
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"log:RemoteWritePrometheus"
],
"Principal": ["*"],
"Resource": "acs:log:*:*:project/test-project/logstore/test-metricstore",
"Condition": {
"StringEquals": {
"acs:SourceVpc": [
"vpc-xxx"
]
}
}
}
]
}
示例2:对指定 Project 下的所有MetricStore开启免密读写能力
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"log:RemoteWritePrometheus",
"log:QueryPrometheusMetrics"
],
"Principal": ["*"],
"Resource": "acs:log:*:*:project/test-project/*"
}
]
}
示例3:对指定MetricStore开启免密读写能力
{
"Version": "1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"log:RemoteWritePrometheus",
"log:QueryPrometheusMetrics"
],
"Principal": ["*"],
"Resource": "acs:log:*:*:project/test-project/logstore/test-metricstore"
}
]
}