Creating a WAF profile
- In the management console
, select the folder where you want to create a WAF profile. - Navigate
to Smart Web Security. - In the left-hand panel, select WAF profiles and click Create WAF profile.
- Name the profile.
- Optionally, provide a description.
- Optionally, add labels to your profile.
- Enable one or multiple rule sets. OWASP Core Rule Set
, Yandex Ruleset, Yandex ML Ruleset. Click the row with the rule set to view its rules. - Select a rule set version.
-
If multiple rule sets are enabled:
-
Select the profile trigger conditions:
Verdict DENY returned in at least one selected rule set: At least one rule set has recognized the request as a threat.Verdict DENY returned in each selected rule set: All added rule sets have recognized the request as a threat.
-
Arrange rule sets in the order of priority in which the rules will analyze the request. Top positions indicate higher priority.
-
- Click Create.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the guides on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), authenticate using the appropriate method.
-
In the configuration file, define the parameters of the resources you want to create:
locals { # In the basic set, rules of this paranoia level and below will be enabled waf_paranoia_level = <paranoia_level> } # Data source: rule set data "yandex_sws_waf_rule_set_descriptor" "source" { name = "<set_name>" version = "<set_version>" } # WAF profile resource "yandex_sws_waf_profile" "default" { name = "<WAF_profile_name>" # Rule set rule_set { action = "<action>" is_enabled = <true_or_false> priority = <priority> # Basic rule set core_rule_set { inbound_anomaly_score = <anomaly_threshold> paranoia_level = local.waf_paranoia_level rule_set { name = "<set_name>" version = "<set_version>" id = "<set_ID>" type = "<set_type>" } } } # Enabling rules from the basic set if their paranoia level is not higher than the value defined in the waf_paranoia_level variable dynamic "rule" { for_each = [ for rule in data.yandex_sws_waf_rule_set_descriptor.source.rules : rule if rule.paranoia_level <= local.waf_paranoia_level ] content { rule_id = rule.value.id is_enabled = true is_blocking = false } } }Example of a WAF profile description in the Terraform configuration
# Declaring local variables locals { # In the basic set, rules of this paranoia level and below will be enabled waf_paranoia_level = 1 # OWASP Core Ruleset identification ruleset_name = "OWASP Core Ruleset" ruleset_version = "4.0.0" ruleset_id = "OWASP_CRS_4_0_0" ruleset_type = "CORE" } # OWASP Core Rule Set data source data "yandex_sws_waf_rule_set_descriptor" "source" { name = local.ruleset_name version = local.ruleset_version } # WAF profile resource "yandex_sws_waf_profile" "default" { name = "waf-profile-owasp" # Rule set rule_set { action = "DENY" is_enabled = true priority = 1 # Basic rule set core_rule_set { inbound_anomaly_score = 2 paranoia_level = local.waf_paranoia_level rule_set { name = local.ruleset_name version = local.ruleset_version id = local.ruleset_id type = local.ruleset_type } } } # Enabling rules from the basic set if their paranoia level is not higher than the value defined in the waf_paranoia_level variable dynamic "rule" { for_each = [ for rule in data.yandex_sws_waf_rule_set_descriptor.source.rules : rule if rule.paranoia_level <= local.waf_paranoia_level ] content { rule_id = rule.value.id is_enabled = true is_blocking = false } } }Where:
-
waf_paranoia_level: Level of paranoia. It classifies rules based on their level of aggressiveness. The higher the paranoia level, the better the protection, but also the greater the risk of WAF false positives. The possible values range from 1 to 4. -
data "yandex_sws_waf_rule_set_descriptor": Terraform data source for the basic rule set. From the data source, you can get a list of rules and their IDs. -
resource "yandex_sws_waf_profile": Terraform resource to manage the WAF profile.-
name: WAF profile name. -
rule_set: Rule section.-
action: Action to perform when the rule set is triggered:RULE_SET_ACTION_UNSPECIFIED: Allow the query.DENY: Block the query.CAPTCHA: Send the query to SmartCaptcha.
-
is_enabled: Flag to enable or disable a set of rules. -
priority: Rule set priority. The possible values range from 1 to 1,000,000. -
core_rule_set: Basic rule set:-
inbound_anomaly_score: Anomaly threshold which is the total anomaly score of triggered rules that results in blocking the request. The possible values range from 2 to 10,000. The higher the value, the more likely it is that the request matching the rules is in fact an attack. -
paranoia_level: Level of paranoia. It classifies rules based on their level of aggressiveness. The higher the paranoia level, the better the protection, but also the greater the risk of false positives. The possible values range from 1 to 4.Note
The paranoia level does not affect whether rules are enabled or disabled. It only recommends the user to enable all rules with the
paranoia_levelless than or equal to the specified one. -
rule_set: Rule set. In this section, specify the ID, name, version, and type of the rule set.Possible values
name version id type OWASP Core Ruleset4.8.0OWASP_CRS_4_8_0COREOWASP Core Ruleset4.0.0OWASP_CRS_4_0_0COREYandex Ruleset0.1.1YARS_0_1_1YAYandex Ruleset0.1.0YARS_0_1_0YAYandex ML RulesetlatestYAMS_LATESTML
-
-
-
dynamic "rule": Dynamic activation of the basic set rules if their paranoia level is not higher than thewaf_paranoia_levelvariable. For dynamically configured rules, you can update settings manually. For example, you can turn a rule into a blocking one or enable a rule with the paranoia level higher than the one defined in the variable.rule_id: Rule ID.is_enabled: Flag to enable or disable a rule.is_blocking: Blocking rule flag. Iftrue, the rule becomes the blocking one.
-
For more on the properties of the
yandex_sws_waf_profileresource, see this provider guide. -
-
Create the resources:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
-
Terraform will create all the required resources. You can check the update of the resources in the management console
After creating a WAF profile, you can modify the set of basic rules and customize the set of exception rules.
Use the create REST API method for the WafProfile resource or the WafProfile/Create RPC API call.