创建安全组
更新时间:2025-08-05
接口描述
本接口用来创建安全组以及安全组规则。
创建安全组和节点无关,当创建资源时会根据资源所在节点进行绑定。
- 同一安全组中的规则以protocol、direction、portRange、sourceIp|destIp唯一性索引,重复记录报409错误。
 - 安全组规则protocol的取值(tcp|udp|icmp),值为空默认表示所有协议。
 
请求结构
                Plain Text
                
            
            1POST /v1/securityGroup HTTP/1.1
2Host: bec.baidubce.com
3Authorization: authorization string
            请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 | 
|---|---|---|---|---|
| name | String | 是 | RequestBody参数 | 创建的安全组的名字,支持大小写字母、数字、中文以及-_ /.特殊字符,必须以字母开头,长度1-65。 | 
| desc | String | 否 | RequestBody参数 | 对所创建的安全组的描述信息 | 
| rules | List<SecurityGroupRule> | 否 | RequestBody参数 | 创建安全组时绑定的安全组规则列表 | 
| withDefaultRules | Boolean | 否 | RequestBody参数 | 当rules参数为空时,withDefaultRules参数表示是否(true/false)默认创建出向全开的规则。 不填缺省值是true。 | 
返回头域
除公共头域,无其它特殊头域。
返回参数
| 参数名称 | 类型 | 描述 | 
|---|---|---|
| result | Boolean | 返回结果,true:表示成功;false:表示失败。 | 
| action | String | 操作描述 | 
| details | Map | 返回结果,包含securityGroupId,类型为String | 
错误码
请参照错误返回章节的内容。
请求示例
                Plain Text
                
            
            1POST /v1/securityGroup HTTP/1.1
2Host: bec.baidubce.com
3Authorization: bce-auth-v1/f81d3b34e48048fbb2634dc7882d7e21/2021-08-11T04:17:29Z/3600/host/74c506f68c65e26c633bfa104c863fffac5190fdec1ec24b7c03eb5d67d2e1de
4
5{
6	"name": "test-security-group",
7	"desc": "create a security group for api doc",
8	"rules": [
9		{
10			"remark": "备注",
11			"protocol": "tcp",
12			"portRange": "1-65535",
13			"direction": "ingress",
14			"sourceIp": ""
15		},
16		{
17			"remark": "全部协议",
18			"protocol": "",
19			"portRange": "",
20			"direction": "egress",
21			"destIp": ""
22		}
23	]
24}
            返回示例
                Plain Text
                
            
            1HTTP/1.1 200 OK
2x-bce-request-id: 1214cca7-4ad5-451d-9215-71cb844c0a50
3Date: Wed, 03 Dec 2021 06:42:19 GMT
4Content-Type: application/json;charset=UTF-8
5Server: BWS	
6
7{
8    "result": true,
9    "action": "create",
10    "details": {
11        "securityGroupId": "sg-eqdhdbrb"
12    }
13}
            Model对象定义
SecurityGroupRule
| 参数名称 | 类型 | 描述 | 是否必须 | 
|---|---|---|---|
| direction | String | 入站/出站,取值ingress或egress。 | 是 | 
| etherType | String | 网络类型,取值IPv4。暂不支持IPv6 | 否 | 
| portRange | String | 端口范围,可以指定80等单个端口,也可以指定范围如80-9000。值为空时默认取值1-65535。 | 否 | 
| protocol | String | 协议类型,tcp、udp或icmp,值为空时默认为所有协议。 | 否 | 
| sourceIp | String | 源IP地址。当direction为ingress时适用 | 否 | 
| destIp | String | 目的IP地址。当direction为egress时适用 | 否 | 
| remark | String | 备注 | 否 | 
