1. 接口描述
接口请求域名: cfw.tencentcloudapi.com 。
新增一条或多条 VPC 边界访问控制规则。
默认接口请求频率限制:20次/秒。
2. 输入参数
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| Action | 是 | String | 公共参数,本接口取值:AddVpcAcRule。 |
| Version | 是 | String | 公共参数,本接口取值:2019-09-04。 |
| Region | 否 | String | 公共参数,本接口不需要传递此参数。 |
| Rules.N | 是 | Array of VpcRuleItem | 待添加的 VPC边界规则列表,至少包含一条,可包含不同 IpVersion。EdgeId 调用 DescribeVpcAclEdgeRange,传 FromList=switchs,并使用 EdgeRanges[].EdgeId;FromList=rules 只返回已有规则使用过的范围,不用于发现可新增范围。FwGroupId 调用 DescribeFwGroupIdNames,IpVersion 使用与目标规则相同的 JSON 整数 0 或 1,并使用 Data[].FwGroupId,不要使用 FwGroupName。地址模板调用 DescribeAddressTemplateList,请求用 TemplateType=1 或 5 过滤,并确认返回项 Data[].Type 为 1 或 5;将 Data[].Uuid(mb_ 前缀)写入对应 Content,不要使用 Data[].TemplateId(ip-/dm- 前缀)。协议端口模板请求用 TemplateType=6 过滤,并将 Data[].TemplateId(pp- 前缀)写入 ParamTemplateId。资产实例调用 DescribeCfwAssets,解析返回结果后使用 assets[].instance_id;资产分组调用 DescribeResourceGroupNew,传 QueryType=resource、GroupId="0"、ShowType=all,解析返回结果后使用 GroupId;资源标签传 QueryType=tag,跳过“全部资产”根节点,以一级节点 GroupName 为 Key、所选二级子节点 GroupName 为 Value 构造 JSON,不要写入 GroupId。batch_import_cover 的覆盖范围仅由首条规则的 IpVersion 决定。 |
| CfwAiAgentOperationSource | 否 | String | AI操作来源 枚举值:
示例值:console |
| From | 否 | String | 添加方式。省略或为空表示普通新增;insert_rule 表示按 OrderIndex 插入;batch_import 表示非覆盖批量导入;batch_import_cover 表示覆盖导入,会删除首条规则 IpVersion 对应的现有可操作规则后再按 Rules 顺序添加,添加失败时已删除的规则不会恢复,风险极高。仅支持上述取值。 示例值:batch_import |
3. 输出参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| RuleUuids | Array of Integer | 新增规则的 ID 列表,顺序与 Rules 一致。 示例值:[8888, 8889] |
| RequestId | String | 唯一请求 ID,由服务端生成,每次请求都会返回(若请求因其他原因未能抵达服务端,则该次请求不会获得 RequestId)。定位问题时需要提供该次请求的 RequestId。 |
4. 示例
示例1 普通新增 IPv4 VPC 规则
使用 RFC 5737 文档地址新增一条启用的 IPv4 TCP 规则;省略 From 表示普通新增。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddVpcAcRule
<公共请求参数>
{
"Rules": [
{
"SourceContent": "192.0.2.10",
"SourceType": "net",
"DestContent": "198.51.100.20",
"DestType": "net",
"Protocol": "TCP",
"RuleAction": "accept",
"Port": "443",
"Description": "允许文档网段 HTTPS 访问",
"OrderIndex": -1,
"Enable": "true",
"EdgeId": "ALL",
"IpVersion": 0
}
]
}
输出示例
{
"Response": {
"RuleUuids": [
10001
],
"RequestId": "00000000-0000-4000-8000-000000000001"
}
}
示例2 普通新增 IPv6 VPC 规则
使用 RFC 3849 文档地址新增一条启用的 IPv6 UDP 规则;省略 From 表示普通新增。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddVpcAcRule
<公共请求参数>
{
"Rules": [
{
"SourceContent": "2001:db8:1::10",
"SourceType": "net",
"DestContent": "2001:db8:2::20",
"DestType": "net",
"Protocol": "UDP",
"RuleAction": "log",
"Port": "53",
"Description": "观察文档网段 DNS 访问",
"OrderIndex": -1,
"Enable": "true",
"EdgeId": "ALL",
"IpVersion": 1
}
]
}
输出示例
{
"Response": {
"RuleUuids": [
10002
],
"RequestId": "00000000-0000-4000-8000-000000000002"
}
}
示例3 普通新增 VPC 域名访问规则
新增一条 IPv4 VPC 域名观察规则;域名目的使用应用层协议,省略 From 表示普通新增。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddVpcAcRule
<公共请求参数>
{
"Rules": [
{
"SourceContent": "192.0.2.0/24",
"SourceType": "net",
"DestContent": "example.com",
"DestType": "domain",
"Protocol": "HTTP",
"RuleAction": "log",
"Port": "80",
"Description": "观察 VPC 到文档域名的 HTTP 访问",
"OrderIndex": -1,
"Enable": "true",
"EdgeId": "ALL",
"IpVersion": 0
}
]
}
输出示例
{
"Response": {
"RuleUuids": [
10003
],
"RequestId": "00000000-0000-4000-8000-000000000003"
}
}
示例4 在指定 VPC 边插入规则
使用 insert_rule 在指定 VPC 边插入一条禁用规则。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddVpcAcRule
<公共请求参数>
{
"From": "insert_rule",
"Rules": [
{
"SourceContent": "192.0.2.10",
"SourceType": "net",
"DestContent": "198.51.100.10",
"DestType": "net",
"Protocol": "TCP",
"RuleAction": "log",
"Port": "443",
"Description": "指定 VPC 边插入规则",
"OrderIndex": 2,
"Enable": "false",
"EdgeId": "cfws-b29ca53311",
"FwGroupId": "ALL",
"IpVersion": 0
}
]
}
输出示例
{
"Response": {
"RuleUuids": [
10004
],
"RequestId": "00000000-0000-4000-8000-000000000004"
}
}
示例5 在指定防火墙组批量导入 VPC 规则
使用非覆盖的 batch_import 向指定防火墙组新增两条禁用规则。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddVpcAcRule
<公共请求参数>
{
"From": "batch_import",
"Rules": [
{
"SourceContent": "192.0.2.51",
"SourceType": "net",
"DestContent": "198.51.100.51",
"DestType": "net",
"Protocol": "TCP",
"RuleAction": "log",
"Port": "443",
"Description": "批量 VPC 规则一",
"OrderIndex": -1,
"Enable": "false",
"EdgeId": "ALL",
"FwGroupId": "cfwg-8f6785ee",
"IpVersion": 0
},
{
"SourceContent": "192.0.2.52",
"SourceType": "net",
"DestContent": "198.51.100.52",
"DestType": "net",
"Protocol": "UDP",
"RuleAction": "log",
"Port": "53",
"Description": "批量 VPC 规则二",
"OrderIndex": -1,
"Enable": "false",
"EdgeId": "ALL",
"FwGroupId": "cfwg-8f6785ee",
"IpVersion": 0
}
]
}
输出示例
{
"Response": {
"RuleUuids": [
10005,
10006
],
"RequestId": "00000000-0000-4000-8000-000000000005"
}
}
示例6 添加实例访问域名的 DNS 宽松和严格匹配规则
用户要求指定实例按域名解析结果访问外部服务时,调用 DescribeCfwAssets 获取来源 assets[].instance_id。dnsparse 在 Host/SNI 匹配或目的 IP 属于当前 DNS 解析结果时命中,domainiptwoverify 要求两个条件同时满足。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddVpcAcRule
<公共请求参数>
{
"Rules": [
{
"SourceContent": "ins-xxxxxxxx",
"SourceType": "instance",
"DestContent": "example.com",
"DestType": "dnsparse",
"Protocol": "TCP",
"RuleAction": "log",
"Port": "443",
"Description": "观察实例 DNS 宽松匹配流量",
"OrderIndex": -1,
"Enable": "false",
"EdgeId": "ALL",
"IpVersion": 0
},
{
"SourceContent": "ins-xxxxxxxx",
"SourceType": "instance",
"DestContent": "example.org",
"DestType": "domainiptwoverify",
"Protocol": "TCP",
"RuleAction": "log",
"Port": "443",
"Description": "观察实例 DNS 严格匹配流量",
"OrderIndex": -1,
"Enable": "false",
"EdgeId": "ALL",
"IpVersion": 0
}
]
}
输出示例
{
"Response": {
"RuleUuids": [
10007,
10008
],
"RequestId": "00000000-0000-4000-8000-000000000006"
}
}
示例7 添加资源标签访问网段的 VPC 规则
用户要求一组带标签的资产访问指定网段时,调用 DescribeResourceGroupNew,传 QueryType=tag,以一级节点 GroupName 为 Key、所选二级子节点 GroupName 为 Value 构造 SourceContent。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddVpcAcRule
<公共请求参数>
{
"Rules": [
{
"SourceContent": "{\"Key\":\"environment\",\"Value\":\"production\"}",
"SourceType": "tag",
"DestContent": "10.0.0.0/24",
"DestType": "net",
"Protocol": "ANY",
"RuleAction": "log",
"Port": "-1/-1",
"Description": "观察指定标签资产访问目标网段",
"OrderIndex": -1,
"Enable": "false",
"EdgeId": "ALL",
"IpVersion": 0
}
]
}
输出示例
{
"Response": {
"RuleUuids": [
10009
],
"RequestId": "00000000-0000-4000-8000-000000000007"
}
}
5. 开发者资源
腾讯云 API 平台
腾讯云 API 平台 是综合 API 文档、错误码、API Explorer 及 SDK 等资源的统一查询平台,方便您从同一入口查询及使用腾讯云提供的所有 API 服务。
API Inspector
用户可通过 API Inspector 查看控制台每一步操作关联的 API 调用情况,并自动生成各语言版本的 API 代码,也可前往 API Explorer 进行在线调试。
SDK
云 API 3.0 提供了配套的开发工具集(SDK),支持多种编程语言,能更方便的调用 API。
- Tencent Cloud SDK 3.0 for Python: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for Java: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for PHP: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for Go: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for Node.js: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for .NET: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for C++: CNB, GitHub, Gitee
- Tencent Cloud SDK 3.0 for Ruby: CNB, GitHub, Gitee
命令行工具
6. 错误码
以下仅列出了接口业务逻辑相关的错误码,其他错误码详见 公共错误码。
| 错误码 | 描述 |
|---|---|
| AuthFailure | CAM签名/鉴权错误。 |
| DryRunOperation | DryRun 操作,代表请求将会是成功的,只是多传了 DryRun 参数。 |
| FailedOperation | 操作失败。 |
| InternalError | 内部错误。 |
| InvalidParameter | 参数错误。 |
| InvalidParameterValue | 参数取值错误。 |
| LimitExceeded | 超过配额限制。 |
| MissingParameter | 缺少参数错误。 |
| OperationDenied | 操作被拒绝。 |
| RequestLimitExceeded | 请求的次数超过了频率限制。 |
| ResourceInUse | 资源被占用。 |
| ResourceInsufficient | 资源不足。 |
| ResourceNotFound | 资源不存在。 |
| ResourceUnavailable | 资源不可用。 |
| ResourcesSoldOut | 资源售罄。 |
| UnauthorizedOperation | 未授权操作。 |
| UnknownParameter | 未知参数错误。 |
| UnsupportedOperation | 操作不支持。 |