创建 ACL
/v1/acls创建一组可供网站引用的 ACL 访问控制规则。接口会校验当前用户可创建的 ACL 数量、同一用户下的名称唯一性、默认动作以及每条匹配规则;规则数量上限由系统配置 acl-max-limit 决定。普通用户只能为自己创建 ACL;管理员可通过 uid 指定所属用户。创建成功后 ACL 会保存为独立配置并返回新 ACL ID。
身份认证
access-token
api-key + api-secret
认证定义
{
"AccessToken": {
"type": "apiKey",
"in": "header",
"name": "access-token",
"description": "通过登录接口获得的短期访问令牌。"
},
"ApiKey": {
"type": "apiKey",
"in": "header",
"name": "api-key",
"description": "API Key;必须和 api-secret 同时发送。"
},
"ApiSecret": {
"type": "apiKey",
"in": "header",
"name": "api-secret",
"description": "API Secret;必须和 api-key 同时发送。"
}
}请求参数
未定义路径、查询或请求头参数。
请求体 · 必填
application/json
object
| 字段 | 类型 | 必填 | 说明与约束 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name | string | 必填 | ACL 名称;不能为空,且在所属用户的 ACL 中必须唯一。 约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||
des | string | 可选 | ACL 的备注说明;省略时保存为空字符串。 约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||
default_action | string | 必填 | 所有 ACL 规则均未匹配时执行的默认动作: 约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||
reject_code | string | 可选 | 默认动作拒绝请求时的响应方式;403 表示直接拒绝,302 表示重定向。 约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||
redirect_url | string | 可选 |
约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||
data | array <object> | 必填 | 按顺序执行的 ACL 规则数组;条目数不得超过系统配置的 约束 / 默认值 / 示例展开字段结构按顺序执行的 ACL 规则数组;条目数不得超过系统配置的 数组元素 · object
| ||||||||||||||||||||||||||||||||||||
enable | integer | 可选 | 新 ACL 的启用状态:1 表示启用,0 表示禁用;省略时启用。 约束 / 默认值 / 示例 | ||||||||||||||||||||||||||||||||||||
uid | integer (int64) | 可选 | 新 ACL 的所属用户 ID,仅管理员可传;普通用户传入时返回管理员权限错误。 约束 / 默认值 / 示例 |
完整 Schema
{
"type": "object",
"required": [
"name",
"default_action",
"data"
],
"properties": {
"name": {
"type": "string",
"minLength": 1,
"description": "ACL 名称;不能为空,且在所属用户的 ACL 中必须唯一。"
},
"des": {
"type": "string",
"default": "",
"description": "ACL 的备注说明;省略时保存为空字符串。"
},
"default_action": {
"type": "string",
"enum": [
"reject",
"allow"
],
"description": "所有 ACL 规则均未匹配时执行的默认动作:`reject` 拒绝请求,`allow` 放行请求。"
},
"reject_code": {
"type": "string",
"enum": [
"403",
"302"
],
"default": "403",
"description": "默认动作拒绝请求时的响应方式;403 表示直接拒绝,302 表示重定向。"
},
"redirect_url": {
"type": "string",
"default": "",
"description": "`reject_code` 为 302 时必填的重定向地址;使用 403 时可省略。"
},
"data": {
"type": "array",
"minItems": 1,
"description": "按顺序执行的 ACL 规则数组;条目数不得超过系统配置的 `acl-max-limit`。",
"items": {
"type": "object",
"required": [
"acl_action",
"acl_matcher"
],
"properties": {
"acl_action": {
"type": "string",
"enum": [
"reject",
"allow"
],
"description": "该条规则匹配后执行的动作:`reject` 拒绝请求,`allow` 放行请求。"
},
"acl_code": {
"type": "string",
"enum": [
"403",
"302"
],
"default": "403",
"description": "该条规则执行 `reject` 时使用的响应方式;省略时为 403。"
},
"acl_url": {
"type": "string",
"default": "",
"description": "该条规则的 `acl_code` 为 302 时必填的重定向地址。"
},
"acl_matcher": {
"type": "array",
"description": "该条 ACL 规则的匹配条件;每个条件由匹配项、操作符和值组成。",
"items": {
"type": "object",
"required": [
"item",
"op"
],
"properties": {
"item": {
"type": "string",
"enum": [
"count404",
"uniq_ua",
"header",
"ip",
"host",
"accept_language",
"user_agent",
"referer",
"uri",
"req_uri",
"req_method",
"country_iso_code",
"asnumber",
"province",
"city",
"isp",
"protocol",
"tls_fp",
"uniq_tls_fp",
"server_port"
],
"description": "要检查的请求或客户端属性,例如 `ip`、`host`、`uri`、国家代码或 TLS 指纹。"
},
"op": {
"type": "string",
"enum": [
">",
"=",
"!=",
"!contain",
"contain",
"prefix",
"suffix",
"regex",
"!regex",
"exists",
"!exists",
"ip_range",
"!ip_range"
],
"description": "匹配操作符;`ip_range` 和 `!ip_range` 用于判断 IP 是否属于指定 CIDR 范围。"
},
"value": {
"type": "string",
"default": "",
"description": "参与匹配的值。服务端会移除空行并转为小写;IP 范围操作符使用空白分隔一个或多个 CIDR。"
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
}
},
"enable": {
"type": "integer",
"enum": [
0,
1
],
"default": 1,
"description": "新 ACL 的启用状态:1 表示启用,0 表示禁用;省略时启用。"
},
"uid": {
"type": "integer",
"format": "int64",
"minimum": 1,
"description": "新 ACL 的所属用户 ID,仅管理员可传;普通用户传入时返回管理员权限错误。"
}
},
"additionalProperties": false
}示例
{
"name": "仅允许指定网段",
"des": "允许文档示例网段访问",
"default_action": "reject",
"reject_code": "403",
"data": [
{
"acl_action": "allow",
"acl_matcher": [
{
"item": "ip",
"op": "ip_range",
"value": "192.0.2.0/24"
}
]
}
],
"enable": 1
}请求体示例
{
"name": "string",
"des": "",
"default_action": "reject",
"reject_code": "403",
"redirect_url": "",
"data": [
{
"acl_action": "reject",
"acl_code": "403",
"acl_url": "",
"acl_matcher": [
{
"item": "count404",
"op": ">",
"value": ""
}
]
}
],
"enable": 1,
"uid": 0
}响应
HTTP 200
请求始终通过 HTTP 200 返回。创建成功时返回新 ACL ID;配额、名称、默认动作、重定向配置或嵌套匹配规则不合法时,通过字符串 code 和 msg 返回具体业务错误。
application/json
oneOf
oneOf · 1 · object
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
code | integer | 必填 | 成功状态码,ACL 创建成功时固定为 0。 约束 / 默认值 / 示例 |
msg | string | 必填 | ACL 创建成功时返回的确认消息。 约束 / 默认值 / 示例 |
data | integer (int64) | 必填 | 新创建 ACL 的唯一 ID。 约束 / 默认值 / 示例 |
oneOf · 2 · object
| 字段 | 类型 | 必填 | 说明与约束 |
|---|---|---|---|
code | string | 必填 | 业务错误码。常见值包括配额超限 |
msg | string | 必填 | 与业务错误码对应的中文校验失败原因。 |
data | string | 必填 | 业务错误时固定为空字符串。 约束 / 默认值 / 示例 |
完整 Schema
{
"oneOf": [
{
"type": "object",
"required": [
"code",
"msg",
"data"
],
"properties": {
"code": {
"type": "integer",
"enum": [
0
],
"description": "成功状态码,ACL 创建成功时固定为 0。"
},
"msg": {
"type": "string",
"enum": [
"ACL添加成功"
],
"description": "ACL 创建成功时返回的确认消息。"
},
"data": {
"type": "integer",
"format": "int64",
"minimum": 1,
"description": "新创建 ACL 的唯一 ID。"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"code",
"msg",
"data"
],
"properties": {
"code": {
"type": "string",
"description": "业务错误码。常见值包括配额超限 `acl-8`、名称错误 `acl-9/acl-11/acl-12`、默认动作错误 `acl-14/acl-15/acl-16`、规则错误 `acl-17` 至 `acl-25`、缺少规则 `acl-26`、启用状态错误 `acl-27/acl-28`、重定向错误 `acl-35` 至 `acl-40` 以及管理员权限错误 `acl-43`。"
},
"msg": {
"type": "string",
"description": "与业务错误码对应的中文校验失败原因。"
},
"data": {
"type": "string",
"enum": [
""
],
"description": "业务错误时固定为空字符串。"
}
},
"additionalProperties": false
}
]
}示例
{
"code": 0,
"msg": "ACL添加成功",
"data": 1
}cURL 示例
根据文档生成;请替换主控地址、路径参数和凭证,并按上表补充查询参数。
curl --request POST \
"https://master.example.invalid/v1/acls" \
--header "access-token: YOUR_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{"name": "string", "des": "", "default_action": "reject", "reject_code": "403", "redirect_url": "", "data": [{"acl_action": "reject", "acl_code": "403", "acl_url": "", "acl_matcher": [{"item": "count404", "op": ">", "value": ""}]}], "enable": 1, "uid": 0}'