更新时间:2024-09-13 GMT+08:00
分享

创建安全组

功能介绍

创建安全组。

接口约束

新建的安全组,默认只允许安全组内的实例互相访问。

调试

您可以在API Explorer中调试该接口,支持自动认证鉴权。

URI

POST /v3/{project_id}/vpc/security-groups

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID。

获取方式请参见获取项目ID

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

dry_run

Boolean

  • 功能说明:是否只预检此次请求。

  • 取值范围:

    • true:发送检查请求,不会创建安全组。检查项包括是否填写了必需参数、请求格式、业务限制。如果检查不通过,则返回对应错误。如果检查通过,则返回响应码202。

    • false(默认值):发送正常请求,并直接创建安全组。

security_group

CreateSecurityGroupOption object

创建安全组的请求体。

表3 CreateSecurityGroupOption

参数

是否必选

参数类型

描述

name

String

  • 功能描述:安全组名称。

  • 取值范围:1-64个字符,支持数字、字母、中文、_(下划线)、-(中划线)、.(点)。

description

String

  • 功能说明:安全组的描述信息。

  • 取值范围:0-255个字符,不能包含“<”和“>”。

enterprise_project_id

String

  • 功能说明:企业项目ID。创建安全组时,给安全组绑定企业项目ID。

  • 取值范围:最大长度36字节,带“-”连字符的UUID格式,或者是字符串“0”。“0”表示默认企业项目。

tags

Array of Tag objects

  • 功能说明:安全组的标签信息,详情参见Tag对象。

  • 取值范围:0-20个标签键值对。

表4 Tag

参数

是否必选

参数类型

描述

key

String

  • 功能说明:标签键。

  • 取值范围:

    • 最大长度36个unicode字符。 key不能为空。

    • 同一资源的key不能重复。

    • 可以包含的字符范围:

      • 英文字母

      • 数字

      • 特殊字符:下划线(_)、中划线(-)

      • 中文字符

value

String

  • 功能描述:标签值。

  • 取值范围:

    • 每个值最大长度43个unicode字符,value可以为空。

    • 可以包含的字符范围:

      • 英文字母

      • 数字

      • 特殊字符:下划线(_)、中划线(-)、点(.)

      • 中文字符

响应参数

状态码: 201

表5 响应Body参数

参数

参数类型

描述

request_id

String

请求ID。

security_group

SecurityGroupInfo object

创建安全组响应体。

表6 SecurityGroupInfo

参数

参数类型

描述

id

String

  • 功能描述:安全组对应的唯一标识。

  • 取值范围:带“-”的标准UUID格式。

name

String

  • 功能说明:安全组名称。

  • 取值范围:1-64个字符,支持数字、字母、中文、_(下划线)、-(中划线)、.(点)。

description

String

  • 功能说明:安全组的描述信息。

  • 取值范围:0-255个字符,不能包含“<”和“>”。

project_id

String

  • 功能说明:安全组所属的项目ID。

created_at

String

  • 功能说明:安全组创建时间。

  • 取值范围:UTC时间格式,yyyy-MM-ddTHH:mm:ssZ。

updated_at

String

  • 功能说明:安全组更新时间。

  • 取值范围:UTC时间格式,yyyy-MM-ddTHH:mm:ssZ。

enterprise_project_id

String

  • 功能说明:安全组所属的企业项目ID。

  • 取值范围:最大长度36字节,带“-”连字符的UUID格式,或者是字符串“0”。“0”表示默认企业项目。

tags

Array of Tag objects

  • 功能说明:安全组的标签信息,详情参见Tag对象。

  • 取值范围:0-20个标签键值对。

security_group_rules

Array of SecurityGroupRule objects

安全组规则。

表7 Tag

参数

参数类型

描述

key

String

  • 功能说明:标签键。

  • 取值范围:

    • 最大长度36个unicode字符。 key不能为空。

    • 同一资源的key不能重复。

    • 可以包含的字符范围:

      • 英文字母

      • 数字

      • 特殊字符:下划线(_)、中划线(-)

      • 中文字符

value

String

  • 功能描述:标签值。

  • 取值范围:

    • 每个值最大长度43个unicode字符,value可以为空。

    • 可以包含的字符范围:

      • 英文字母

      • 数字

      • 特殊字符:下划线(_)、中划线(-)、点(.)

      • 中文字符

表8 SecurityGroupRule

参数

参数类型

描述

id

String

  • 功能描述:安全组规则对应的唯一标识。

  • 取值范围:带“-”的标准UUID格式。

description

String

  • 功能说明:安全组规则的描述信息。

  • 取值范围:0-255个字符,不能包含“<”和“>”。

security_group_id

String

  • 功能说明:安全组规则所属的安全组ID。

direction

String

  • 功能说明:安全组规则的出入控制方向。

  • 取值范围:

    • ingress 表示入方向。

    • egress 表示出方向。

protocol

String

  • 功能说明:协议类型。

  • 取值范围:icmp、tcp、udp、icmpv6或IP协议号。

  • 约束:为空表示支持所有协议。协议为icmpv6时,网络类型应该为IPv6;协议为icmp时,网络类型应该为IPv4。

ethertype

String

  • 功能说明:IP地址协议类型。

  • 取值范围:IPv4,IPv6。

  • 约束:不填默认值为IPv4。

multiport

String

  • 功能说明:端口取值范围。

  • 取值范围:支持单端口(80),连续端口(1-30)以及不连续端口(22,3389,80)。

action

String

  • 功能说明:安全组规则生效策略。

  • 取值范围:

    • allow 表示允许。

    • deny 表示拒绝。

  • 约束:默认值为deny。

priority

Integer

  • 功能说明:优先级。

  • 取值范围:1~100,1代表最高优先级。

remote_group_id

String

  • 功能说明:远端安全组ID,表示该安全组内的流量允许或拒绝。

  • 取值范围:租户下存在的安全组ID。

  • 约束:与remote_ip_prefix,remote_address_group_id功能互斥。

remote_ip_prefix

String

  • 功能说明:远端IP地址,

    • 当direction是egress时为虚拟机访问端的地址;

    • 当direction是ingress时为访问虚拟机的地址。

  • 取值范围:IP地址,或者cidr格式。

  • 约束:与remote_group_id、remote_address_group_id互斥。

remote_address_group_id

String

  • 功能说明:远端地址组ID。

  • 取值范围:租户下存在的地址组ID。

  • 约束:与remote_ip_prefix,remote_group_id功能互斥。

created_at

String

  • 功能说明:安全组规则创建时间。

  • 取值范围:UTC时间格式,yyyy-MM-ddTHH:mm:ssZ。

updated_at

String

  • 功能说明:安全组规则更新时间。

  • 取值范围:UTC时间格式,yyyy-MM-ddTHH:mm:ssZ。

project_id

String

  • 功能说明:安全组规则所属项目ID。

请求示例

  • 创建安全组,指定名称为security_group_1,描述为security group description,指定预检该请求。

    POST https://{Endpoint}/v3/{project_id}/vpc/security-groups
    
    {
      "security_group" : {
        "name" : "security_group_1",
        "description" : "security group description"
      },
      "dry_run" : true
    }
  • 创建安全组,指定名称为security_group_1,描述为security group description。

    POST https://{Endpoint}/v3/{project_id}/vpc/security-groups
    
    {
      "security_group" : {
        "name" : "security_group_1",
        "description" : "security group description"
      }
    }

响应示例

状态码: 201

POST操作正常返回,更多状态码请参见状态码

  • {
      "security_group" : {
        "id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
        "name" : "security_group_1",
        "project_id" : "060576782980d5762f9ec014dd2f1148",
        "description" : "security group description",
        "enterprise_project_id" : "0",
        "security_group_rules" : [ {
          "id" : "f11a3824-ac19-4fad-b4f1-c5f4a6dd0a80",
          "project_id" : "060576782980d5762f9ec014dd2f1148",
          "security_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
          "remote_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
          "direction" : "ingress",
          "protocol" : null,
          "description" : "",
          "created_at" : "2020-07-09T05:56:27Z",
          "updated_at" : "2020-07-09T05:56:27Z",
          "ethertype" : "IPv6",
          "remote_ip_prefix" : null,
          "multiport" : null,
          "remote_address_group_id" : null,
          "action" : "allow",
          "priority" : 100
        }, {
          "id" : "3d6480e8-9ea4-46dc-bb1b-8db190cd5677",
          "project_id" : "060576782980d5762f9ec014dd2f1148",
          "security_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
          "remote_group_id" : null,
          "direction" : "egress",
          "protocol" : null,
          "description" : "",
          "created_at" : "2020-07-09T05:56:27Z",
          "updated_at" : "2020-07-09T05:56:27Z",
          "ethertype" : "IPv6",
          "remote_ip_prefix" : null,
          "multiport" : null,
          "remote_address_group_id" : null,
          "action" : "allow",
          "priority" : 100
        }, {
          "id" : "9581f18c-1fdd-43da-ace9-7758a56ef28a",
          "project_id" : "060576782980d5762f9ec014dd2f1148",
          "security_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
          "remote_group_id" : null,
          "direction" : "egress",
          "protocol" : null,
          "description" : "",
          "created_at" : "2020-07-09T05:56:27Z",
          "updated_at" : "2020-07-09T05:56:27Z",
          "ethertype" : "IPv4",
          "remote_ip_prefix" : null,
          "multiport" : null,
          "remote_address_group_id" : null,
          "action" : "allow",
          "priority" : 100
        }, {
          "id" : "a3ba270e-e58b-432d-a912-aeb7eace9fb8",
          "project_id" : "060576782980d5762f9ec014dd2f1148",
          "security_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
          "remote_group_id" : "69c999ad-d9ef-4d79-94fd-35e6ceb75325",
          "direction" : "ingress",
          "protocol" : null,
          "description" : "",
          "created_at" : "2020-07-09T05:56:27Z",
          "updated_at" : "2020-07-09T05:56:27Z",
          "ethertype" : "IPv4",
          "remote_ip_prefix" : null,
          "multiport" : null,
          "remote_address_group_id" : null,
          "action" : "allow",
          "priority" : 100
        } ],
        "created_at" : "2020-07-09T05:56:27Z",
        "updated_at" : "2020-07-09T05:56:27Z"
      },
      "request_id" : "a8cf4f79ca3c22ca685e7e8872e8c20b"
    }

状态码

状态码

描述

201

POST操作正常返回,更多状态码请参见状态码

错误码

请参见错误码

相关文档