批量添加安全组规则
更新时间:2025-08-05
接口描述
- 该接口用于向安全组中添加新的安全组规则
- 同一安全组中的规则以protocol、direction、portRange、sourceIp | destIp六元组作为唯一性索引,若安全组中已存在相同的规则将报409错误。
请求结构
Plain Text
1POST /v1/securityGroup/{securityGroupId}/rule/batch/{action} HTTP/1.1
2Host: bec.baidubce.com
3Authorization: authorization string
4
5{
6 "rules": [
7 {
8 "protocol": protocol,
9 "portRange": portRange,
10 "direction": direction,
11 "sourceIp": sourceIp,
12 "remark": "备注"
13 }
14 ]
15}
请求头域
除公共头域外,无其它特殊头域。
请求参数
参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
---|---|---|---|---|
securityGroupId | String | 是 | URL参数 | 目标安全组ID |
action | String | 是 | Query参数 | 对安全组执行动作,当前取值add |
rules | List<SecurityGroupRule> | 是 | RequestBody参数 | 待添加的安全组规则列表 |
返回头域
除公共头域,无其它特殊头域。
返回参数
参数名称 | 类型 | 描述 |
---|---|---|
result | Boolean | 返回结果,true:表示成功;false:表示失败。 |
action | String | 操作描述 |
details | Details | 返回结果,类型为String |
请求示例
Plain Text
1POST /v1/securityGroup/sg-nky7qeom/rule/batch/add HTTP/1.1
2Host: bec.baidubce.com
3Authorization: bce-auth-v1/f81d3b34e48048fbb2634dc7882d7e21/2021-08-11T04:17:29Z/3600/host/uuid
4
5{
6 "rules": [
7 {
8 "remark": "备注",
9 "protocol": "tcp",
10 "portRange": "1-65535",
11 "direction": "ingress",
12 "sourceIp": ""
13 }
14 ]
15}
返回示例
Plain Text
1HTTP/1.1 200 OK
2x-bce-request-id: 1214cca7-4ad5-451d-9215-71cb844c0a50
3Date: Wed, 03 Dec 2014 06:42:19 GMT
4Content-Type: application/json;charset=UTF-8
5Server: BWS
6
7{
8 "result": true,
9 "action": "add",
10 "details": {
11 "id": "sg-m1pxebfd",
12 "name": "test",
13 "desc": "",
14 "rules": [
15 {
16 "securityGroupRuleId": "sgr-m1pxebfd-vtlzdbkd",
17 "direction": "egress",
18 "protocol": "icmp",
19 "remark": "PING请求_IPv4",
20 "etherType": "IPv4",
21 "destIp": "0.0.0.0/0"
22 },
23 {
24 "securityGroupRuleId": "sgr-m1pxebfd-awq69vfm",
25 "direction": "ingress",
26 "protocol": "tcp",
27 "portRange": "1-65535",
28 "remark": "备注",
29 "etherType": "IPv4",
30 "sourceIp": "0.0.0.0/0"
31 }
32 ],
33 "isDefault": false
34 }
35}
Model对象定义
Details
参数名称 | 类型 | 描述 |
---|---|---|
id | String | 安全组ID |
name | String | 名称 |
desc | String | 描述 |
rules | List<SecurityGroupRule> | 安全组规则 |
SecurityGroupRule
参数名称 | 类型 | 描述 |
---|---|---|
direction | String | 入站/出站,取值ingress或egress。 |
etherType | String | 网络类型,取值IPv4。暂不支持IPv6 |
portRange | String | 端口范围,可以指定80等单个端口,也可以指定范围如80-9000。 值为空时默认取值1-65535 |
protocol | String | 协议类型,tcp、udp或icmp,值为空时默认为所有协议 |
sourceIp | String | 源IP地址 |
destIp | String | 目的IP地址 |
remark | String | 备注 |