创建ACL规则
功能介绍
创建ACL规则
调用方法
请参见如何调用API。
URI
POST /v1/{project_id}/acl-rule
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
租户项目id |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
enterprise_project_id |
否 |
String |
企业项目id,用户支持企业项目后,由企业项目生成的id。 |
fw_instance_id |
否 |
String |
防火墙实例id,创建云防火墙后用于标志防火墙由系统自动生成的标志id,可通过调用查询防火墙实例接口,默认情况下,fw_instance_Id为空时,返回账号下第一个墙的信息;fw_instance_Id非空时,返回与fw_instance_Id对应墙的信息。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值) |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
object_id |
是 |
String |
防护对象id,是创建云防火墙后用于区分互联网边界防护和VPC边界防护的标志id,可通过调用查询防火墙实例接口,注意type为0的为互联网边界防护对象id,type为1的为VPC边界防护对象id。 |
type |
是 |
Integer |
规则type,0:互联网规则,1:vpc规则,2:nat规则 枚举值:
|
rules |
是 |
Array of rules objects |
rules |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
是 |
String |
规则名称 |
sequence |
是 |
OrderRuleAclDto object |
规则序列 |
address_type |
是 |
Integer |
地址类型,0 ipv4,1 ipv6,2 domain 枚举值:
|
action_type |
是 |
Integer |
动作0:permit,1:deny |
status |
是 |
Integer |
规则下发状态 0:禁用,1:启用 枚举值:
|
applications |
否 |
Array of strings |
应用列表 |
applicationsJsonString |
否 |
String |
应用列表转化json字符串 |
long_connect_time |
否 |
Long |
长连接时长 |
long_connect_time_hour |
否 |
Long |
长连接时长小时 |
long_connect_time_minute |
否 |
Long |
长连接时长分钟 |
long_connect_time_second |
否 |
Long |
长连接时长秒 |
long_connect_enable |
是 |
Integer |
是否支持长连接,0表示不支持长连接,1表示支持长连接 枚举值:
|
description |
否 |
String |
描述 |
direction |
否 |
Integer |
方向:0表示外到内,1表示内到外【说明:规则type=0:互联网规则 | 2:nat规则时方向值必填】 枚举值:
|
source |
是 |
RuleAddressDtoForRequest object |
源地址传输对象 |
destination |
是 |
RuleAddressDtoForRequest object |
目的地址传输对象 |
service |
是 |
RuleServiceDto object |
服务对象 |
tag |
否 |
TagsVO object |
标签显示值 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
dest_rule_id |
否 |
String |
目标规则id,添加规则位于此规则之后,非置顶时不能为空,置顶时为空 |
top |
否 |
Integer |
是否置顶,0代表非置顶,1代表置顶 |
bottom |
否 |
Integer |
是否置底,0代表非置底,1代表置底 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
Integer |
类型0手工输入,1关联IP地址组,2域名,3地理位置,4域名组,5多对象,6域名组-DNS解析,7域名组-URL过滤。 |
address_type |
否 |
Integer |
地址类型0 ipv4,1 ipv6 |
address |
否 |
String |
IP,手动类型不能为空,自动及domain类型为空 |
address_set_id |
否 |
String |
关联IP地址组ID,自动类型不能为空,手动类型合domain类型为空 |
address_set_name |
否 |
String |
地址组名称 |
domain_address_name |
否 |
String |
域名地址名称,域名类型时不能为空,手动类型及自动类型时为空 |
region_list_json |
否 |
String |
规则region列表json值 |
region_list |
否 |
Array of IpRegionDto objects |
规则region列表 |
domain_set_id |
否 |
String |
域名组id |
domain_set_name |
否 |
String |
域名组名称 |
ip_address |
否 |
Array of strings |
IP地址列表 |
address_set_type |
否 |
Integer |
地址组类型,0表示自定义地址组,1表示WAF回源IP地址组,2表示DDoS回源IP地址组,3表示NAT64转换地址组 |
predefined_group |
否 |
Array of strings |
预定义地址组列表 |
address_group |
否 |
Array of strings |
地址组列表 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
region_id |
否 |
String |
区域id |
description_cn |
否 |
String |
中文描述 |
description_en |
否 |
String |
英文描述 |
region_type |
否 |
Integer |
区域类型,0表示国家,1表示省份,2表示大洲 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
Integer |
服务输入类型,0为手动输入类型,1为自动输入类型 |
protocol |
否 |
Integer |
协议类型:TCP为6, UDP为17,ICMP为1,ICMPV6为58,ANY为-1,手动类型不为空,自动类型为空 |
protocols |
否 |
Array of integers |
协议列表,协议类型:TCP为6, UDP为17,ICMP为1,ICMPV6为58,ANY为-1,手动类型不为空,自动类型为空 |
source_port |
否 |
String |
源端口 |
dest_port |
否 |
String |
目的端口 |
service_set_id |
否 |
String |
服务组id,手动类型为空,自动类型为非空 |
service_set_name |
否 |
String |
服务组名称 |
custom_service |
否 |
Array of ServiceItem objects |
自定义服务 |
predefined_group |
否 |
Array of strings |
预定义服务组列表 |
service_group |
否 |
Array of strings |
服务组列表 |
service_group_names |
否 |
Array of ServiceGroupVO objects |
服务组名称列表 |
service_set_type |
否 |
Integer |
服务组类型,0表示自定义服务组,1表示常用WEB服务,2表示常用远程登录和PING,3表示常用数据库 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
protocol |
否 |
Integer |
协议类型:TCP为6, UDP为17,ICMP为1,ICMPV6为58,ANY为-1,手动类型不为空,自动类型为空 |
source_port |
否 |
String |
源端口 |
dest_port |
否 |
String |
目的端口 |
description |
否 |
String |
服务成员描述 |
name |
否 |
String |
服务成员名称 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
data |
RuleIdList object |
规则id列表 |
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码 最小长度:8 最大长度:36 |
error_msg |
String |
错误描述 最小长度:2 最大长度:512 |
请求示例
示例为添加一个IPv4类型的外到内的规则,名称为测试规则,源类型为IP地址,地址为1.1.1.1,目的类型为IP地址,目的地址类型为2.2.2.2,服务类型为服务,协议类型为TCP,源端口为0,目的端口为0,不支持长连接,动作为放行,启用状态为启用
https://{Endpoint}/v1/9d80d070b6d44942af73c9c3d38e0429/acl-rule { "object_id" : "ae42418e-f077-41a0-9d3b-5b2f5ad9102b", "rules" : [ { "name" : "测试规则", "status" : 1, "action_type" : 0, "description" : "", "source" : { "type" : 0, "address" : "1.1.1.1" }, "destination" : { "type" : 0, "address" : "2.2.2.2" }, "service" : { "type" : 0, "protocol" : 6, "source_port" : "0", "dest_port" : "0" }, "address_type" : 0, "tag" : { "tag_key" : "", "tag_value" : "" }, "long_connect_enable" : 0, "direction" : 0, "sequence" : { "top" : 1, "dest_rule_id" : null } } ], "type" : 0 }
响应示例
状态码: 200
添加acl响应
{ "data" : { "rules" : [ { "id" : "0475c516-0e41-4caf-990b-0c504eebd73f", "name" : "testName" } ] } }
状态码: 400
Bad Request
{ "error_code" : "CFW.00900016", "error_msg" : "导入任务进行中,请任务结束后再操作" }
SDK代码示例
SDK代码示例如下。
Java
示例为添加一个IPv4类型的外到内的规则,名称为测试规则,源类型为IP地址,地址为1.1.1.1,目的类型为IP地址,目的地址类型为2.2.2.2,服务类型为服务,协议类型为TCP,源端口为0,目的端口为0,不支持长连接,动作为放行,启用状态为启用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.cfw.v1.region.CfwRegion; import com.huaweicloud.sdk.cfw.v1.*; import com.huaweicloud.sdk.cfw.v1.model.*; import java.util.List; import java.util.ArrayList; public class AddAclRuleSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); CfwClient client = CfwClient.newBuilder() .withCredential(auth) .withRegion(CfwRegion.valueOf("<YOUR REGION>")) .build(); AddAclRuleRequest request = new AddAclRuleRequest(); request.withEnterpriseProjectId("<enterprise_project_id>"); request.withFwInstanceId("<fw_instance_id>"); AddRuleAclDto body = new AddRuleAclDto(); TagsVO tagRules = new TagsVO(); tagRules.withTagKey("") .withTagValue(""); RuleServiceDto serviceRules = new RuleServiceDto(); serviceRules.withType(0) .withProtocol(6) .withSourcePort("0") .withDestPort("0"); RuleAddressDtoForRequest destinationRules = new RuleAddressDtoForRequest(); destinationRules.withType(0) .withAddress("2.2.2.2"); RuleAddressDtoForRequest sourceRules = new RuleAddressDtoForRequest(); sourceRules.withType(0) .withAddress("1.1.1.1"); OrderRuleAclDto sequenceRules = new OrderRuleAclDto(); sequenceRules.withTop(1); List<AddRuleAclDtoRules> listbodyRules = new ArrayList<>(); listbodyRules.add( new AddRuleAclDtoRules() .withName("测试规则") .withSequence(sequenceRules) .withAddressType(AddRuleAclDtoRules.AddressTypeEnum.NUMBER_0) .withActionType(0) .withStatus(AddRuleAclDtoRules.StatusEnum.NUMBER_1) .withLongConnectEnable(AddRuleAclDtoRules.LongConnectEnableEnum.NUMBER_0) .withDescription("") .withDirection(AddRuleAclDtoRules.DirectionEnum.NUMBER_0) .withSource(sourceRules) .withDestination(destinationRules) .withService(serviceRules) .withTag(tagRules) ); body.withRules(listbodyRules); body.withType(AddRuleAclDto.TypeEnum.NUMBER_0); body.withObjectId("ae42418e-f077-41a0-9d3b-5b2f5ad9102b"); request.withBody(body); try { AddAclRuleResponse response = client.addAclRule(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Python
示例为添加一个IPv4类型的外到内的规则,名称为测试规则,源类型为IP地址,地址为1.1.1.1,目的类型为IP地址,目的地址类型为2.2.2.2,服务类型为服务,协议类型为TCP,源端口为0,目的端口为0,不支持长连接,动作为放行,启用状态为启用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcfw.v1.region.cfw_region import CfwRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcfw.v1 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] credentials = BasicCredentials(ak, sk) client = CfwClient.new_builder() \ .with_credentials(credentials) \ .with_region(CfwRegion.value_of("<YOUR REGION>")) \ .build() try: request = AddAclRuleRequest() request.enterprise_project_id = "<enterprise_project_id>" request.fw_instance_id = "<fw_instance_id>" tagRules = TagsVO( tag_key="", tag_value="" ) serviceRules = RuleServiceDto( type=0, protocol=6, source_port="0", dest_port="0" ) destinationRules = RuleAddressDtoForRequest( type=0, address="2.2.2.2" ) sourceRules = RuleAddressDtoForRequest( type=0, address="1.1.1.1" ) sequenceRules = OrderRuleAclDto( top=1 ) listRulesbody = [ AddRuleAclDtoRules( name="测试规则", sequence=sequenceRules, address_type=0, action_type=0, status=1, long_connect_enable=0, description="", direction=0, source=sourceRules, destination=destinationRules, service=serviceRules, tag=tagRules ) ] request.body = AddRuleAclDto( rules=listRulesbody, type=0, object_id="ae42418e-f077-41a0-9d3b-5b2f5ad9102b" ) response = client.add_acl_rule(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Go
示例为添加一个IPv4类型的外到内的规则,名称为测试规则,源类型为IP地址,地址为1.1.1.1,目的类型为IP地址,目的地址类型为2.2.2.2,服务类型为服务,协议类型为TCP,源端口为0,目的端口为0,不支持长连接,动作为放行,启用状态为启用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" cfw "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := cfw.NewCfwClient( cfw.CfwClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.AddAclRuleRequest{} enterpriseProjectIdRequest:= "<enterprise_project_id>" request.EnterpriseProjectId = &enterpriseProjectIdRequest fwInstanceIdRequest:= "<fw_instance_id>" request.FwInstanceId = &fwInstanceIdRequest tagKeyTag:= "" tagValueTag:= "" tagRules := &model.TagsVo{ TagKey: &tagKeyTag, TagValue: &tagValueTag, } protocolService:= int32(6) sourcePortService:= "0" destPortService:= "0" serviceRules := &model.RuleServiceDto{ Type: int32(0), Protocol: &protocolService, SourcePort: &sourcePortService, DestPort: &destPortService, } addressDestination:= "2.2.2.2" destinationRules := &model.RuleAddressDtoForRequest{ Type: int32(0), Address: &addressDestination, } addressSource:= "1.1.1.1" sourceRules := &model.RuleAddressDtoForRequest{ Type: int32(0), Address: &addressSource, } topSequence:= int32(1) sequenceRules := &model.OrderRuleAclDto{ Top: &topSequence, } descriptionRules:= "" directionRules:= model.GetAddRuleAclDtoRulesDirectionEnum().E_0 var listRulesbody = []model.AddRuleAclDtoRules{ { Name: "测试规则", Sequence: sequenceRules, AddressType: model.GetAddRuleAclDtoRulesAddressTypeEnum().E_0, ActionType: int32(0), Status: model.GetAddRuleAclDtoRulesStatusEnum().E_1, LongConnectEnable: model.GetAddRuleAclDtoRulesLongConnectEnableEnum().E_0, Description: &descriptionRules, Direction: &directionRules, Source: sourceRules, Destination: destinationRules, Service: serviceRules, Tag: tagRules, }, } request.Body = &model.AddRuleAclDto{ Rules: listRulesbody, Type: model.GetAddRuleAclDtoTypeEnum().E_0, ObjectId: "ae42418e-f077-41a0-9d3b-5b2f5ad9102b", } response, err := client.AddAclRule(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
添加acl响应 |
400 |
Bad Request |
401 |
Unauthorized |
403 |
Forbidden |
404 |
Not Found |
500 |
Internal Server Error |
错误码
请参见错误码。