Configuring logging via Smart Web Security
This method provides detailed logs of request checks by security rules, WAF, and ARL. In the profile, you can select the rule types and verdicts to be logged. Logging via Application Load Balancer saves the load balancer's HTTP requests along with the result of the Smart Web Security check.
To write logs, Smart Web Security integrates the following services:
- Monium Logs: For security profile logs. The logs contain information about HTTP requests and triggered rules, including WAF and ARL, and are stored in Monium projects.
- Audit Trails: Collects Smart Web Security audit events. These are records of security events and actions with resources.
Audit logs
There are two types of events in Audit Trails:
- Management events, which include actions related to Yandex Cloud resource configuration, such as creating or deleting a security profile.
- Data events, which include actions performed on resources within Yandex Cloud services, e.g., triggering a rule from a WAF profile.
Events can be written to an Object Storage bucket, a Monium project, or a data stream in Data Streams.
Logs of HTTP requests and triggered rules
Request verification logs can be written via the Smart Web Security profile to Monium Logs or via the L7 Application Load Balancer to Cloud Logging. Logging via a security profile provides more analysis options.
Security profile logs are sent to the folder__<directory_id> Monium project, which specifies the ID of the directory containing the profile. You can view logs in the Smart Web Security or Monium UI.
Logs from proxy servers and L7 load balancers are sent to the selected log group in Cloud Logging. Proxy server logs are also available in the Smart Web Security UI, and load balancer logs, in the Application Load Balancer UI.
Log analysis enables you to configure and monitor Smart Web Security performance:
- Test security rules, WAF, and ARL in Logging only (dry run) mode. In this mode, the system does not block user requests but logs rule matches.
- View the number of blocked and allowed requests, evaluate and adjust rule performance.
- View detailed request information and identify false positives.
In some cases, traffic may be blocked during attacks. When this happens, the logs will include the sws_service_rule service rule label.
Working with logs
To get started with Smart Web Security logs:
Enable logging
Logging can be enabled when creating a security profile or proxy server, as well as when editing them.
Note
To configure logging in a security profile, you need the smart-web-security.editor role on the folder containing the profile. To view logs in Monium, you need a role with log read permissions.
-
In the management console
, select the folder containing the Smart Web Security profile. -
Navigate
to Smart Web Security. -
In the left-hand panel, select Security profiles.
-
In the row with the profile you need, click
and select Edit. -
Enable Write logs.
-
In the Send logs to field, select Monium.
-
Configure the log filters:
-
Under Log requests for rules, select the rule types:
- Base rules.
- Smart Protection.
- Web Application Firewall.
- Advanced Rate Limiter.
-
Under Log requests with verdict, select the verdicts:
- ALLOW.
- DENY.
- Sent for challenge: CAPTCHA or JS challenge.
-
For requests with the
ALLOWverdict, specify the percentage of logs to skip in the How many logs with the ALLOW verdict should not be recorded field:0%to log all requests, and100%to log none.
-
-
Click Save.
-
In the management console
, select the folder containing the proxy server. -
Navigate
to Smart Web Security. -
In the left-hand panel, select Domain security.
-
In the row of the proxy server in question, click
and select Edit. -
Enable Log requests.
-
Select the Cloud Logging log group to write logs to or create a new one.
-
Optionally, to reduce the volume of logs, create a discard rule:
- Under Add rule, click Rules for discarding logs.
- Select HTTP codes or HTTP code classes for which you want to reduce log entries.
- Specify the share of logs to discard, ranging from
0%(all logs are recorded) to100%(no logs are recorded).
For other HTTP codes, add separate rules.
-
Click Save.
Configure the logging of Smart Web Security events to an Object Storage bucket. Before creating a trail, prepare a bucket and service account.
- In the management console
, select the folder containing the Smart Web Security profile. - Navigate
to Audit Trails. - Click Create trail.
- In the Log destination field, select Object Storage.
- In the Bucket field, select the prepared bucket.
- Disable Control plane log collection.
- Under Data plane log collection, clear the list and select Smart Web Security.
- Under Service account, select the prepared account with the storage.uploader role for the bucket and the audit-trails.viewer role for the folder containing the security profile.
- Under General information, enter a name for the trail, e.g.,
trail-sws. - Click Create.
The system will log all data events from Smart Web Security in the current folder, ignoring management events.
For other ways to enable event logging, see this article.
To make Yandex Smart Web Security deliver its events to Audit Trails:
-
In the management console
, select the folder containing the Smart Web Security profile. -
Navigate
to Smart Web Security. -
In the left-hand panel, select Security profiles.
-
In the row with the security profile you need, click
and select Edit. -
Enable Write logs.
-
In the Send logs to field, select Audit Trails.
-
Configure the log filters:
-
Under Log requests for rules, select the rule types:
- Base rules.
- Smart Protection.
- Web Application Firewall.
- Advanced Rate Limiter.
-
Under Log requests with verdict, select the verdicts:
- ALLOW.
- DENY.
- Sent for challenge: CAPTCHA or JS challenge.
-
For requests with the
ALLOWverdict, specify the percentage of logs to skip in the How many logs with the ALLOW verdict should not be recorded field:0%to log all requests, and100%to log none.
-
-
Click Save.
This allows configuring event delivery only from specific security profiles or only for specific rules and verdicts.
Viewing logs
For a security profile:
-
In the management console
, select the folder with the security profile. -
Navigate
to Smart Web Security. -
In the left-hand panel, select
Logs. -
Specify the log search period.
-
In the query row, select the fields for filtering. To find the logs of a specific profile, add the
security_profile_id = "<profile_id>"condition.To enter your query in text mode, click
and use the Monium query language. Save theproject,cluster, andservicelabels selected by default. -
Click Execute query. To view the contents of a record, expand it.
For a proxy server:
The logging.viewer role for the log group is required.
- In the management console
, select the folder containing the proxy server. - Navigate
to Smart Web Security. - In the left-hand panel, select Domain security.
- Select the proxy server in question.
- Navigate to the Logs tab.
The proxy server logs can also be viewed in Cloud Logging.
-
On the Monium
home page, select Explore → Logs on the left. -
Specify the log search period.
-
In the query string, specify
project = "folder__<folder_id>for the folder containing the security profile. Select the cluster and service values for the Smart Web Security logs from the drop-down lists. -
To find the logs of a specific profile, add the
security_profile_id = "<profile_id>"condition.The query can be composed from labels in the drop-down lists or entered in the Monium query language. To enter the query, click
. -
Click Execute query. To view the contents of a record, expand it.
To view the logs, you need the storage.viewer role for the bucket.
- In the management console
, select the folder with the bucket. - Navigate
to Object Storage. - Select the bucket specified in the trail settings.
- On the Objects tab, find the files for the date in question. The file path contains the trail ID and recording date.
- Download the required JSON file and open it in a text editor.
Each file contains an array of events. To find a specific Smart Web Security event, search for the value of the event_type field in the following format: yandex.cloud.audit.smartwebsecurity.<event_name>.
Examples of preset log filters
The examples below relate to security profile logs and are suitable for the Smart Web Security and Monium interfaces. Logs are delivered in JSON format, with one record corresponding to one client request processed by Smart Web Security.
Queries for log filtering are based on the relationship between Smart Web Security profiles and rules. You can view logs for active, running rules, or rules in Logging only (dry run) mode.
Add the required conditions from the examples below to the query selector, keeping the project, cluster, and service labels. The fields are described in Logging.
Filters for active rules
-
Show requests blocked by basic rules based on specific conditions, e.g., by IP list or region:
module_type = "RULE_CONDITION", meta.matched_rule_verdict = "DENY" -
Show requests that have triggered the Smart Protection rules with a CAPTCHA challenge:
module_type = "SMART_PROTECTION", meta.matched_rule_verdict = "CAPTCHA" -
Show requests blocked based on the WAF profile, i.e., by the security profile WAF rules:
module_type = "WAF", meta.matched_rule_verdict = "DENY" -
Show requests blocked by the ARL profile rules:
meta.arl_verdict = "DENY" -
Show requests which triggered a specific ARL rule,
arl-rule-1:meta.arl_verdict = "DENY", meta.arl_applied_quota_name = "arl-rule-1"
Filters for rules in logging mode
-
Show requests that have triggered the Smart Protection rules with a CAPTCHA challenge:
module_type = "SMART_PROTECTION", meta.dry_run_matched_rule_verdict = "CAPTCHA" -
Show requests that exceeded the specific ARL rule,
arl-rule-1:meta.arl_dry_run_exceeded_quota_names = "arl-rule-1"
You can similarly add other conditions to the filters and adjust them to fit your traffic flow.