Implementing rules in your firewall using Rules Engine will allow you to determine the rules it should execute in specific scenarios.
This guide demonstrates the process of creating a rule with a practical example of verifying the existence of a certificate and returning a custom response when there isn’t one. This behavior is useful in scenarios such as adjusting your policies to comply with BACEN requirements.
To create a rule:
- Access Azion Console > Firewall.
- Select the firewall in which you want to configure the rule.
- Click the Rules Engine tab.
- Click the + Rule button.
- Give your rule a name and, optionally, a description.
- In the Criteria section, select the
SSL Verification Statusvariable. - As a comparison operator, select
is esqual. - As an argument, select
Missing Client Certificate. - In the Behaviors section, select Set Custom Response.
- As arguments:
- On Status Code, add
401. - On Content Type, add the content and header description. Example:
application/json. - On Content Body, pass the message you want to present to users.
- On Status Code, add
- Click the Save button.
- Run the following
POSTrequest to create a rule, replacing[TOKEN VALUE]with your personal token and the<edge_firewall_id>variable with your firewall id value:
curl --request POST --url https://api.azion.com/v4/edge_firewall/firewalls/<edge_firewall_id>/request_rules --header 'Accept: application/json' --header 'Authorization: Token [TOKEN VALUE]' --header 'Content-Type: application/json' --data '{ "name": "SSL Verification", "active": true, "criteria": [ [ { "conditional": "if", "variable": "${ssl_verification_status}", "operator": "is_equal", "argument": "MISSING_CLIENT_CERTIFICATE" } ] ], "behaviors": [ { "type": "set_custom_response", "attributes": { "status_code": 401, "content_type": "application/json", "content_body": "{}" } } ]}'| Key | Description |
|---|---|
name | Name of the rule |
description | Description of the rule |
behaviors | Array that stores objects that define behaviors |
criteria | Array that stores objects that define criteria |
See the Azion API documentation to find out more about criteria and behavior objects.
- You’ll receive the following response:
{"results": { "name": "SSL Verification", "is_active": true, "behaviors": [ { "status_code": 401, "content_body": "{}", "name": "set_custom_response", "content_type": "application/json" } ], "criteria": [ [ { "variable": "ssl_verification_status", "operator": "is_equal", "conditional": "if", "argument": "MISSING_CLIENT_CERTIFICATE" } ] ], "last_modified": "2023-11-23T23:54:14.941097Z", "last_editor": "your-email@example.com", "id": <id>, "order": 2},"schema_version": 3}- Wait a few minutes for the changes to propagate.