Rule engine and rule configuration

Updated at:
Copy as MD

The EPG rule engine provides fine-grained control over outbound application traffic through three tiers of objects: egress proxy configurations, rule groups, and rules. The rule engine matches requests based on conditions such as destination domain names, URIs, and request headers, and then allows or denies the requests. For allowed requests, you can specify the outbound address pool that serves as the egress. This allows you to meet security compliance and traffic scheduling requirements without building your own proxy clusters.

Three-tier model

Tier

Function

Egress proxy configuration

Defines the default action for each phase and references multiple rule groups by priority to form a complete outbound access control policy. Takes effect after being associated with an instance.

Rule group

A collection of rules referenced by an egress proxy configuration in priority order. Can be associated with an outbound address pool. Requests that match an Allow rule in the PreRequest phase of the group use the IP addresses in the pool as the egress (the default address pool of the instance is used if no pool is associated).

Rule

A single matching rule that includes an effective phase, match conditions, an action, and a priority. When matched, the Allow or Deny action is performed.

Multi-phase rule matching

During the processing of an outbound request, EPG sequentially passes through three phases: PreDns (before DNS resolution), PreRequest (before the request is sent), and PostResponse (after the response is returned). For details about the execution timing and function of each phase, see Execution timing of each phase.

Rules are organized and matched within these three phases. The mechanism works as follows:

  • Phase-based matching: Each rule belongs to a specific phase. When a request enters a phase, only the rules of that phase are evaluated. Currently, rules can be configured only for the PreDns and PreRequest phases.

  • Priority order: Within the same phase, rules are matched in ascending order of priority value (1 to 1000) — first by the priority of the rule group in the egress proxy configuration, then by the priority of the rule within the group. Once a rule is matched, its action (Allow or Deny) is performed and no subsequent rules are evaluated.

  • Multiple conditions (AND logic): A single rule can contain multiple match conditions. The rule is matched only when all conditions are met simultaneously. Different phases support different condition keys (for example, the PreDns phase supports only source IP and destination domain name). For details, see Create a rule.

  • Default action fallback: When a request does not match any rule in a phase, the default action defined for that phase in the egress proxy configuration is performed.

    Important

    If TLS interception is not enabled, HTTPS requests do not enter the PreRequest phase. The rules and default actions of this phase do not take effect on such requests, and the requests are sent directly through the default address pool.

Configure rules

Rules are created within rule groups. A rule takes effect on the outbound traffic of an instance only after the rule group is bound to an egress proxy configuration and that configuration is associated with the instance. When a request matches the rule, the corresponding action is performed.

(Recommended) First verify that the proxy link is available, and then create rule groups and rules and bind them to the egress proxy configuration. Apply outbound controls incrementally so that issues can be identified more quickly when outbound behavior does not meet expectations.

Prerequisites

You have created an EPG instance (an egress proxy configuration is associated during creation), and you need to implement access control on the outbound traffic of the instance by using rules.

1. Create a rule group

  1. Log on to the EPG console. In the left-side navigation pane, choose Rule Group Management > Rule Group List, and then click Create a rule group.

  2. On the Create Rule Group page, configure the following settings and click Create.

    • Rule Group Name: Required. Enter an easily identifiable rule group name.

    • Associated outbound address pool: Optional. Select an outbound address pool. When a request matches an Allow rule in the PreRequest phase of this rule group, the IP addresses in the selected pool are used as the egress. If no pool is selected, the default address pool of the instance is used.

      An outbound address pool belongs to a specific instance. The address pool associated with a rule group must belong to the same EPG instance as the egress proxy configuration to which the rule group is subsequently bound.

2. Create a rule

  1. On the Rule Group List page, click the ID of the target rule group to go to the details page. On the Rule Management tab, in the PreDns phase or PreRequest phase section, click Create a rule. Rules cannot be created for the PostResponse phase.

  2. In the Create Rule dialog box, configure the following settings and click Confirm.

    • Rule Name: Required. Enter an easily identifiable rule name.

    • Priority: Valid values: 1 to 1000. A smaller value indicates a higher priority. Rules are matched in ascending order of priority value. Priority values must be unique within the same phase of the same rule group. As a best practice, assign a smaller priority value (higher priority) to rules with more specific conditions to make sure they are matched first.

    • Matching Condition: Configure the traffic characteristics that the rule matches. Click Add condition to add multiple conditions. Multiple conditions have an AND relationship (all must be met), and the combination of Condition Key and Match Type must be unique.

      • Condition Key: Specifies which part of the request to match, such as destination domain name, source IP address, or HTTP request header.

      • Match Type: The comparison rule between the Condition Key and the Condition Value, which determines when a request is considered matched. When multiple Condition Value entries are specified for the same condition, match-type operators (such as "matches" or "equals") require only one value to match, while non-match-type operators (such as "does not match" or "not equals") require all values to not match.

      • Condition Value: The specific value corresponding to the Condition Key. You can specify multiple values for the same condition, separated by commas (,).

      Important

      If TLS interception is not enabled on the instance, for HTTPS requests, the client establishes an end-to-end encrypted tunnel with the destination server through EPG by using the CONNECT method. EPG only passes through the traffic and cannot parse the request content within the tunnel. In this case, HTTPS requests do not enter the PreRequest phase. The rules and default actions of this phase do not take effect on such requests, and the requests are sent directly through the default address pool. To control HTTPS traffic, enable TLS interception. If you need to control traffic only by source IP address or destination domain name, configure rules in the PreDns phase.

      Supported condition keys

      Condition key

      Supported phases

      Description

      Source ip address

      PreDns, PreRequest

      The IP address or CIDR block of the client that initiates the request, such as 192.168.0.0/16.

      Target domain name

      PreDns, PreRequest

      The destination domain name of the request, such as api.example.com.

      Request Protocol

      PreRequest

      The protocol type of the request, such as HTTP or HTTPS.

      HTTP URI path

      PreRequest

      The URI path of the request, such as /api/v1/data.

      HTTP request method

      PreRequest

      The HTTP request method, such as GET, POST, PUT, or DELETE. Case-insensitive.

      HTTP User-Agent

      PreRequest

      The User-Agent string of the client.

      HTTP request content type

      PreRequest

      The Content-Type of the request, such as application/json.

      HTTP custom request header

      PreRequest

      An HTTP request header with a specified name. After you select this condition key, you must also specify the request header name, such as x-auth-token.

    • Action: Select Allow or Deny. The behavior of each action varies by phase:

      • PreDns phase: Allow indicates that the request is allowed to proceed to subsequent processing. Deny indicates that the request is intercepted before DNS resolution.

      • PreRequest phase: Allow indicates that the request is allowed, and the IP addresses in the outbound address pool associated with the rule group are used as the egress (the default address pool of the instance is used when no pool is associated). Deny indicates that the request is intercepted and no connection to the destination server is established.

3. Bind the rule group to an egress proxy configuration

A rule group takes effect only after it is bound to an egress proxy configuration. Bind the rule group to the target egress proxy configuration and set the priority. For details, see Bind a rule group.

Configuration examples

The following examples demonstrate only the rule configuration itself. Unless otherwise specified, the default action for each phase in the egress proxy configuration is Allow.

Example 1: Allow access only to a specific path on a specific domain

Important

Before you configure this example, make sure that TLS interception is enabled on the instance. Otherwise, HTTPS requests do not enter the PreRequest phase and are sent directly through the default address pool, which causes the whitelist to fail.

Allow applications to access only the /v1/chat/completions path on api.example.com and deny all other outbound requests.

  1. In the egress proxy configuration, set the default action of the PreRequest phase to Deny so that requests not explicitly allowed are denied by default (whitelist mode).

  2. Create a rule group. In the PreRequest phase of the rule group, create a rule with the Action set to Allow and add the following two match conditions:

    Condition Key

    Match Type

    Condition Value

    Target domain name

    Equals

    api.example.com

    HTTP URI path

    Equals

    /v1/chat/completions

  3. Bind the rule group to the target egress proxy configuration to activate the rule. Whitelist mode works by denying all requests by default and allowing only explicitly matched requests. Make sure that other rule groups under the same configuration do not allow requests outside the scope specified by this rule group in the PreRequest phase, which would cause access control to fail.

The two conditions have an AND relationship and must both be met for the rule to match. Requests that match both the domain name and the path are allowed. All other requests do not match any Allow rule and are subject to the default action (Deny) of the PreRequest phase.

Example 2: Assign a dedicated egress address to a specific tenant

Forward requests that carry the custom request header x-tenant-id: tenant-001 through a dedicated outbound address pool to achieve tenant-level egress address isolation.

  1. Create a rule group and select the dedicated address pool for the tenant in Associated outbound address pool.

  2. In the PreRequest phase of the rule group, create a rule with the Action set to Allow and add the following match condition:

    Condition Key

    Match Type

    Request header name

    Condition Value

    HTTP custom request header

    Equals

    x-tenant-id

    tenant-001

  3. Bind the rule group to the target egress proxy configuration. If multiple rule groups are already bound to the configuration, make sure this rule group has a higher priority (a smaller priority value) so that requests carrying the x-tenant-id header match this rule first and use the dedicated address pool.

Requests that match this rule use the IP addresses in the outbound address pool associated with the rule group as the egress, achieving egress address isolation based on tenant ID.

Manage rule groups and rules

  • Associate or change the outbound address pool: Click the ID of the target rule group to go to the details page. Click Edit next to Associated outbound address pool, select the target address pool, and confirm. The address pool must belong to the same instance as the egress proxy configuration to which the rule group is bound.

  • Create, modify, or delete rules: Click the ID of the target rule group to go to the details page. On the Rule Management tab, perform the following operations:

    • Create a rule: In the PreDns phase or PreRequest phase section, click Create a rule. After you complete the configuration, click Confirm. For details, see Create a rule.

    • Modify a rule: Click Edit in the Operation column of the target rule. After you make the changes, click Save.

    • Delete a rule: Click Delete in the Operation column of the target rule and confirm. Alternatively, select multiple rules in the same phase and click Batch Delete to confirm.

  • Delete a rule group: On the Rule Group List page, click Delete in the Operation column of the target rule group and confirm. A rule group that is bound to an egress proxy configuration cannot be deleted directly. You must first unbind it from the egress proxy configuration.

Limits

Limit item

Maximum value

Number of rule groups per account per region

100

Number of rule groups that can be bound to each egress proxy configuration

10

Number of rules per rule group

100

When matching conditions are added to a rule, the total length of all condition values in each matching condition

3,072 bytes