Create and apply a service policy
Overview
A service policy contains one or more rules that match incoming requests based on criteria such as source IP, HTTP path, headers, or client identity. When a request matches a criterion, the system takes an action configured in the policy (allow, deny, or pass to the next policy). The system evaluates policies and rules within each policy in order: the first matching rule in the first matching policy determines the outcome. If no policy matches, the system denies the request.
You can configure a service policy in three different namespaces: system, shared, and app. The following information shows how to configure a service policy for an app namespace.
Before you begin
Before you begin, verify that you have:
- An active F5 Distributed Cloud Services account. If you don’t have an account, see Get Started with Distributed Cloud Console.
- A load balancer. If you don't have a load balancer, see Create HTTP Load Balancer.
- Optionally, one or more cloud or edge locations with a Distributed Cloud Services site. Install the node or cluster image using the Site Management guides.
Create a service policy
To create and apply a service policy to your application, log in to the F5 Distributed Cloud Console and complete the following steps.
-
From the Distributed Cloud Console home page, select Multi-Cloud App Connect.
-
Select an existing namespace from the Namespace drop-down menu. If you need to add a new namespace, see Create a namespace.
-
Select Security > Service Policies > Service Policies.
-
Select Add Service Policy, and enter the following information:
- Enter a Name for the new service policy. This name must be unique within the namespace and entered in RFC 1035 format. For example, enter
acmecorp-web. - Optionally, select one or more labels. For each label, select a key and corresponding value.
- Optionally, enter a description for the new policy.
- Enter a Name for the new service policy. This name must be unique within the namespace and entered in RFC 1035 format. For example, enter
-
From the Server Selection drop-down menu, select the servers to which this policy applies. If you select Any Server (the default), the policy applies to whichever load balancer it is attached with no additional filtering. The other options let you restrict the policy so that it only takes effect for requests directed at specific servers:
- Any Server: The policy applies to whichever load balancer it is attached. No additional server-level filtering is performed.
- Server Name: Restrict the policy to requests where the server name matches a specific value. The server name is derived from the HTTP Host header, the virtual host name, or the TLS SNI. Enter the expected server name in the Server Name box.
- Group of Servers by Name: Restrict the policy to requests where the server name matches any value in a list. Select Add to add Exact Values or Regex Values for server names.
- Group of Servers by Label Selector: Restrict the policy to servers with labels that match a selector expression. In the Selector Expression box, select Add Label. For each label you want to add:
- Select a key, operator and value from the drop-down lists.
- Select Apply. If this is the last label, select outside the Selector Expression box or press the tab or esc key.
Note: Only known label keys can be used in this box. These include system-defined keys (for example,
ves.io/app_type) and any keys your tenant has created as known label keys. Arbitrary label keys aren't supported. -
In the Rules section, create rules that determine how incoming requests are handled.
From the Select Policy Rules drop-down menu, select one of the following options:
Allow All Requests or Deny All Requests
Select Allow All Requests or Deny All Requests to allow or deny all requests sent to the server.
- Select Allow All Requests or Deny All Requests.
- Select Add Service Policy to save the new policy.
Next steps:
Apply the security policy to an HTTP load balancer. See Apply a service policy.
Allowed Sources or Denied Sources
Define which client sources are allowed or denied. You can include multiple categories in your list.
For example, if you select Allowed Sources and configure both the IPv4 Prefix List and a Country List, the result allows any requests to your server from any of the IPv4 addresses or any of the countries listed.
-
Select from the following criteria:
- IPv4 Prefix List: Create a list of IPv4 prefixes to match against client source addresses.
- Select Configure and then select Add to enter an IPv4 prefix. Select Add again to add additional IPv4 prefixes.
- After you finish adding entries, select Apply.
- IP Prefix Set: Select Add and then use the drop-down menu to select an existing set of IPv4 prefixes or select Add to create a new set. You can add multiple sets of IP prefixes.
- BGP ASN List: Create a list of BGP ASNs to match against client source ASNs.
- Select Configure and then enter a BGP ASN. Select Add to add additional BGP ASNs.
- After you finish adding entries, select Apply.
- BGP ASN Set: Select Add and then use the drop-down menu to select an existing set of BGP ASNs or select Add to create a new set. You can add multiple sets of BGP ASNs.
- Country List: Create a list of countries. Addresses that belong to one of the countries are allowed or denied. Select one or more countries from the drop-down list.
- TLS Fingerprint Classes: Create a list of TLS Fingerprint Classes to match against the TLS JA3 fingerprint of a request.
- Order TLS Fingerprint Values: Create a list of TLS JA3 fingerprints to compare against the TLS JA3 fingerprint of a request. Select Add and enter a fingerprint value. You can use the See Common Values to select from a list of common TLS values.
- IPv4 Prefix List: Create a list of IPv4 prefixes to match against client source addresses.
-
Use the Default Action menu to specify what happens when a request doesn't match any of the criteria above:
- Next Policy: Allows your load balancer to evaluate the source request using the next service policy.
- Allow or Deny: Allows or denies the source request.
-
Select Add Service Policy to save the new service policy.
Next steps:
Apply the security policy to an HTTP load balancer. See Apply a service policy.
Custom Rule List
Create a list of custom rules that determine how your HTTP load balancers respond to requests to your servers.
Important: Custom rules aren't saved until you select Apply to save the rule and then select Apply again to save the rule set.
- In the Rules section, select Configure, and then select Add.
- Enter a Name for the rule and optionally add a Description.
Configure a rule action
In the Action section, select the following rule action options:
- From the Action drop-down menu, select an action to be enforced (Allow, Deny, or Next Policy) if the input request matches the rule. If you selected Next Policy, the service takes no action and does not evaluate any more rules in this policy. The service moves on to match the input against the next security policy in the policy set.
- Optionally, select Log Rule Evaluation. When selected, the rule operates in observation mode: if the request matches, the match is logged but the action (Allow/Deny) is not enforced. Evaluation continues with the remaining rules in the sequence.
- From the Select App Firewall Action Type drop-down menu, select one of the following options:
- Do not modify App Firewall Processing: Performs normal app firewall processing for the request.
- Skip App Firewall Processing: Skips all app firewall processing for the request.
- App Firewall Detection Control: Define a list of signature IDs, violations, attack types and bot names that you want to exclude from matching the criteria you defined. Select Add in each category where you want to add entries.
- From the Select Bot Action Type drop-down menu, decide if you want to perform normal bot processing for the request or if you want to Skip Bot Processing.
- From the Malicious User Mitigation Action drop-down menu, decide if you want to apply default mitigation actions to this request or if you want to Skip Processing the mitigation actions.
Apply the rule to specific clients
In the Clients section, specify the clients to which this rule applies.
- From the Client Selection drop-down menu, select how you want to apply the rule to clients:
-
Any Client: The rule applies to all clients.
-
Client Name: Enter a specific name for the client to which you want to apply this rule.
-
Group of Clients by Name: Select Add to enter client names. Enter Exact Values or Regex Values (regular expressions). Select Add again to enter more than one value.
-
List of IP Threat Categories: Select one or more categories from the menu provided. The service matches clients in a category against the rule criteria.
-
Group of Clients by Label Selector: Select a label key, an operator, and a value if required, and then select Apply.
For example, select ves.io/country In (ves-io-can) to match any client in Canada. You can add multiple labels. When you finish, press the tab key or select outside the area to complete the expression.
-
- From the Source IP Match drop-down menu, select one of the following options:
- Any Source IP: Matches any source IP address.
- IP Prefix List: Enter an IP prefix. Select Add to enter additional IP prefixes. The rule is applied if the origin IP address is covered by one of the IP prefixes in your list. To reorder your list, select the Actions column.
- IP Prefix Sets: Select an IP prefix set from the drop-down menu. Select Add to select another IP prefix set. To reorder your sets, select the Actions column.
- From the Source ASN Match drop-down menu, select one of the following options:
- Any Source ASN: Matches any origin ASN.
- ASN List: Enter an ASN. Select Add to enter additional ASNs. The rule is applied if the origin ASN matches an ASN in your list. To reorder your list, select the Actions column.
- BGP ASN Sets: Select a BGP ASN set from the drop-down menu. Select Add to select another BGP ASN set. To reorder your sets, select the Actions column.
- From the TLS Fingerprint Matcher drop-down menu, select whether you want to match clients to a JA4 TLS Fingerprint or a JA3 TLS Fingerprint. Then select Configure and select Add to add TLS fingerprints you want to match.
- From the Source Segments drop-down menu, select the source segments where you want the rule to apply. Select one of the following options:
- Any: The rule applies to traffic from any source segment. Source segments aren't used for matching.
- Segments: Select the segments against which you want to match source traffic. From the drop-down menu, select a segment or select Add to create a new segment. Select Add to add additional segments.
Apply the rule to specific server domains
- In the Servers section, select Add and enter Exact Values or Regex Values (regular expressions) to match the destination domain of a request. For example, enter
internal.example.com. The rule matches requests whose destination domain matches one of these values. - From the Transformers drop-down menu, select a list of transformers you want to apply to your domain matchers before matching.
- To select a port range to which the destination port should belong, in the Port Matcher section, select Configure. Then select Add and enter a port number or start and end values for a range of port number separated by “-“. For example, enter
0-1023. After you finish adding port numbers, select Apply. - Select Invert Port Matcher to match all ports except those in the Port Ranges list.
Apply the rule to specific requests
-
In the Request Match section, enter the types of requests that you want to match with this policy rule. You can specify the request type in a number of different ways:
- HTTP Method: Select the HTTP methods you want to match from the Method List drop-down. You can select multiple methods.
- Invert Method Matcher: Select to match only the HTTP methods you didn't select. When selected, the methods you selected above aren't matched.
- HTTP Path:
- Select Configure
- Select Add and enter Prefix Values, Exact Values, Regex Values (regular expressions), or Suffix Values for an HTTP path.
- From the Transformers drop-down menu, select a list of transformers you want to apply to the HTTP path for easier matching.
- Select Invert Path Matcher to match only the HTTP paths you didn't select. When selected, the paths you added above aren't matched.
- Select Match Encoded Path to match the URL-encoded form of the request path.
- After you finish, select Apply.
- HTTP Query Parameters:
- Select Add and then enter a Query Parameter Name.
- Use the Match Options drop-down menu to select one of the following options:
- Present or Not Present: Matches if that parameter name is or isn't present in the request.
- Match Values: Select Add to enter Exact Values or Regex Values (regular expressions) to match against. You can add either or both types of values.
- From the Transformers drop-down menu, select a list of transformers you want to apply to the query parameter for easier matching.
- Select Invert Query Parameter Matcher to match all query parameters except those you added.
- After you finish, select Apply.
- HTTP Headers:
- Select Add and then enter a Header Name.
- Use the Match Options drop-down menu to select one of the following options:
- Present or Not Present: Matches if that header name is or isn't present in the request.
- Match Values: Select Add to enter Exact Values or Regex Values (regular expressions) to match against. You can add either or both types of values.
- From the Transformers drop-down menu, select a list of transformers you want to apply to the header for easier matching.
- Select Invert Header Matcher to match all headers except those you added.
- After you finish, select Apply.
- JWT Claims:
- Select Add and then enter a JWT Claim Name.
- Use the Match Options drop-down menu to select one of the following options:
- Present or Not Present: Matches if that JWT Claim name is or isn't present in the JWT payload.
- Match Values: Select Add to enter Exact Values or Regex Values (regular expressions) to match against. You can add either or both types of values.
- From the Transformers drop-down menu, select a list of transformers you want to apply to the JWT claim for easier matching.
- Select Invert Matcher to match all JWT claims except those you added.
- After you finish, select Apply.
- Cookie Matchers:
- Select Add and then enter a Cookie Name.
- Use the Match Options drop-down menu to select one of the following options:
- Present or Not Present: Matches if that cookie name is or isn't present in the request.
- Match Values: Select Add to enter Exact Values or Regex Values (regular expressions) to match against. You can add either or both types of values.
- From the Transformers drop-down menu, select a list of transformers you want to apply to the cookie name for easier matching.
- Select Invert Matcher to match all cookies except those you added.
- After you finish, select Apply.
- Argument Matchers:
- Select Add and then enter an Argument Name.
- Use the Match Options drop-down menu to select one of the following options:
- Present or Not Present: Matches if that POST argument is or isn't present in the request.
- Match Values: Select Add to enter Exact Values or Regex Values (regular expressions) to match against. You can add either or both types of values.
- From the Transformers drop-down menu, select a list of transformers you want to apply to the argument for easier matching.
- Select Invert Matcher to match all POST arguments except those you added.
- After you finish, select Apply.
-
In the Request Body Matcher section, select Add to enter Exact Values or Regex Values in the body of a request that you want to match with this policy rule.
From the Transformers drop-down menu, select a list of transformers you want to apply to your request body matchers before matching.
-
In the Request Constraints section, configure limits on requests based on the request attributes. Requests match if any attribute sizes exceed the specified maximum values.
- Select Configure.
- In the Cookie Constraints, Header Constraints, Parameter Constraints, and Other Constraints sections, select Match If Exceeds. The recommended value automatically populates. You can also enter your own value.
Note: For Cookie Constraints, internal cookies are included in the count and processed based on the configuration options. For Header Constraints, internal headers are included in the count and processed per the configuration options. The body of each POST request is parsed for parameters when the Content-Type is
application/x-www-form-urlencoded. For the Max Request Size option, the match is based on the size of the request (as in Request Line plus HTTP Request Headers). This doesn't include the request body. - After you finish, select Apply.
-
In the Advanced Match section, optionally perform the following:
- In the Keys section, select Add to enter label keys that must be the same for the client and server, such as "environment" or "location." Enter only the key, not a value. The rule matches a request only when the client and the server have the same value for every key listed.
- In the API Group Matcher section, enter a list of API group names to which the API request must belong to match.
- Select Configure and then select an API group name from the Exact Values drop-down menu. Select Add to add another entry.
- Select Invert String Matcher to match all API group names except the ones you selected.
- After you finish, select Apply.
-
In the Expiration Timestamp box, enter a timestamp at which you want your custom rule to expire. You must use RFC 3339 format. When the rule expires, you can still see the rule, but the system no longer applies the rule.
-
In the User Identity Matcher section, select Add and enter Exact Values or Regex Values to match the user identifier assigned to the request. The identifier comes from the User Identification policy on the load balancer, and it starts with a prefix that shows its type. For example, IP-203.0.113.10 for client IP, Header-X-User-alice for an HTTP header, or JWTClaim-sub-12345 for a JWT claim.
-
After you finish select Apply. To add another rule, select Add.
-
After you complete the custom rule specification, select Apply.
Determine rule order and save your policy
- After you create your custom rules, you can choose the order in which the service policy evaluates them. If you have multiple service policies enabled on the same load balancer, you can choose the order in which the load balancer evaluates them.
- Select Add Service Policy to save the new policy.
Next steps:
Apply the security policy to an HTTP load balancer. See Apply a service policy.
Apply a service policy
You can make service policies active for your application namespace so they're all automatically applied to your load balancer. Or you can apply one or more specific service policies to the load balancer. On your HTTP load balancer, you select one of the following options:
- Apply Namespace Service Policies: All active service policies in your application namespace are enabled on the load balancer. For information, see Set active service policy.
- Apply Specified Service Policies: Only specific service policies that you select are applied to the load balancer. For information, see Apply a specific service policy to a load balancer.
The order of service policies and the order of rules within a service policy matter. It is important to plan the ordering of your service policies and rules to get the effect you intend. When the load balancer receives a request, it evaluates the request characteristics based on the match criteria in each service policy starting with the first policy in your list.
- If there is a match in the first policy, then that policy takes effect and the load balancer doesn't evaluate any additional policies.
- If there is no match in the first policy, then the load balancer evaluates the next policy in the list.
- If all policies are evaluated and none match, then the request is blocked by default.
For example, in the policy list below, the last policy, ves-io-allow-all, allows all traffic through. This setup relies on matches to prior policies to deny undesired traffic. In the case below, all policies above ves-io-allow-all deny a request for some reason, except allowed-ips. The service policy allowed-ips allows certain IP addresses through without enforcing any of the following service policies. If you were to move allowed-ips below method-enforcement, then allowed-ips is still subject to blocking if the request uses a disallowed HTTP method.

Figure: List of Service Policies
Set active service policy
Note: In the Common Security Controls section of your HTTP load balancer, from the Service Policies drop-down menu, you must select Apply Namespace Service Policies.
To enable all active service policies in your application namespace on the load balancer, do the following:
- From the Multi-Cloud App Connect navigation menu, select your namespace.
- Select Security > Service Policies > Active Service Policies.
- Select Manage Active Service Policies. This displays a list of active service policies available for the given namespace. The list may be empty.
- To add a new service policy to the active list, select Add.
- From the Service Policies drop-down menu, select your service policy. Select Add again to add more service policies to the list.
- To change the order in which active service policies are evaluated in a namespace, do one of the following:
- Use the drag handle to drag and drop the rules up or down in the list.
- In the Actions column, select the Action menu (...) and then select Move to another spot. The load balancer evaluates policies at the top of the list first.
- After you finish adding service policies, select Save Active Service Policies.
Apply a specific service policy to a load balancer
Note: In the Common Security Controls section of your HTTP load balancer, from the Service Policies drop-down menu, you must select Apply Specified Service Policies. You can apply as many service policies as necessary.
To apply service policies, do the following:
- To edit your load balancer, select Manage > Load Balancers > HTTP Load Balancers.
- From the Actions column for your load balancer, select the Action (...) menu.
- Select Manage Configuration and then select Edit Configuration.
- In the Common Security Controls section, from the Service Policies drop-down menu, select the Apply Specified Service Policies option.
- Select Configure.
- From the Policies menu, select a service policy. Select Add to add more service policies.
- If you added more than one service policy, to change the order in which active service policies are evaluated in a namespace, do one of the following:
- Use the drag handle to drag and drop the rules up or down in the list.
- In the Actions column, select the Action menu (...) and then select Move to another spot. The load balancer evaluates policies at the top of the list first.
- After you finish adding and moving security policies, select Apply.
- If you're finished with load balancer configuration, select Save HTTP Load Balancer.