1. 接口描述
接口请求域名: cfw.tencentcloudapi.com 。
新增一条或多条企业安全组规则。
默认接口请求频率限制:20次/秒。
2. 输入参数
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| Action | 是 | String | 公共参数,本接口取值:AddEnterpriseSecurityGroupRules。 |
| Version | 是 | String | 公共参数,本接口取值:2019-09-04。 |
| Region | 否 | String | 公共参数,本接口不需要传递此参数。 |
| Data.N | 是 | Array of SecurityGroupRule | 待创建的规则数组,不能为空。每条规则必须提供访问源、访问目的、动作、非空描述和字符串 OrderIndex。未使用 ServiceTemplateId 时必须提供 Protocol 和 Port;使用 ServiceTemplateId 时二者可同时省略或留空,如填写非空值则必须为 Protocol=ANY、Port=-1/-1。Scope 可省略,默认使用 SG。 |
| CfwAiAgentOperationSource | 否 | String | AI操作来源 枚举值:
示例值:console |
| ClientToken | 否 | String | 保留字段,不提供幂等保证;重复请求仍可能重复创建规则,建议省略。 示例值:123e4567-e89b-12d3-a456-426655440000 |
| From | 否 | String | 添加方式。batch_import 表示非覆盖批量导入;batch_import_cover 表示覆盖导入,会删除当前账号的全部可操作企业安全组规则后再添加 Data,添加失败时已删除的规则不会恢复,风险极高。两种批量导入都会使用 Data.Enable。其它值按普通新增处理。 示例值:batch_import_cover |
| IsDelay | 否 | Integer | 延迟生效标记。1 表示将规则保留为待生效状态,0 表示按账号当前发布设置处理;省略等同于 0。账号停止自动发布时,规则仍保持待生效。 示例值:1 |
| IsUseId | 否 | Integer | 规则 ID 复用标记。1 表示使用每条规则的 Data.Id,此时 Data.Id 传十进制数字字符串;其它值由系统分配 ID。重复 ID 会导致创建失败。 示例值:1 |
| Type | 否 | Integer | 添加位置类型,可省略,默认为 0:0 添加到末尾,1 添加到最前,2 从指定顺序插入。Type=0 或 1 按 Data 数组顺序确定最终顺序;Type=2 使用首条 Data.OrderIndex 作为插入位置,超过当前最大顺序时添加到末尾。 示例值:1 |
3. 输出参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| Rules | Array of SecurityGroupSimplifyRule | 新增规则的摘要列表。 |
| Status | Integer | 处理状态:0 表示成功。 示例值:0 |
| RequestId | String | 唯一请求 ID,由服务端生成,每次请求都会返回(若请求因其他原因未能抵达服务端,则该次请求不会获得 RequestId)。定位问题时需要提供该次请求的 RequestId。 |
4. 示例
示例1 使用协议和端口新增企业安全组规则
显式指定 TCP 协议和 443 端口,在最高优先级新增一条放行规则。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddEnterpriseSecurityGroupRules
<公共请求参数>
{
"Type": 1,
"Data": [
{
"SourceType": "net",
"SourceContent": "192.0.2.0/24",
"DestType": "net",
"DestContent": "198.51.100.10",
"RuleAction": "accept",
"Description": "允许文档网段访问 HTTPS",
"OrderIndex": "1",
"Protocol": "TCP",
"Port": "443",
"Scope": "SG"
}
]
}
输出示例
{
"Response": {
"Status": 0,
"Rules": [
{
"SourceContent": "192.0.2.0/24",
"DestContent": "198.51.100.10",
"Protocol": "TCP",
"Description": "允许文档网段访问 HTTPS",
"RuleUuid": 900001,
"Sequence": 1,
"Scope": "SG"
}
],
"RequestId": "123e4567-e89b-42d3-a456-426614174000"
}
}
示例2 使用服务模板新增企业安全组规则
使用服务模板新增企业安全组规则。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddEnterpriseSecurityGroupRules
<公共请求参数>
{
"Type": 1,
"Data": [
{
"SourceType": "net",
"SourceContent": "192.0.2.0/24",
"DestType": "net",
"DestContent": "198.51.100.20",
"RuleAction": "drop",
"Description": "使用服务模板限制文档地址",
"OrderIndex": "1",
"Protocol": "ANY",
"Port": "-1/-1",
"ServiceTemplateId": "ppmg-example-service-01",
"Scope": "SG"
}
]
}
输出示例
{
"Response": {
"Status": 0,
"Rules": [
{
"SourceContent": "192.0.2.0/24",
"DestContent": "198.51.100.20",
"Protocol": "ANY",
"Description": "使用服务模板限制文档地址",
"RuleUuid": 900002,
"Sequence": 1,
"Scope": "SG"
}
],
"RequestId": "123e4567-e89b-42d3-a456-426614174001"
}
}
示例3 在末尾新增轻量服务器范围规则
使用 Type=0 在末尾新增一条 LH 范围规则;LH 范围不能使用地址模板或服务模板。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddEnterpriseSecurityGroupRules
<公共请求参数>
{
"Type": 0,
"Data": [
{
"SourceType": "net",
"SourceContent": "192.0.2.0/24",
"DestType": "net",
"DestContent": "198.51.100.30",
"RuleAction": "accept",
"Description": "允许轻量服务器 HTTPS 访问",
"OrderIndex": "-1",
"Protocol": "TCP",
"Port": "443",
"Scope": "LH"
}
]
}
输出示例
{
"Response": {
"Status": 0,
"Rules": [
{
"SourceContent": "192.0.2.0/24",
"DestContent": "198.51.100.30",
"Protocol": "TCP",
"Description": "允许轻量服务器 HTTPS 访问",
"RuleUuid": 900003,
"Sequence": 3,
"Scope": "LH"
}
],
"RequestId": "123e4567-e89b-42d3-a456-426614174002"
}
}
示例4 在指定位置插入企业安全组规则
使用 Type=2 在指定顺序插入一条规则,并通过 IsDelay=1 延迟生效;调用前使用 DescribeCfwRules,传 RuleType=enterprise_sg、ExpandNames=false,将目标位置对应的 rules[].sequence 转为十进制字符串后写入 OrderIndex。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddEnterpriseSecurityGroupRules
<公共请求参数>
{
"Type": 2,
"IsDelay": 1,
"Data": [
{
"SourceType": "net",
"SourceContent": "192.0.2.80",
"DestType": "net",
"DestContent": "198.51.100.80",
"RuleAction": "accept",
"Description": "指定位置企业安全组规则",
"OrderIndex": "7",
"Protocol": "TCP",
"Port": "443",
"Scope": "SG"
}
]
}
输出示例
{
"Response": {
"Status": 0,
"Rules": [
{
"RuleUuid": 900004,
"Sequence": 7,
"SourceContent": "192.0.2.80",
"DestContent": "198.51.100.80",
"Protocol": "TCP",
"Description": "指定位置企业安全组规则",
"Scope": "SG"
}
],
"RequestId": "123e4567-e89b-42d3-a456-426614174003"
}
}
示例5 批量导入企业安全组规则
使用非覆盖的 batch_import 新增两条禁用规则,并通过 IsDelay=1 延迟生效;不会删除已有规则。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddEnterpriseSecurityGroupRules
<公共请求参数>
{
"Type": 0,
"From": "batch_import",
"IsDelay": 1,
"Data": [
{
"SourceType": "net",
"SourceContent": "192.0.2.91",
"DestType": "net",
"DestContent": "198.51.100.91",
"RuleAction": "accept",
"Description": "批量企业安全组规则一",
"OrderIndex": "-1",
"Protocol": "TCP",
"Port": "443",
"Enable": "false",
"Scope": "SG"
},
{
"SourceType": "net",
"SourceContent": "192.0.2.92",
"DestType": "net",
"DestContent": "198.51.100.92",
"RuleAction": "accept",
"Description": "批量企业安全组规则二",
"OrderIndex": "-1",
"Protocol": "UDP",
"Port": "53",
"Enable": "false",
"Scope": "SG"
}
]
}
输出示例
{
"Response": {
"Status": 0,
"Rules": [
{
"RuleUuid": 900005,
"Sequence": 8,
"SourceContent": "192.0.2.91",
"DestContent": "198.51.100.91",
"Protocol": "TCP",
"Description": "批量企业安全组规则一",
"Scope": "SG"
},
{
"RuleUuid": 900006,
"Sequence": 9,
"SourceContent": "192.0.2.92",
"DestContent": "198.51.100.92",
"Protocol": "UDP",
"Description": "批量企业安全组规则二",
"Scope": "SG"
}
],
"RequestId": "123e4567-e89b-42d3-a456-426614174004"
}
}
示例6 延迟下发企业安全组规则
使用 IsDelay=1 将规则保留为待生效状态,后续需由业务流程显式发布。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddEnterpriseSecurityGroupRules
<公共请求参数>
{
"Type": 0,
"IsDelay": 1,
"Data": [
{
"SourceType": "net",
"SourceContent": "192.0.2.100",
"DestType": "net",
"DestContent": "198.51.100.100",
"RuleAction": "accept",
"Description": "延迟下发企业安全组规则",
"OrderIndex": "-1",
"Protocol": "TCP",
"Port": "9443",
"Scope": "SG"
}
]
}
输出示例
{
"Response": {
"Status": 0,
"Rules": [
{
"RuleUuid": 900007,
"Sequence": 10,
"SourceContent": "192.0.2.100",
"DestContent": "198.51.100.100",
"Protocol": "TCP",
"Description": "延迟下发企业安全组规则",
"Scope": "SG"
}
],
"RequestId": "123e4567-e89b-42d3-a456-426614174005"
}
}
示例7 新增安全组和轻量服务器组合范围规则
使用 SG,LH 组合范围同时作用于安全组和轻量服务器;组合范围不能使用地址模板或服务模板。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddEnterpriseSecurityGroupRules
<公共请求参数>
{
"Type": 0,
"IsDelay": 1,
"Data": [
{
"SourceType": "net",
"SourceContent": "192.0.2.110",
"DestType": "net",
"DestContent": "198.51.100.110",
"RuleAction": "accept",
"Description": "安全组和轻量服务器组合范围",
"OrderIndex": "-1",
"Protocol": "TCP",
"Port": "443",
"Scope": "SG,LH"
}
]
}
输出示例
{
"Response": {
"Status": 0,
"Rules": [
{
"RuleUuid": 900008,
"Sequence": 11,
"SourceContent": "192.0.2.110",
"DestContent": "198.51.100.110",
"Protocol": "TCP",
"Description": "安全组和轻量服务器组合范围",
"Scope": "SG,LH"
}
],
"RequestId": "123e4567-e89b-42d3-a456-426614174006"
}
}
示例8 批量添加标签地域和实例域名规则
用户要求按资产标签限制访问地域,并允许指定实例按 DNS 解析结果访问域名时,调用 DescribeResourceGroupNew 获取标签名称,调用 DescribeSecurityGroupRegionList 获取 Data[].Region,调用 DescribeCfwAssets 获取 assets[].instance_id。
输入示例
POST / HTTP/1.1
Host: cfw.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: AddEnterpriseSecurityGroupRules
<公共请求参数>
{
"Type": 0,
"From": "batch_import",
"IsDelay": 1,
"Data": [
{
"SourceType": "tag",
"SourceContent": "{\"Key\":\"environment\",\"Value\":\"production\"}",
"DestType": "region",
"DestContent": "ap-guangzhou",
"RuleAction": "log",
"Description": "观察生产标签资产访问广州地域",
"OrderIndex": "-1",
"Protocol": "ANY",
"Port": "-1/-1",
"Enable": "false",
"Scope": "SG"
},
{
"SourceType": "instance",
"SourceContent": "ins-xxxxxxxx",
"DestType": "dnsparse",
"DestContent": "example.com",
"RuleAction": "log",
"Description": "观察指定实例访问解析域名",
"OrderIndex": "-1",
"Protocol": "TCP",
"Port": "443",
"Enable": "false",
"Scope": "SG"
}
]
}
输出示例
{
"Response": {
"Status": 0,
"Rules": [
{
"RuleUuid": 900009,
"Sequence": 12,
"SourceContent": "{\"Key\":\"environment\",\"Value\":\"production\"}",
"DestContent": "ap-guangzhou",
"Protocol": "ANY",
"Description": "观察生产标签资产访问广州地域",
"Scope": "SG"
},
{
"RuleUuid": 900010,
"Sequence": 13,
"SourceContent": "ins-xxxxxxxx",
"DestContent": "example.com",
"Protocol": "TCP",
"Description": "观察指定实例访问解析域名",
"Scope": "SG"
}
],
"RequestId": "123e4567-e89b-42d3-a456-426614174007"
}
}
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. 错误码
以下仅列出了接口业务逻辑相关的错误码,其他错误码详见 公共错误码。
| 错误码 | 描述 |
|---|---|
| FailedOperation | 操作失败。 |
| InternalError | 内部错误。 |
| InvalidParameter | 参数错误。 |
| InvalidParameterValue | 参数取值错误。 |
| LimitExceeded | 超过配额限制。 |
| ResourceInUse | 资源被占用。 |
| UnsupportedOperation | 操作不支持。 |