Creating a trail to upload audit logs
You can create a trail that will upload both management and data event audit logs into one of the destination objects:
- Yandex Object Storage bucket.
- Yandex Cloud Logging group.
- Yandex Data Streams data stream.
When creating a trail via the CLI, Terraform, or API, you can set field value conditions in the data event filters. Thus you will reduce the event stream and the amount of stored logs.
Getting started
Prepare a destination object and service account for your trail:
-
Create a bucket with restricted access the audit logs will be uploaded to.
-
(Optional) Enable encryption for the bucket:
Make sure the account you are going to use to create an encryption key for the bucket has the
kms.editorrole for the folder. -
Create a service account for the trail.
-
Assign to the service account these roles for the trail to collect and upload logs:
-
storage.uploader for the bucket.
-
kms.keys.encrypter for the bucket encryption key.
This role is only required if encryption was enabled for the bucket.
-
audit-trails.viewer for a resource defining the required log collection scope:
- Organization: To collect logs in selected clouds of the organization.
- Cloud: To collect logs in selected folders of the cloud.
- Folder: To collect logs in this folder.
Child resources inherit access permissions from their parent resources. For example, if a service account gets a role for a cloud, then the trail that uses this account will be able to collect logs for resources across all folders of this cloud. However, the trail will not be able to collect logs in other clouds owned by the organization: a role for the organization is required for that.
-
-
Make sure the account you are going to use to create a trail has the required roles:
- audit-trails.editor for the folder to host the trail.
- iam.serviceAccounts.user for the trail’s service account.
-
Create a log group the audit logs will be uploaded to.
-
Create a service account for the trail.
-
Assign to the service account these roles for the trail to collect and upload logs:
- logging.writer for the log group.
-
audit-trails.viewer for a resource defining the required log collection scope:
- Organization: To collect logs in selected clouds of the organization.
- Cloud: To collect logs in selected folders of the cloud.
- Folder: To collect logs in this folder.
Child resources inherit access permissions from their parent resources. For example, if a service account gets a role for a cloud, then the trail that uses this account will be able to collect logs for resources across all folders of this cloud. However, the trail will not be able to collect logs in other clouds owned by the organization: a role for the organization is required for that.
-
Make sure the account you are going to use to create a trail has the required roles:
- audit-trails.editor for the folder to host the trail.
- iam.serviceAccounts.user for the trail’s service account.
-
Create a data stream the audit logs will be uploaded to.
Tip
We recommend enabling autopartitioning on the target data stream.
When overloading individual shards or the entire stream, some events may get lost. Autopartitioning automatically adds shards as needed and distributes the workloads to avoid losses. If autopartitioning is disabled, remember to manually check and increase the number of shards.
-
Create a service account for the trail.
-
Assign to the service account these roles for the trail to collect and upload logs:
- yds.writer for the data stream.
-
audit-trails.viewer for a resource defining the required log collection scope:
- Organization: To collect logs in selected clouds of the organization.
- Cloud: To collect logs in selected folders of the cloud.
- Folder: To collect logs in this folder.
Child resources inherit access permissions from their parent resources. For example, if a service account gets a role for a cloud, then the trail that uses this account will be able to collect logs for resources across all folders of this cloud. However, the trail will not be able to collect logs in other clouds owned by the organization: a role for the organization is required for that.
-
Make sure the account you are going to use to create a trail has the required roles:
- audit-trails.editor for the folder to host the trail.
- iam.serviceAccounts.user for the trail’s service account.
Creating a trail
-
In the management console
, select the folder to host the trail. -
Navigate
to Audit Trails. -
Click Create trail.
-
Under Destination, select one of the destination objects and specify its settings:
-
Object Storage: Uploading audit logs to an Object Storage bucket. Recommended for long-term data storage. Configure log storage settings:
-
Bucket: Bucket you created earlier.
-
Object prefix: Prefix that will be assigned to the objects with audit logs in the bucket. It is an optional parameter used in the full name of the audit log file.
Note
Use a prefix to store audit logs and third-party data in the same bucket. Do not use the same prefix for logs and other bucket objects because that may cause logs and third-party objects to overwrite each other.
-
Encryption key: Bucket encryption key. You only need to select it if encryption was enabled for the bucket.
-
-
Cloud Logging: Log group you created earlier. Audit logs will be uploaded into this log group. Recommended for quick log collection and analysis.
-
Data Streams: Data stream you created earlier. Audit logs will be uploaded into this stream. Recommended for streaming logs to other services or systems.
-
-
Under Control plane log collection:
-
Enable log collection.
-
Select a resource:
Organization,Cloud, orFolder. -
Depending on the resource you selected, select specific clouds or folders to collect events from:
-
For the
Organizationcollection scope, select one or more clouds to collect events from in the Cloud drop-down list.Keep the default value (
All) to collect events from all clouds in the organization. -
For the
Cloudcollection scope, select one or more folders to collect events from in the Folder drop-down list.Keep the default value (
All) to collect events from all folders in the cloud.
-
-
-
Under Data plane log collection:
Warning
In the management console, collection of some data events is on by default. Their delivery is billed as per the pricing policy. If you do not need data events, disable their collection.
-
Enable log collection.
-
Select the services to collect audit logs for.
-
Configure the event collection scope and filter for each service:
-
Click
to the right of the service name. -
Select a resource:
Organization,Cloud, orFolder. -
Depending on the resource you selected, select specific clouds or folders to collect events from:
-
For the
Organizationcollection scope, select one or more clouds to collect events from in the Cloud drop-down list.Keep the default value (
All) to collect events from all clouds in the organization. -
For the
Cloudcollection scope, select one or more folders to collect events from in the Folder drop-down list.Keep the default value (
All) to collect events from all folders in the cloud.
-
-
Select the event filter:
Get all: To collect all events within the service.Selected: To collect only selected events. Then proceed to select the events.Exclude: To collect all events except for the selected ones. Then proceed to select the events.
-
To restrict event collection by field values, set the filtering conditions via the CLI, API, or Terraform.
-
-
Under Service account, select the previously created service account the trail will operate under.
-
In the Name field, enter a name for the trail. It must be unique within the folder.
-
Optionally, enter a description for the trail.
-
Click Create.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
View the description of the CLI command for creating a trail:
yc audit-trails trail create --help
Use a YAML specification for collecting data events. If you only need management events, provide parameters directly in the command.
In the YAML specification
-
Create a YAML file with the trail configuration. In this template, logs are uploaded to the bucket:
name: <trail_name> folder_id: <folder_ID> destination: object_storage: bucket_id: <bucket_name> object_prefix: <prefix_for_objects> service_account_id: <service_account_ID> filtering_policy: management_events_filter: resource_scopes: - id: <cloud_or_folder_organization_ID> type: <type> data_events_filters: - service: <service_name> resource_scopes: - id: <cloud_or_folder_organization_ID> type: <type> included_events: event_types: - <full_event_name>You can also use the specification for an existing trail as a basis.
Configuration parameters:
-
name: Trail name. It must be unique within the folder. -
folder_id: ID of the folder the trail will reside in. -
destination: Settings for the audit log destination object.Specify only one destination:
object_storage,cloud_logging, ordata_stream.-
object_storage: Uploading logs to a Yandex Object Storage bucket:-
bucket_id: Name of the bucket you created earlier.To view a list of bucket names in the default folder, run this command:
yc storage bucket list -
object_prefix: Prefix to assign to the objects with audit logs within the bucket. It is an optional parameter used in the full name of the audit log file.Note
Use a prefix to store audit logs and third-party data in the same bucket. Do not use the same prefix for logs and other bucket objects because that may cause logs and third-party objects to overwrite each other.
-
-
cloud_logging: Uploading logs to a Yandex Cloud Logging group.Replace the
destinationsection in the template:destination: cloud_logging: log_group_id: <log_group_ID>In the
log_group_idparameter, specify the ID of the log group you created earlier. You can request the ID with the list of log groups in the folder. -
data_stream: Uploading logs to a data stream in Yandex Data Streams:Replace the
destinationsection in the template:destination: data_stream: stream_name: <data_stream_name> database_id: <database_ID> codec: RAWstream_name: Name of the data stream you created earlier. You can request the name with the list of data streams in the folder.database_id: ID of the YDB database used by Data Streams. You can request the ID with the list of YDB databases in the folder.codec: Event compression method when writing to Data Streams. The possible values areRAW(no compression, default),GZIP, andZSTD. Enable compression if you expect an event flow greater than 1 MB/s.
-
-
service_account_id: ID of the service account you created earlier.
-
filtering_policy: Settings of the filtering policy that determines which events to collect and include in the audit logs. The policy consists of filters pertaining to different levels of events.Warning
You must configure at least one filter for the policy; otherwise, you will not be able to create a trail.
Available filters:
-
management_events_filter: Management event filter.Specify the log collection scope in the
resource_scopesparameter:-
id: Organization, cloud, or folder ID. -
type: Scope type according to the specified ID:organization-manager.organization: Organization.resource-manager.cloud: Cloud.resource-manager.folder: Folder.
You can combine several scopes belonging to the same organization in one
resource_scopesparameter. For example, you can collect logs from one entire cloud and only from particular folders in another cloud:resource_scopes: # Collecting logs from all of cloud 1 - id: <ID_of_cloud_1> type: resource-manager.cloud # Collecting logs from folder 1 of cloud 2 - id: <folder_1_ID> type: resource-manager.folder # Collecting logs from folder 2 of cloud 2 - id: <folder_2_ID> type: resource-manager.folderService account permissions must allow collecting logs from the specified scopes.
-
-
data_events_filters: Data event filters. You can configure several filters of this type, one filter per service.A filter for one service has the following structure:
-
service: Service name. You can get it from the data event reference. -
resource_scopes: Places to collect data events from. You can configure this parameter the same way as the management event filter. -
*_events: Full names of events to collect or exclude:included_events.event_types: Collect only specified events.excluded_events.event_types: Collect all events other than the specified ones.
To exclude events, replace the
included_eventssection in the template:excluded_events: event_types: - <full_event_name>Use the full name from the
event_typefield of the audit log. For example,yandex.cloud.audit.iam.CreateIamTokencorresponds to theCreateIamTokenevent from the reference.
Warning
For filters by event name, the
included_eventsandexcluded_eventssections are mutually exclusive. If they are not specified, all events are recorded. You can additionally set field value conditions in the same filter. -
-
-
-
Optionally, supplement the filter with conditions based on field values for the relevant service. Do it by setting the
include_rulesandexclude_rulesrules in thefiltering_policy.data_events_filterslist item. For filter configuration examples, see Creating a trail. -
Run this command:
yc audit-trails trail create --file <file_path>
In command parameters
To collect management events from a folder and upload them to a bucket, run this command:
yc audit-trails trail create \
--name <trail_name> \
--service-account-id <service_account_ID> \
--destination-bucket <bucket_name> \
--filter-all-folder-id <folder_ID>
For a different destination object, replace --destination-bucket with one of these options:
-
Log group:
--destination-log-group-id <log_group_ID> -
Data stream:
--destination-yds-stream <data_stream_name> \ --destination-yds-database-id <database_ID>
Command parameters:
--name: Name of the new trail.
-
--description: Trail description. This is an optional setting. -
--labels: List of labels. This is an optional setting. You can specify one or more labels separated by commas in<key1>=<value1>,<key2>=<value2>format. -
--service-account-id: Service account ID. -
--destination-bucket: Name of the Yandex Object Storage bucket you want to upload audit logs to.You cannot use this parameter together with
--destination-log-group-idor--destination-yds-stream. -
--destination-bucket-object-prefix: Prefix that will be assigned to the objects with audit logs in the bucket. It is an optional parameter used in the full name of the audit log file.Note
Use a prefix to store audit logs and third-party data in the same bucket. Do not use the same prefix for logs and other bucket objects because that may cause logs and third-party objects to overwrite each other.
-
--destination-log-group-id: ID of the Yandex Cloud Logging log group the audit logs will be uploaded to.You cannot use this parameter together with
--destination-bucketor--destination-yds-stream. -
--destination-yds-stream: Name of the Yandex Data Streams data stream the audit logs will be uploaded to.You cannot use this parameter together with
--destination-bucketor--destination-log-group-id. -
--destination-yds-database-id: ID of the YDB database used by Data Streams. -
--destination-yds-codec: Event compression method when writing to Data Streams. The possible values areRAW(no compression, default),GZIP,ZSTD. Enable compression if you expect an event flow greater than 1 MB/s. -
--filter-all-folder-id: Folder ID. The system will be logging management events for all resources in this folder. -
--filter-all-cloud-id: Cloud ID. The system will be logging management events for all resources in this cloud. -
--filter-all-organisation-id: Organization ID. The system will be logging management events for all resources in this organization. -
--filter-some-folder-ids: List of folder IDs. The system will be logging management events for all resources in those folders, in the cloud specified in--filter-from-cloud-id.This parameter can only be used together with
--filter-from-cloud-id. -
--filter-from-cloud-id: ID of the cloud housing the folders specified in the--filter-some-folder-idsparameter.This parameter can only be used together with
--filter-some-folder-ids. -
--filter-some-cloud-ids: List of cloud IDs. The system will be logging management events for all resources in those clouds, in the organization specified in--filter-from-organisation-id.This parameter can only be used together with
--filter-from-organisation-id. -
--filter-from-organisation-id: ID of the organization housing the clouds specified under--filter-some-cloud-ids.This parameter can only be used together with
--filter-some-cloud-ids.
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.
-
Specify the trail properties in the configuration file. In this template, logs are uploaded to the bucket:
resource "yandex_audit_trails_trail" "basic_trail" { name = "<trail_name>" folder_id = "<folder_ID>" description = "<trail_description>" labels = { key = "value" } service_account_id = "<service_account_ID>" storage_destination { bucket_name = "<bucket_name>" object_prefix = "<prefix>" } filtering_policy { management_events_filter { resource_scope { resource_id = "<cloud_or_folder_organization_ID>" resource_type = "<type>" } } data_events_filter { service = "<service_name>" included_events = ["<full_event_name>"] resource_scope { resource_id = "<cloud_or_folder_organization_ID>" resource_type = "<type>" } } } }Where:
-
name: Name of the new trail. The naming requirements are as follows:- Length: between 3 and 63 characters.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
-
folder_id: ID of the folder to create the trail in. -
description: Trail description. This is an optional parameter. -
labels: List of labels inkey=valueformat. This is an optional parameter. -
service_account_id: ID of the service account the trail uses to collect and upload audit logs.Based on the audit log collection scope, the service account must have the
audit-trails.viewerrole for the organization, cloud, or folder whose audit logs the trail will be collecting.
Specify only one destination:
storage_destination,logging_destination, ordata_stream_destination.-
logging_destination: Uploading logs to a Yandex Cloud Logging group.Replace the
storage_destinationsection in the template:logging_destination { log_group_id = "<log_group_ID>" }log_group_id: ID of the log group for the trail to save audit logs to.
-
storage_destination: Uploading logs to a Yandex Object Storage bucket:-
log_group_id: Name of the bucket for the trail to save audit logs to. -
object_prefix: Prefix that will be assigned to the objects with audit logs in the bucket. It is an optional parameter used in the full name of the audit log file.Note
Use a prefix to store audit logs and third-party data in the same bucket. Do not use the same prefix for logs and other bucket objects because that may cause logs and third-party objects to overwrite each other.
-
-
data_stream_destination: Uploading logs to a data stream in Yandex Data Streams:Replace the
storage_destinationsection in the template:data_stream_destination { database_id = "<database_ID>" stream_name = "<data_stream_name>" codec = "RAW" }stream_name: Name of the data stream for the trail to save audit logs to.database_id: ID of the Yandex Managed Service for YDB database used by Data Streams.codec: Event compression method when writing to Data Streams. The possible values areRAW(no compression, default),GZIP, andZSTD. Enable compression if you expect an event flow greater than 1 MB/s.
-
filtering_policy: Settings of the filtering policy that determines which events to collect and include in the audit logs. The policy consists of filters pertaining to different levels of events. It contains themanagement_events_filteranddata_events_filtersections.-
management_events_filter: Management event filter.-
resource_scope: Log collection scope. You can specify multipleresource_scopesections for scopes belonging to the same organization. For example, you can collect logs from one entire cloud and only from particular folders in another cloud. Service account permissions must allow collecting logs from the specified scopes.-
resource_id: ID of the collection scope (organization, cloud, or folder). -
resource_type: Scope type according to the specified ID:organization-manager.organization: Organization.resource-manager.cloud: Cloud.resource-manager.folder: Folder.
-
-
-
data_events_filter: Data event filter. You can configure several filters of this type, one filter per service. A filter for one service has the following structure:-
service: Name of the service in which the trail will process events. You can get it from the data event reference. -
resource_scope: Places to collect data events from. You can configure this section the same way as the management event filter. -
included_events: Full names of events to collect. You can replace it withexcluded_events(full names of events to exclude). These parameters are mutually exclusive. If both are not set, selection is not limited to event names.Use the full name from the
event_typefield of the audit log. For example,yandex.cloud.audit.iam.CreateIamTokencorresponds to theCreateIamTokenevent from the reference. -
include_ruleandexclude_rule: Optional rules with conditions based on field values. These apply together with event selection by names.
-
-
For more on the properties of the
yandex_audit_trails_trailresource, see this provider guide. -
-
Optionally, supplement the filter with conditions based on field values for the relevant service. To do this, under
filtering_policy.data_events_filter, set theinclude_ruleandexclude_rule. Use the Yandex Cloud provider version 0.225.0 or higher. For filter configuration examples, see Creating a trail. -
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 new resources and their settings either in the management console
or using this CLI command:yc audit-trails trail get <trail_name> -
-
Authenticate with the API.
-
Prepare the following trail parameters: folder, destination object, service account, and filtering policy with the relevant services and scopes.
To use the settings of an existing trail as a basis, get them using the get REST API method or TrailService/Get gRPC API call.
-
Optionally, supplement the filter with conditions based on field values for the relevant service. Do it by setting the
includeRulesandexcludeRulesrules in thefilteringPolicy.dataEventsFilterslist item in the REST API request. In the gRPC API, useinclude_rulesandexclude_rulesinfiltering_policy.data_events_filters. For a filter configuration example, see Creating a trail. -
To create a trail, use the create REST API method for the Trail resource or the TrailService/Create gRPC API call.
The trail will be created and start uploading audit logs to the selected destination object.
When uploading to Cloud Logging, you may get duplicate events in a log group. To find duplicates, refer to the unique record ID, json_payload.event_id.
Examples
Creating a trail with event filtering
In our example, we create the sample-trail-all-planes trail in folder0***, and it writes logs to sample-logs-bucket under the service0*** service account.
The filters dictate which events are logged:
- Management events: From all the
org1***organization’s clouds. - Data events:
- Managed Service for PostgreSQL: All events from
cloud1***andfolder1***except forCreateDatabaseandUpdateDatabase. - Identity and Access Management: Only
CreateIamTokenevents fromfolder2***. Events with both theiam.sessioncredentials type anduser@example.comfor the subject name are excluded.
- Managed Service for PostgreSQL: All events from
-
Create a YAML file named
sample-trail-all-planes.yamlwith the trail configuration:name: sample-trail-all-planes folder_id: folder0*** destination: object_storage: bucket_id: sample-logs-bucket service_account_id: service0*** filtering_policy: management_events_filter: resource_scopes: - id: org1*** type: organization-manager.organization data_events_filters: - service: mdb.postgresql resource_scopes: - id: cloud1*** type: resource-manager.cloud - id: folder1*** type: resource-manager.folder excluded_events: event_types: - yandex.cloud.audit.mdb.postgresql.CreateDatabase - yandex.cloud.audit.mdb.postgresql.UpdateDatabase - service: iam resource_scopes: - id: folder2*** type: resource-manager.folder included_events: event_types: - yandex.cloud.audit.iam.CreateIamToken exclude_rules: - conditions: - field: $.details.credential.type operator: IN values: - iam.session - field: $.details.subject_name operator: IN values: - user@example.com -
Run this command:
yc audit-trails trail create --file sample-trail-all-planes.yaml
-
Specify the trail properties in the Terraform configuration file:
resource "yandex_audit_trails_trail" "basic_trail" { name = "sample-trail-all-planes" folder_id = "folder0***" service_account_id = "service0***" storage_destination { bucket_name = "sample-logs-bucket" } filtering_policy { management_events_filter { resource_scope { resource_id = "org1***" resource_type = "organization-manager.organization" } } data_events_filter { service = "mdb.postgresql" excluded_events = [ "yandex.cloud.audit.mdb.postgresql.CreateDatabase", "yandex.cloud.audit.mdb.postgresql.UpdateDatabase", ] resource_scope { resource_id = "cloud1***" resource_type = "resource-manager.cloud" } resource_scope { resource_id = "folder1***" resource_type = "resource-manager.folder" } } data_events_filter { service = "iam" included_events = ["yandex.cloud.audit.iam.CreateIamToken"] resource_scope { resource_id = "folder2***" resource_type = "resource-manager.folder" } exclude_rule { condition { field = "$.details.credential.type" operator = "IN" values = ["iam.session"] } condition { field = "$.details.subject_name" operator = "IN" values = ["user@example.com"] } } } } } -
Apply the configuration:
terraform apply
Use the create REST API method for the Trail resource.
To use the examples, install cURL
The example below is for MacOS and Linux. To run it on Windows, check the details on working with Bash in Microsoft Windows.
-
Get an IAM token for API authentication and write it into an environment variable:
export IAM_TOKEN=<IAM_token> -
Create a file named
body.jsonwith the following request body:{ "folderId": "folder0***", "name": "sample-trail-all-planes", "destination": { "objectStorage": { "bucketId": "sample-logs-bucket" } }, "serviceAccountId": "service0***", "filteringPolicy": { "managementEventsFilter": { "resourceScopes": [ { "id": "org1***", "type": "organization-manager.organization" } ] }, "dataEventsFilters": [ { "service": "mdb.postgresql", "resourceScopes": [ { "id": "cloud1***", "type": "resource-manager.cloud" }, { "id": "folder1***", "type": "resource-manager.folder" } ], "excludedEvents": { "eventTypes": [ "yandex.cloud.audit.mdb.postgresql.CreateDatabase", "yandex.cloud.audit.mdb.postgresql.UpdateDatabase" ] } }, { "service": "iam", "resourceScopes": [ { "id": "folder2***", "type": "resource-manager.folder" } ], "includedEvents": { "eventTypes": [ "yandex.cloud.audit.iam.CreateIamToken" ] }, "excludeRules": [ { "conditions": [ { "field": "$.details.credential.type", "operator": "IN", "values": ["iam.session"] }, { "field": "$.details.subject_name", "operator": "IN", "values": ["user@example.com"] } ] } ] } ] } } -
Run this request:
curl \ --request POST \ --header "Authorization: Bearer ${IAM_TOKEN}" \ --header "Content-Type: application/json" \ --data "@body.json" \ https://audittrails.api.cloud.yandex.net/audit-trails/v1/trails
Filtering by field value
You can use these examples to create or update a trail. Add the relevant snippet to the filter of the service in question: in the CLI, to the filtering_policy.data_events_filters list item; in Terraform, to the filtering_policy.data_events_filter section.
Excluding events by credentials type and user
The filter for iam excludes events with the iam.session credentials type and the user@example.com subject name, e.g., CreateIamToken.
exclude_rules:
- conditions:
- field: $.details.credential.type
operator: IN
values:
- iam.session
- field: $.details.subject_name
operator: IN
values:
- user@example.com
exclude_rule {
condition {
field = "$.details.credential.type"
operator = "IN"
values = ["iam.session"]
}
condition {
field = "$.details.subject_name"
operator = "IN"
values = ["user@example.com"]
}
}
Excluding events by IP address
The filter for mdb.mongodb excludes GenericAuditEvent events with details.remote_address from the 192.0.2.0/24 subnet.
exclude_rules:
- conditions:
- field: $.event_type
operator: IN
values:
- yandex.cloud.audit.mdb.mongodb.GenericAuditEvent
- field: $.details.remote_address
operator: IP_IN
values:
- 192.0.2.0/24
exclude_rule {
condition {
field = "$.event_type"
operator = "IN"
values = ["yandex.cloud.audit.mdb.mongodb.GenericAuditEvent"]
}
condition {
field = "$.details.remote_address"
operator = "IP_IN"
values = ["192.0.2.0/24"]
}
}
Excluding network events by source and destination addresses
The filter for network excludes ExternalFlow events with source and destination addresses from the 198.51.100.0/24 subnet.
exclude_rules:
- conditions:
- field: $.event_type
operator: IN
values:
- yandex.cloud.audit.network.flowlogs.ExternalFlow
- field: $.details.dst_addr
operator: IP_IN
values:
- 198.51.100.0/24
- field: $.details.src_addr
operator: IP_IN
values:
- 198.51.100.0/24
exclude_rule {
condition {
field = "$.event_type"
operator = "IN"
values = ["yandex.cloud.audit.network.flowlogs.ExternalFlow"]
}
condition {
field = "$.details.dst_addr"
operator = "IP_IN"
values = ["198.51.100.0/24"]
}
condition {
field = "$.details.src_addr"
operator = "IP_IN"
values = ["198.51.100.0/24"]
}
}
Collecting Kubernetes secret read events
The filter for k8s only keeps ApiServerWatch, ApiServerGet, and ApiServerList events for secrets resources.
include_rules:
- conditions:
- field: $.event_type
operator: IN
values:
- yandex.cloud.audit.k8s.apiserver.ApiServerWatch
- yandex.cloud.audit.k8s.apiserver.ApiServerGet
- yandex.cloud.audit.k8s.apiserver.ApiServerList
- field: $.details.native_api_server_event.objectRef.resource
operator: IN
values:
- secrets
include_rule {
condition {
field = "$.event_type"
operator = "IN"
values = [
"yandex.cloud.audit.k8s.apiserver.ApiServerWatch",
"yandex.cloud.audit.k8s.apiserver.ApiServerGet",
"yandex.cloud.audit.k8s.apiserver.ApiServerList",
]
}
condition {
field = "$.details.native_api_server_event.objectRef.resource"
operator = "IN"
values = ["secrets"]
}
}
The objectRef key register matches the Kubernetes source event.
What's next
- Learn more about the audit log format.
- Find out about the procedure for uploading audit logs to SIEM.
- Learn how to search for events in audit logs.