Skip to main content

Edit Access Control V2

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

Request

Request-Line

PUT /cdn/v1.1/services/{serviceId}/accessControl/{policyId} HTTP/1.1

Request Parameters

Path Parameters

ParameterTypeRequiredDescription
serviceIdIntegerMandatoryThe unique identifier of the website acceleration service.
policyIdIntegerMandatoryPolicy ID number for access control.

Body Parameters

ParameterTypeRequiredDescription
policyNameStringMandatoryPolicy name for access control.
typeStringMandatoryAccess control type, could be "allow", "deny" or "token".
matchesArrayMandatoryMatching configuration that determines which requests the rule applies to. See Matches for details.
priorityIntegerOptionalPriority weight for the rule. Rules with a higher weight take precedence. The weight must be non-zero.
ipRestrictionStringOptionalComma-separated list of ips/networks.Only requests from these subnets are allowed, other requests will be rejected with 403 Forbidden response.
geoRestrictionIntegerOptionalComma-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: Matches
ParameterTypeRequiredDescription
ArrayMandatorySee Match for details.
Object: Match
ParameterTypeRequiredDescription
fieldStringMandatoryWhich part of the request to match. Supported values:
req.path - Request path (excluding query string).
req.query - Request query parameters.
req.method - HTTP method (GET, POST, etc.).
client.ip - Client IP address.
req.host - Request host.
req.header.user-agent - User-Agent header.
req.header.cookie - Cookie header.
req.header.origin - Origin header.
req.header.via - Via header.
operatorStringMandatoryDefines how to match the field. Supported values:
startswith - Succeeds if the what matches one of the prefixes listed in patterns.
not_startswith - Matches if field value does not starts with any of the specified prefixes.
istartswith - Case-independent version of startswith.
not_istartwith - Matches if the field value does not starts with any of the specified prefixes, ignoring letter case differences.
regex - Succeeds if what matches one of the regexes listed in patterns.
equals - Succeeds if the what matches one of the strings listed in patterns.
not_equals - Succeeds if the field value does not exactly match any of the specified strings.
iequals - Case-independent version of equals.
not_iequals - Succeeds if the field value does not exactly match any of the specified strings,ignoring letter case differences.
endswith - Succeeds if the what ends with one of the strings listed in patterns. Useful e.g. to match file extensions like ".mp4".
not_endswith - Succeeds if the what does not ends with one of the strings listed in patterns.
iendswith - Case-independent version of endswith.
not_iendswith - Succeeds if the what does not ends with one of the strings listed in patterns,ignoring letter case differences.
subnet - Succeeds if the what belongs to one of subnets, specified in patterns, like "1.222.94.98/32".
not_subnet - Succeeds if the what does not belongs to one of subnets.
Note: subnet operator is applicable only to the client.ip match option.
valuesString[]MandatoryList of values matching the URL path string.

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.
400InvalidPriority.UniquePriority value must be unique.
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.
400InvalidPolicy.MatchesIncorrectThe matches can not be empty or incorrect.
400InvalidPolicy.MatchFieldIncorrectThe match field can not be empty or use the specified value.
400InvalidPolicy.MatchOperatorIncorrectThe match operator required or use the specified value.
400InvalidPolicy.MatchValuesIncorrectThe match values required or can not be empty.
400InvalidPolicy.MatchValueIncorrectAll match values must not be empty.

Response

Response Body

ParameterTypeDescription
policyIdIntegerPolicy ID number for access control.
policyNameStringPolicy name for access control.
typeStringAccess control type, could be "allow", "deny" or "token".
matchesArrayMatching configuration that determines which requests the rule applies to. See Matches 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.
400InvalidPolicy.MatchesIncorrectThe matches can not be empty or incorrect.
400InvalidPolicy.MatchFieldIncorrectThe match field can not be empty or use the specified value.
400InvalidPolicy.MatchOperatorIncorrectThe match operator required or use the specified value.
400InvalidPolicy.MatchValuesIncorrectThe match values required or can not be empty.
400InvalidPolicy.MatchValueIncorrectAll match values must not be empty.

Examples

Edit Access Control V2

Request

PUT /cdn/v1.1/services/{serviceId}/accessControl/{policyId} HTTP/1.1

{
"policyName":"accetss",
"matches":[
{
"field":"req.path",
"operator":"startswith",
"values":["/css/","/images/abc/"]
},
{
"field":"req.method",
"operator":"iequals",
"values":["GET"]
}
],
"priority":41,
"type":"token",
"geoRestriction":"US,CN",
"ipRestriction":"172.16.12.1",
"anonymousIp":true,
"tokenSecret":"bdfy7r6jflo3iydy9zxigkl5m0hte6d423d45dfg6gavo07xvmtc4tzsdc9yxyjy",
"enabled":true
}

Successful Response Body

{
"policyId": 262277,
"policyName": "accetss",
"type": "token",
"matches": [
{
"field": "req.path",
"operator": "startswith",
"values": [
"/css/",
"/images/abc/"
]
},
{
"field": "req.method",
"operator": "iequals",
"values": [
"GET"
]
}
],
"priority": 41,
"ipRestriction": "172.16.12.1",
"geoRestriction": "CN,US",
"anonymousIp": false,
"tokenSecret": "bdfy7r6jflo3iydy9zxigkl5m0hte6d423d45dfg6gavo07xvmtc4tzsdc9yxyjy",
"enabled": true
}