Updated on 2023-12-21 GMT+08:00

CFW Custom Policies

Custom policies can be created to supplement the system-defined policies of CFW. For details about the actions supported by custom policies, see CFW Permissions and Supported Actions.

You can create custom policies in either of the following ways:

  • Visual editor: Select cloud services, actions, resources, and request conditions. This does not require knowledge of policy syntax.
  • JSON: Edit JSON policies from scratch or based on an existing policy.

For details, see Creating a Custom Policy. The following section contains examples of common CFW custom policies.

CFW Example Custom Policies

  • Example 1: Allowing users to create a CFW instance
    {
            "Version": "1.1",
            "Statement": [
                    {
                            "Effect": "Allow",
                            "Action": [
                                    "cfw:instance:create"
                                                           ]
                    }
            ]
    }
  • Example 2: Not allowing users to remove items from a blacklist or whitelist

    A deny policy must be used together with other policies. If the permissions assigned to a user contain both "Allow" and "Deny", the "Deny" permissions take precedence over the "Allow" permissions.

    The following method can be used if you need to assign permissions of the CFW FullAccess policy to a user but also forbid the user from deleting web tamper protection rules (cfw:blackWhite:delete). Create a custom policy with the action to delete web tamper protection rules, set its Effect to Deny, and assign both this policy and the CFW FullAccess policy to the group the user belongs to. Then the user can perform all operations on CFW except removing items from a blacklist or whitelist. Example:

    {
            "Version": "1.1",
            "Statement": [
                    {
                            "Effect": "Deny",
                            "Action": [
                                    "cfw:blackWhite:delete"                                
                            ]
                    },
            ]
    }
  • Multi-action policy

    A custom policy can contain the actions of multiple services that are of the project-level type. The following is an example policy containing actions of multiple services:

    {
            "Version": "1.1",
            "Statement": [
                    {
                            "Effect": "Allow",
                            "Action": [
                                    "cfw:instance:get",
                                    "cfw:eipStatistics:get"
                            ]
                    },
                   {
                            "Effect": "Allow",
                            "Action": [
                                    "hss:hosts:switchVersion",
                                    "hss:hosts:manualDetect",
                                    "hss:manualDetectStatus:get"
                            ]
                    }
            ]
    }