Skip to main content

Create Access Control

This API is used to configure access control for the website acceleration service.

Request

Request-Line

POST /cdn/v1.0/services/{serviceId}/accessControl HTTP/1.1

Request Parameters

Path Parameters

ParameterTypeRequiredDescription
serviceIdIntegerMandatoryThe unique identifier of the website acceleration service.

Body Parameters

ParameterTypeRequiredDescription
policyNameStringMandatoryPolicy name for access control.
typeStringMandatoryAccess control type, could be "allow", "deny" or "token".
matchUrlPathObjectMandatoryURL path matching configuration that determines which requests the rule applies to. See Match Url Path for details.
priorityIntegerMandatoryPriority weight for the rule. Rules with a higher weight take precedence. The weight must be non-zero.
matchQueryStringObjectOptionalQuery-string matching configuration used to refine which requests the rule applies to. See Match Query String for details.
ipRestrictionStringOptionalComma-separated list of ips/networks.Only requests from these subnets are allowed, other requests will be rejected with 403 Forbidden response.
geoRestrictionStringOptionalComma-separated list of geographic locations to be matched. Each location should be specified as a 2-letter ISO3166 code. E.g "SG,GB".
anonymousIpBooleanOptionalSet true to apply for anonymous IP, set false to apply for non anonymous IP. Default is false.
tokenSecretStringOptionalField tokenSecret is only for type "token".Comma-separated list of tokens.Each token should have 64 characters,Each character must be numeric or lowercase letter.
enabledBooleanOptionalFlag indicating whether the rule is active. Default is true.
Object: Match Url Path
ParameterTypeRequiredDescription
operatorStringMandatoryDefines how to match the field. Supported values:prefix,regex,equals,suffix.
patternsString[]MandatoryList of patterns matching the URL path string.
Object: Match Query String
ParameterTypeRequiredDescription
operatorStringMandatoryDefines how to match the field. Supported values:prefix,regex,equals,suffix.
patternsString[]MandatoryList of patterns matching the URL query string.

Response

Response Body

ParameterTypeDescription
policyIdIntegerPolicy ID number for access control.
policyNameStringPolicy name for access control.
typeStringAccess control type, could be "allow", "deny" or "token".
matchUrlPathObjectURL path matching configuration that determines which requests the rule applies to. See Match Url Path for details.
matchQueryStringObjectQuery-string matching configuration used to refine which requests the rule applies to. See Match Query String for details.
priorityIntegerPriority weight for the rule. Rules with a higher weight take precedence. The weight must be non-zero.
ipRestrictionStringComma-separated list of ips/networks.Only requests from these subnets are allowed, other requests will be rejected with 403 Forbidden response.
geoRestrictionStringComma-separated list of geographic locations to be matched. Each location should be specified as a 2-letter ISO3166 code. E.g "SG,GB".
anonymousIpBooleanSet true to apply for anonymous IP, set false to apply for non anonymous IP. Default is false.
tokenSecretStringField tokenSecret is only for type "token".Comma-separated list of tokens.Each token should have 64 characters,Each character must be numeric or lowercase letter.
enabledBooleanFlag indicating whether the rule is active. Default is true.

Status Codes, Error Codes and Error Messages

Status CodeError CodeError Message
400Request.BadRequestBad request.
400InvalidCustomer.IdEmptyCustomer id can be empty or invalid.
400InvalidService.IdIncorrectService id is empty or invalid.
400ServiceId.IdPermissionServiceId can not be found or unknown.
400Invalid.PolicyNamePolicy name is required.
400InvalidPolicy.TypeEmptyPolicy type can not be empty.
400InvalidPolicy.AccessTypePolicy access type must be one of the following values 'allow','deny','token'.
400InvalidPolicy.MatchURLIncorrectThe matchUrlPath can not be empty.
400InvalidPolicy.OperatorOperator must be one of the following: prefix,regex,equals or suffix.
400InvalidPolicy.MatchUrlPathPatternsIncorrectThe MatchUrlPath patterns could not be empty.
400InvalidPolicy.PriorityPriority is required.
400InvalidPolicy.IpRestrictionIp restriction format is incorrect,Supported formats: 172.31.31.0, 172.31.31.0/255.255.255.0, 172.31.32.0/24.
400InvalidPolicy.GeoFormatGeo restriction format is incorrect.

Examples

Create Access Control

Request

POST /cdn/v1.0/services/{serviceId}/accessControl HTTP/1.1

{
"policyName":"accetss",
"matchUrlPath":{
"operator":"suffix",
"patterns":["/wp-content/web/"]
},
"matchQueryString":{
"operator":"prefix",
"patterns":["/"]
},
"priority":123,
"type":"token",
"geoRestriction":"US,CN",
"ipRestriction":"172.16.12.1",
"anonymousIp":true,
"tokenSecret":"bdfy7r6jflo3iydy9zxigkl5m0hte6d423d45dfg6gavo07xvmtc4tzsdc9yxyjy",
"enabled":true
}

Successful Response Body

{
"policyId": 261951,
"policyName": "accetss",
"type": "token",
"matchUrlPath": {
"operator": "suffix",
"patterns": [
"/wp-content/web/"
]
},
"matchQueryString": {
"operator": "prefix",
"patterns": [
"/"
]
},
"priority": 123,
"ipRestriction": "172.16.12.1",
"geoRestriction": "CN,US",
"anonymousIp": false,
"tokenSecret": "bdfy7r6jflo3iydy9zxigkl5m0hte6d423d45dfg6gavo07xvmtc4tzsdc9yxyjy",
"enabled": true
}